mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Remove listener on async_unload_entry in devolo Home Control (#42520)
This commit is contained in:
parent
a967f689c7
commit
c480284861
@ -44,9 +44,9 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||
|
||||
try:
|
||||
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
||||
hass.data[DOMAIN][entry.entry_id] = []
|
||||
hass.data[DOMAIN][entry.entry_id] = {"gateways": [], "listener": None}
|
||||
for gateway_id in gateway_ids:
|
||||
hass.data[DOMAIN][entry.entry_id].append(
|
||||
hass.data[DOMAIN][entry.entry_id]["gateways"].append(
|
||||
await hass.async_add_executor_job(
|
||||
partial(
|
||||
HomeControl,
|
||||
@ -65,13 +65,15 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||
)
|
||||
|
||||
def shutdown(event):
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
||||
gateway.websocket_disconnect(
|
||||
f"websocket disconnect requested by {EVENT_HOMEASSISTANT_STOP}"
|
||||
)
|
||||
|
||||
# Listen when EVENT_HOMEASSISTANT_STOP is fired
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown)
|
||||
hass.data[DOMAIN][entry.entry_id]["listener"] = hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP, shutdown
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@ -89,8 +91,9 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> boo
|
||||
await asyncio.gather(
|
||||
*[
|
||||
hass.async_add_executor_job(gateway.websocket_disconnect)
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]
|
||||
]
|
||||
)
|
||||
hass.data[DOMAIN][entry.entry_id]["listener"]()
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
return unload
|
||||
|
@ -28,7 +28,7 @@ async def async_setup_entry(
|
||||
"""Get all binary sensor and multi level sensor devices and setup them via config entry."""
|
||||
entities = []
|
||||
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
||||
for device in gateway.binary_sensor_devices:
|
||||
for binary_sensor in device.binary_sensor_property:
|
||||
entities.append(
|
||||
|
@ -22,7 +22,7 @@ async def async_setup_entry(
|
||||
"""Get all cover devices and setup them via config entry."""
|
||||
entities = []
|
||||
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
||||
for device in gateway.multi_level_switch_devices:
|
||||
for multi_level_switch in device.multi_level_switch_property:
|
||||
if device.device_model_uid in [
|
||||
|
@ -19,7 +19,7 @@ async def async_setup_entry(
|
||||
"""Get all cover devices and setup them via config entry."""
|
||||
entities = []
|
||||
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
||||
for device in gateway.multi_level_switch_devices:
|
||||
for multi_level_switch in device.multi_level_switch_property:
|
||||
if multi_level_switch.startswith("devolo.Blinds"):
|
||||
|
@ -17,7 +17,7 @@ async def async_setup_entry(
|
||||
"""Get all light devices and setup them via config entry."""
|
||||
entities = []
|
||||
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
||||
for device in gateway.multi_level_switch_devices:
|
||||
for multi_level_switch in device.multi_level_switch_property.values():
|
||||
if multi_level_switch.switch_type == "dimmer":
|
||||
|
@ -29,7 +29,7 @@ async def async_setup_entry(
|
||||
"""Get all sensor devices and setup them via config entry."""
|
||||
entities = []
|
||||
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
||||
for device in gateway.multi_level_sensor_devices:
|
||||
for multi_level_sensor in device.multi_level_sensor_property:
|
||||
entities.append(
|
||||
|
@ -13,7 +13,7 @@ async def async_setup_entry(
|
||||
"""Get all devices and setup the switch devices via config entry."""
|
||||
entities = []
|
||||
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
||||
for device in gateway.binary_switch_devices:
|
||||
for binary_switch in device.binary_switch_property:
|
||||
# Exclude the binary switch which also has multi_level_switches here,
|
||||
|
Loading…
x
Reference in New Issue
Block a user