diff --git a/custom_components/gyverlamp/__init__.py b/custom_components/gyverlamp/__init__.py index 64467dd..2fed676 100644 --- a/custom_components/gyverlamp/__init__.py +++ b/custom_components/gyverlamp/__init__.py @@ -2,6 +2,7 @@ from homeassistant.core import HomeAssistant DOMAIN = "gyverlamp" +PLATFORMS = ["light"] async def async_setup(hass, hass_config): @@ -11,23 +12,17 @@ async def async_setup(hass, hass_config): async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): - # migrate data (after first setup) to options - if entry.data: - hass.config_entries.async_update_entry(entry, data={}, options=entry.data) + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - # add options handler - entry.add_update_listener(async_update_options) - - # forward to light setup - coro = hass.config_entries.async_forward_entry_setup(entry, "light") - hass.async_create_task(coro) + if not entry.update_listeners: + entry.add_update_listener(async_update_options) return True -async def async_update_options(hass: HomeAssistant, config_entry: ConfigEntry): - await hass.config_entries.async_reload(config_entry.entry_id) +async def async_update_options(hass: HomeAssistant, entry: ConfigEntry): + await hass.config_entries.async_reload(entry.entry_id) async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): - return await hass.config_entries.async_forward_entry_unload(entry, "light") + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/custom_components/gyverlamp/config_flow.py b/custom_components/gyverlamp/config_flow.py index 1051a96..b78f6ef 100644 --- a/custom_components/gyverlamp/config_flow.py +++ b/custom_components/gyverlamp/config_flow.py @@ -21,7 +21,7 @@ async def async_step_user(self, user_input=None): if user_input is not None: host = user_input[CONF_HOST] user_input[CONF_EFFECTS] = parse_effects(user_input[CONF_EFFECTS]) - return self.async_create_entry(title=host, data=user_input) + return self.async_create_entry(title=host, data={}, options=user_input) effects = ",".join(EFFECTS) return self.async_show_form(