diff --git a/homeassistant/components/devolo_home_control/__init__.py b/homeassistant/components/devolo_home_control/__init__.py index e2b1ffc5d6d..8e4274ff02b 100644 --- a/homeassistant/components/devolo_home_control/__init__.py +++ b/homeassistant/components/devolo_home_control/__init__.py @@ -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 diff --git a/homeassistant/components/devolo_home_control/binary_sensor.py b/homeassistant/components/devolo_home_control/binary_sensor.py index fa9e5789f12..200b24ac7ff 100644 --- a/homeassistant/components/devolo_home_control/binary_sensor.py +++ b/homeassistant/components/devolo_home_control/binary_sensor.py @@ -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( diff --git a/homeassistant/components/devolo_home_control/climate.py b/homeassistant/components/devolo_home_control/climate.py index d3d9bd9a3fc..d333a5c7609 100644 --- a/homeassistant/components/devolo_home_control/climate.py +++ b/homeassistant/components/devolo_home_control/climate.py @@ -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 [ diff --git a/homeassistant/components/devolo_home_control/cover.py b/homeassistant/components/devolo_home_control/cover.py index 7ed217c7cb9..7514a9b7c9f 100644 --- a/homeassistant/components/devolo_home_control/cover.py +++ b/homeassistant/components/devolo_home_control/cover.py @@ -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"): diff --git a/homeassistant/components/devolo_home_control/light.py b/homeassistant/components/devolo_home_control/light.py index f046caea794..2a9be33223f 100644 --- a/homeassistant/components/devolo_home_control/light.py +++ b/homeassistant/components/devolo_home_control/light.py @@ -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": diff --git a/homeassistant/components/devolo_home_control/sensor.py b/homeassistant/components/devolo_home_control/sensor.py index d432560e8b8..e78b4eabeac 100644 --- a/homeassistant/components/devolo_home_control/sensor.py +++ b/homeassistant/components/devolo_home_control/sensor.py @@ -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( diff --git a/homeassistant/components/devolo_home_control/switch.py b/homeassistant/components/devolo_home_control/switch.py index ecd505d9c98..b4e070c50c8 100644 --- a/homeassistant/components/devolo_home_control/switch.py +++ b/homeassistant/components/devolo_home_control/switch.py @@ -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,