From d8894926dbd3983a13dd85e08681edd3e582e4bd Mon Sep 17 00:00:00 2001 From: Greg Gibeling Date: Thu, 2 Jan 2025 15:08:27 -0800 Subject: [PATCH 1/3] G2-1689 Update async_forward_entry_setup calls --- custom_components/intellicenter/__init__.py | 54 +++++---------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/custom_components/intellicenter/__init__.py b/custom_components/intellicenter/__init__.py index f80a83c..17501fd 100644 --- a/custom_components/intellicenter/__init__.py +++ b/custom_components/intellicenter/__init__.py @@ -1,5 +1,4 @@ """Pentair IntelliCenter Integration.""" -import asyncio import logging from typing import Any, Optional @@ -99,33 +98,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: SYSTEM_TYPE: {MODE_ATTR, VACFLO_ATTR}, } model = PoolModel(attributes_map) - controller = ModelController(entry.data[CONF_HOST], model, loop=hass.loop) class Handler(ConnectionHandler): - UPDATE_SIGNAL = DOMAIN + "_UPDATE_" + entry.entry_id CONNECTION_SIGNAL = DOMAIN + "_CONNECTION_" + entry.entry_id def started(self, controller): - _LOGGER.info(f"connected to system: '{controller.systemInfo.propName}'") - for object in controller.model: _LOGGER.debug(f" loaded {object}") - - async def setup_platforms(): - """Set up platforms.""" - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_setup(entry, platform) - for platform in PLATFORMS - ] - ) - - # dispatcher.async_dispatcher_send(hass, self.CONNECTION_SIGNAL, True) - - hass.async_create_task(setup_platforms()) + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) @callback def reconnected(self, controller): @@ -148,23 +131,17 @@ def updated(self, controller, updates: dict[str, PoolObject]): dispatcher.async_dispatcher_send(hass, self.UPDATE_SIGNAL, updates) try: - handler = Handler(controller) - await handler.start() - hass.data.setdefault(DOMAIN, {}) - hass.data[DOMAIN][entry.entry_id] = handler # subscribe to Home Assistant STOP event to do some cleanup - async def on_hass_stop(event): """Stop push updates when hass stops.""" handler.stop() hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop) - return True except ConnectionRefusedError as err: raise ConfigEntryNotReady from err @@ -174,28 +151,23 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload IntelliCenter config entry.""" # Unload entities for this entry/device. + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) - - # Cleanup - handler = hass.data[DOMAIN].pop(entry.entry_id, None) + if unload_ok: + # Cleanup + handler = hass.data[DOMAIN].pop(entry.entry_id, None) - _LOGGER.info(f"unloading integration {entry.entry_id}") - if handler: + _LOGGER.info(f"unloading integration {entry.entry_id}") + if handler: handler.stop() - # if it was the last instance of this integration, clear up the DOMAIN entry - if not hass.data[DOMAIN]: - del hass.data[DOMAIN] + # if it was the last instance of this integration, clear up the DOMAIN entry + if not hass.data[DOMAIN]: + del hass.data[DOMAIN] - return True + return True + + return False # ------------------------------------------------------------------------------------- From f51b852023a2a74de8fa3b5735a937637b88fafe Mon Sep 17 00:00:00 2001 From: Greg Gibeling Date: Thu, 2 Jan 2025 16:06:24 -0800 Subject: [PATCH 2/3] G2-1689 Correct async calling --- custom_components/intellicenter/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/custom_components/intellicenter/__init__.py b/custom_components/intellicenter/__init__.py index 17501fd..710b7e8 100644 --- a/custom_components/intellicenter/__init__.py +++ b/custom_components/intellicenter/__init__.py @@ -108,7 +108,14 @@ def started(self, controller): _LOGGER.info(f"connected to system: '{controller.systemInfo.propName}'") for object in controller.model: _LOGGER.debug(f" loaded {object}") - await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + + async def setup_platforms(): + """Set up platforms.""" + await asyncio.gather( + hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + ) + # dispatcher.async_dispatcher_send(hass, self.CONNECTION_SIGNAL, True) + hass.async_create_task(setup_platforms()) @callback def reconnected(self, controller): From da9b021841dc24dd55c14ecc3010bbf96d0e5573 Mon Sep 17 00:00:00 2001 From: Greg Gibeling Date: Thu, 2 Jan 2025 16:09:22 -0800 Subject: [PATCH 3/3] G2-1689 Re-add removed import --- custom_components/intellicenter/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/custom_components/intellicenter/__init__.py b/custom_components/intellicenter/__init__.py index 710b7e8..6ca23df 100644 --- a/custom_components/intellicenter/__init__.py +++ b/custom_components/intellicenter/__init__.py @@ -1,4 +1,5 @@ """Pentair IntelliCenter Integration.""" +import asyncio import logging from typing import Any, Optional