diff --git a/custom_components/ge_home/binary_sensor.py b/custom_components/ge_home/binary_sensor.py index fb808f8..9a5f690 100644 --- a/custom_components/ge_home/binary_sensor.py +++ b/custom_components/ge_home/binary_sensor.py @@ -36,4 +36,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn _LOGGER.debug(f'Found {len(entities):d} unregistered binary sensors') async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)) diff --git a/custom_components/ge_home/button.py b/custom_components/ge_home/button.py index cfbb843..cff4818 100644 --- a/custom_components/ge_home/button.py +++ b/custom_components/ge_home/button.py @@ -34,4 +34,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn _LOGGER.debug(f'Found {len(entities):d} unregistered buttons ') async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) \ No newline at end of file + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)) diff --git a/custom_components/ge_home/climate.py b/custom_components/ge_home/climate.py index 8255fb8..d562cf2 100644 --- a/custom_components/ge_home/climate.py +++ b/custom_components/ge_home/climate.py @@ -36,4 +36,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn _LOGGER.debug(f'Found {len(entities):d} unregistered climate entities') async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) \ No newline at end of file + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)) diff --git a/custom_components/ge_home/humidifier.py b/custom_components/ge_home/humidifier.py index 4d1ed11..729a803 100644 --- a/custom_components/ge_home/humidifier.py +++ b/custom_components/ge_home/humidifier.py @@ -33,4 +33,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn _LOGGER.debug(f'Found {len(entities):d} unregistered humidifiers') async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)) diff --git a/custom_components/ge_home/light.py b/custom_components/ge_home/light.py index b652d02..afe49d5 100644 --- a/custom_components/ge_home/light.py +++ b/custom_components/ge_home/light.py @@ -37,4 +37,6 @@ async def async_setup_entry( _LOGGER.debug(f"Found {len(entities):d} unregistered lights") async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)) diff --git a/custom_components/ge_home/number.py b/custom_components/ge_home/number.py index 2b4213c..a44b820 100644 --- a/custom_components/ge_home/number.py +++ b/custom_components/ge_home/number.py @@ -34,4 +34,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn _LOGGER.debug(f'Found {len(entities):d} unregisterd numbers') async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)) diff --git a/custom_components/ge_home/select.py b/custom_components/ge_home/select.py index 613b03b..842faef 100644 --- a/custom_components/ge_home/select.py +++ b/custom_components/ge_home/select.py @@ -37,4 +37,6 @@ async def async_setup_entry( _LOGGER.debug(f"Found {len(entities):d} unregistered selects") async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)) diff --git a/custom_components/ge_home/sensor.py b/custom_components/ge_home/sensor.py index 9732dbf..d0092d5 100644 --- a/custom_components/ge_home/sensor.py +++ b/custom_components/ge_home/sensor.py @@ -47,8 +47,10 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn _LOGGER.debug(f'Found {len(entities):d} unregistered sensors') async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) - + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)) + # register set_timer entity service platform.async_register_entity_service( SERVICE_SET_TIMER, diff --git a/custom_components/ge_home/switch.py b/custom_components/ge_home/switch.py index 3aa6f11..688f96b 100644 --- a/custom_components/ge_home/switch.py +++ b/custom_components/ge_home/switch.py @@ -33,4 +33,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn _LOGGER.debug(f'Found {len(entities):d} unregistered switches') async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)) diff --git a/custom_components/ge_home/update_coordinator.py b/custom_components/ge_home/update_coordinator.py index 3b5ab5d..0a61eae 100644 --- a/custom_components/ge_home/update_coordinator.py +++ b/custom_components/ge_home/update_coordinator.py @@ -3,7 +3,7 @@ import asyncio import async_timeout import logging -from typing import Any, Dict, Iterable, Optional, Tuple +from typing import Any, Callable, Dict, Iterable, Optional, Tuple, List from gehomesdk import ( EVENT_APPLIANCE_INITIAL_UPDATE, @@ -62,6 +62,7 @@ class GeHomeUpdateCoordinator(DataUpdateCoordinator): self._password = config_entry.data[CONF_PASSWORD] self._region = config_entry.data[CONF_REGION] self._appliance_apis = {} # type: Dict[str, ApplianceApi] + self._signal_remove_callbacks = [] # type: List[Callable] self._reset_initialization() @@ -149,6 +150,9 @@ class GeHomeUpdateCoordinator(DataUpdateCoordinator): api = self.appliance_apis[mac_addr] api.appliance = appliance + def add_signal_remove_callback(self, cb: Callable): + self._signal_remove_callbacks.append(cb) + async def get_client(self) -> GeWebsocketClient: """Get a new GE Websocket client.""" if self.client: @@ -209,6 +213,12 @@ class GeHomeUpdateCoordinator(DataUpdateCoordinator): """Resets the coordinator.""" _LOGGER.debug("resetting the coordinator") entry = self._config_entry + + # remove all the callbacks for this coordinator + for c in self._signal_remove_callbacks: + c() + self._signal_remove_callbacks.clear() + unload_ok = all( await asyncio.gather( *[ diff --git a/custom_components/ge_home/water_heater.py b/custom_components/ge_home/water_heater.py index 19e8b4d..1a855c1 100644 --- a/custom_components/ge_home/water_heater.py +++ b/custom_components/ge_home/water_heater.py @@ -35,4 +35,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn _LOGGER.debug(f'Found {len(entities):d} unregistered water heaters') async_add_entities(entities) - async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered) + # add the ready signal and register the remove callback + coordinator.add_signal_remove_callback( + async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered))