mirror of https://github.com/simbaja/ha_gehome.git
- fixed error when reloading integration
This commit is contained in:
parent
c665ac3fd9
commit
d2329e6025
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
# add the ready signal and register the remove callback
|
||||
coordinator.add_signal_remove_callback(
|
||||
async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered))
|
||||
|
|
|
@ -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)
|
||||
# add the ready signal and register the remove callback
|
||||
coordinator.add_signal_remove_callback(
|
||||
async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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(
|
||||
*[
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue