Skip to content

Commit

Permalink
add remove device command
Browse files Browse the repository at this point in the history
  • Loading branch information
gluap committed Dec 30, 2023
1 parent 8faba7e commit 2f23f61
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion custom_components/duofern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
_LOGGER = logging.getLogger(__name__)

from .const import DOMAIN, DUOFERN_COMPONENTS

from homeassistant.helpers.device_registry import DeviceEntry
# Validation of the user's configuration
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({
vol.Optional('serial_port',
Expand All @@ -37,6 +37,21 @@
}, extra=vol.ALLOW_EXTRA)


async def async_remove_config_entry_device(
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry
) -> bool:
"""Remove a config entry from a device."""
stick = getDuofernStick(hass)
try:
del(stick.duofern_parser.modules["by_code"][device_entry.name])
stick.config['devices'] = [dev for dev in stick.config['devices'] if dev['id'] != device_entry.name]
except:
logging.warning(device_entry)
logging.warning(device_entry.__dict__)
stick.sync_devices()
return True


def setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Setup the duofern stick for communicating with the duofern devices via entities"""
configEntries = hass.config_entries.async_entries(DOMAIN)
Expand Down

0 comments on commit 2f23f61

Please sign in to comment.