From 556d55079925b05a06f01b7cb32d694216f48758 Mon Sep 17 00:00:00 2001 From: Tomaae Date: Mon, 24 Jan 2022 13:43:00 +0100 Subject: [PATCH] Redid integration setup to setup platform --- custom_components/mikrotik_router/__init__.py | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/custom_components/mikrotik_router/__init__.py b/custom_components/mikrotik_router/__init__.py index 240f908..7054683 100644 --- a/custom_components/mikrotik_router/__init__.py +++ b/custom_components/mikrotik_router/__init__.py @@ -36,10 +36,18 @@ async def async_setup(hass, _config): return True +# --------------------------- +# update_listener +# --------------------------- +async def update_listener(hass, config_entry) -> None: + """Handle options update.""" + await hass.config_entries.async_reload(config_entry.entry_id) + + # --------------------------- # async_setup_entry # --------------------------- -async def async_setup_entry(hass, config_entry): +async def async_setup_entry(hass, config_entry) -> bool: """Set up Mikrotik Router as config entry.""" controller = MikrotikControllerData(hass, config_entry) await controller.async_hwinfo_update() @@ -54,25 +62,8 @@ async def async_setup_entry(hass, config_entry): await controller.async_init() hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id] = controller - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, "sensor") - ) - - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, "binary_sensor") - ) - - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, "device_tracker") - ) - - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, "switch") - ) - - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, "button") - ) + hass.config_entries.async_setup_platforms(config_entry, PLATFORMS) + config_entry.async_on_unload(config_entry.add_update_listener(update_listener)) hass.services.async_register( DOMAIN, RUN_SCRIPT_COMMAND, controller.run_script, schema=SCRIPT_SCHEMA