Remove listener on async_unload_entry in devolo Home Control (#42520)

This commit is contained in:
Guido Schmitz 2020-10-28 20:54:57 +01:00 committed by GitHub
parent a967f689c7
commit c480284861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 11 deletions

View File

@ -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

View File

@ -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(

View File

@ -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 [

View File

@ -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"):

View File

@ -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":

View File

@ -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(

View File

@ -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,