diff --git a/custom_components/ohme/__init__.py b/custom_components/ohme/__init__.py index ca7110f..7156dc9 100644 --- a/custom_components/ohme/__init__.py +++ b/custom_components/ohme/__init__.py @@ -21,6 +21,16 @@ async def async_setup_dependencies(hass, config): await client.async_update_device_info() +async def async_update_listener(hass, entry): + """Handle options flow credentials update.""" + # Re-instantiate the API client + await async_setup_dependencies(hass, dict(entry.data)) + + # Refresh all coordinators for good measure + for coordinator in hass.data[DOMAIN][DATA_COORDINATORS]: + await coordinator.async_refresh() + + async def async_setup_entry(hass, entry): """This is called from the config flow.""" hass.data.setdefault(DOMAIN, {}) @@ -70,6 +80,8 @@ async def async_setup_entry(hass, entry): hass.config_entries.async_forward_entry_setup(entry, entity_type) ) + entry.async_on_unload(entry.add_update_listener(async_update_listener)) + return True @@ -78,6 +90,7 @@ async def async_unload_entry(hass, entry): return await hass.config_entries.async_unload_platforms(entry, ENTITY_TYPES) + async def async_migrate_entry(hass: core.HomeAssistant, config_entry) -> bool: """Migrate old entry.""" # Version number has gone backwards @@ -92,7 +105,7 @@ async def async_migrate_entry(hass: core.HomeAssistant, config_entry) -> bool: config_entry.version = CONFIG_VERSION hass.config_entries.async_update_entry(config_entry, data=new_data) - + _LOGGER.debug("Migration to version %s successful", config_entry.version) return True