Skip to content

Commit

Permalink
- fixed error when reloading integration
Browse files Browse the repository at this point in the history
  • Loading branch information
simbaja committed Nov 28, 2023
1 parent c665ac3 commit d2329e6
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 12 deletions.
4 changes: 3 additions & 1 deletion custom_components/ge_home/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_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))
4 changes: 3 additions & 1 deletion custom_components/ge_home/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_LOGGER.debug(f'Found {len(entities):d} unregistered buttons ')
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))
4 changes: 3 additions & 1 deletion custom_components/ge_home/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_LOGGER.debug(f'Found {len(entities):d} unregistered climate entities')
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))
4 changes: 3 additions & 1 deletion custom_components/ge_home/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_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))
4 changes: 3 additions & 1 deletion custom_components/ge_home/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_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))
4 changes: 3 additions & 1 deletion custom_components/ge_home/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_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))
4 changes: 3 additions & 1 deletion custom_components/ge_home/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_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))
6 changes: 4 additions & 2 deletions custom_components/ge_home/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_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,
Expand Down
4 changes: 3 additions & 1 deletion custom_components/ge_home/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_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))
12 changes: 11 additions & 1 deletion custom_components/ge_home/update_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -62,6 +62,7 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
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()

Expand Down Expand Up @@ -149,6 +150,9 @@ def maybe_add_appliance_api(self, appliance: GeAppliance):
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:
Expand Down Expand Up @@ -209,6 +213,12 @@ async def async_reset(self):
"""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(
*[
Expand Down
4 changes: 3 additions & 1 deletion custom_components/ge_home/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ def async_devices_discovered(apis: list[ApplianceApi]):
_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))

0 comments on commit d2329e6

Please sign in to comment.