Handle multiple setups of devolo Home Control (#41752)
This commit is contained in:
parent
22db1a509d
commit
13b2d10194
7 changed files with 123 additions and 110 deletions
|
@ -41,11 +41,13 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||||
raise ConfigEntryNotReady
|
raise ConfigEntryNotReady
|
||||||
|
|
||||||
gateway_ids = await hass.async_add_executor_job(mydevolo.get_gateway_ids)
|
gateway_ids = await hass.async_add_executor_job(mydevolo.get_gateway_ids)
|
||||||
gateway_id = gateway_ids[0]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
||||||
hass.data[DOMAIN]["homecontrol"] = await hass.async_add_executor_job(
|
hass.data[DOMAIN][entry.entry_id] = []
|
||||||
|
for gateway_id in gateway_ids:
|
||||||
|
hass.data[DOMAIN][entry.entry_id].append(
|
||||||
|
await hass.async_add_executor_job(
|
||||||
partial(
|
partial(
|
||||||
HomeControl,
|
HomeControl,
|
||||||
gateway_id=gateway_id,
|
gateway_id=gateway_id,
|
||||||
|
@ -53,6 +55,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||||
url=conf[CONF_HOMECONTROL],
|
url=conf[CONF_HOMECONTROL],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
except ConnectionError as err:
|
except ConnectionError as err:
|
||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady from err
|
||||||
|
|
||||||
|
@ -62,7 +65,8 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||||
)
|
)
|
||||||
|
|
||||||
def shutdown(event):
|
def shutdown(event):
|
||||||
hass.data[DOMAIN]["homecontrol"].websocket_disconnect(
|
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||||
|
gateway.websocket_disconnect(
|
||||||
f"websocket disconnect requested by {EVENT_HOMEASSISTANT_STOP}"
|
f"websocket disconnect requested by {EVENT_HOMEASSISTANT_STOP}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,19 +76,21 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload = all(
|
unload = all(
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*[
|
*[
|
||||||
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
hass.config_entries.async_forward_entry_unload(entry, platform)
|
||||||
for platform in PLATFORMS
|
for platform in PLATFORMS
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
await asyncio.gather(
|
||||||
await hass.async_add_executor_job(
|
*[
|
||||||
hass.data[DOMAIN]["homecontrol"].websocket_disconnect
|
hass.async_add_executor_job(gateway.websocket_disconnect)
|
||||||
|
for gateway in hass.data[DOMAIN][entry.entry_id]
|
||||||
|
]
|
||||||
)
|
)
|
||||||
del hass.data[DOMAIN]["homecontrol"]
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
return unload
|
return unload
|
||||||
|
|
|
@ -28,16 +28,17 @@ async def async_setup_entry(
|
||||||
"""Get all binary sensor and multi level sensor devices and setup them via config entry."""
|
"""Get all binary sensor and multi level sensor devices and setup them via config entry."""
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for device in hass.data[DOMAIN]["homecontrol"].binary_sensor_devices:
|
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||||
|
for device in gateway.binary_sensor_devices:
|
||||||
for binary_sensor in device.binary_sensor_property:
|
for binary_sensor in device.binary_sensor_property:
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloBinaryDeviceEntity(
|
DevoloBinaryDeviceEntity(
|
||||||
homecontrol=hass.data[DOMAIN]["homecontrol"],
|
homecontrol=gateway,
|
||||||
device_instance=device,
|
device_instance=device,
|
||||||
element_uid=binary_sensor,
|
element_uid=binary_sensor,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for device in hass.data[DOMAIN]["homecontrol"].devices.values():
|
for device in gateway.devices.values():
|
||||||
if hasattr(device, "remote_control_property"):
|
if hasattr(device, "remote_control_property"):
|
||||||
for remote in device.remote_control_property:
|
for remote in device.remote_control_property:
|
||||||
for index in range(
|
for index in range(
|
||||||
|
@ -45,7 +46,7 @@ async def async_setup_entry(
|
||||||
):
|
):
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloRemoteControl(
|
DevoloRemoteControl(
|
||||||
homecontrol=hass.data[DOMAIN]["homecontrol"],
|
homecontrol=gateway,
|
||||||
device_instance=device,
|
device_instance=device,
|
||||||
element_uid=remote,
|
element_uid=remote,
|
||||||
key=index,
|
key=index,
|
||||||
|
|
|
@ -22,7 +22,8 @@ async def async_setup_entry(
|
||||||
"""Get all cover devices and setup them via config entry."""
|
"""Get all cover devices and setup them via config entry."""
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for device in hass.data[DOMAIN]["homecontrol"].multi_level_switch_devices:
|
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||||
|
for device in gateway.multi_level_switch_devices:
|
||||||
for multi_level_switch in device.multi_level_switch_property:
|
for multi_level_switch in device.multi_level_switch_property:
|
||||||
if device.device_model_uid in [
|
if device.device_model_uid in [
|
||||||
"devolo.model.Thermostat:Valve",
|
"devolo.model.Thermostat:Valve",
|
||||||
|
@ -31,7 +32,7 @@ async def async_setup_entry(
|
||||||
]:
|
]:
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloClimateDeviceEntity(
|
DevoloClimateDeviceEntity(
|
||||||
homecontrol=hass.data[DOMAIN]["homecontrol"],
|
homecontrol=gateway,
|
||||||
device_instance=device,
|
device_instance=device,
|
||||||
element_uid=multi_level_switch,
|
element_uid=multi_level_switch,
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,12 +19,13 @@ async def async_setup_entry(
|
||||||
"""Get all cover devices and setup them via config entry."""
|
"""Get all cover devices and setup them via config entry."""
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for device in hass.data[DOMAIN]["homecontrol"].multi_level_switch_devices:
|
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||||
|
for device in gateway.multi_level_switch_devices:
|
||||||
for multi_level_switch in device.multi_level_switch_property:
|
for multi_level_switch in device.multi_level_switch_property:
|
||||||
if multi_level_switch.startswith("devolo.Blinds"):
|
if multi_level_switch.startswith("devolo.Blinds"):
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloCoverDeviceEntity(
|
DevoloCoverDeviceEntity(
|
||||||
homecontrol=hass.data[DOMAIN]["homecontrol"],
|
homecontrol=gateway,
|
||||||
device_instance=device,
|
device_instance=device,
|
||||||
element_uid=multi_level_switch,
|
element_uid=multi_level_switch,
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,12 +17,13 @@ async def async_setup_entry(
|
||||||
"""Get all light devices and setup them via config entry."""
|
"""Get all light devices and setup them via config entry."""
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for device in hass.data[DOMAIN]["homecontrol"].multi_level_switch_devices:
|
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||||
|
for device in gateway.multi_level_switch_devices:
|
||||||
for multi_level_switch in device.multi_level_switch_property.values():
|
for multi_level_switch in device.multi_level_switch_property.values():
|
||||||
if multi_level_switch.switch_type == "dimmer":
|
if multi_level_switch.switch_type == "dimmer":
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloLightDeviceEntity(
|
DevoloLightDeviceEntity(
|
||||||
homecontrol=hass.data[DOMAIN]["homecontrol"],
|
homecontrol=gateway,
|
||||||
device_instance=device,
|
device_instance=device,
|
||||||
element_uid=multi_level_switch.element_uid,
|
element_uid=multi_level_switch.element_uid,
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,22 +29,23 @@ async def async_setup_entry(
|
||||||
"""Get all sensor devices and setup them via config entry."""
|
"""Get all sensor devices and setup them via config entry."""
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for device in hass.data[DOMAIN]["homecontrol"].multi_level_sensor_devices:
|
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||||
|
for device in gateway.multi_level_sensor_devices:
|
||||||
for multi_level_sensor in device.multi_level_sensor_property:
|
for multi_level_sensor in device.multi_level_sensor_property:
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloGenericMultiLevelDeviceEntity(
|
DevoloGenericMultiLevelDeviceEntity(
|
||||||
homecontrol=hass.data[DOMAIN]["homecontrol"],
|
homecontrol=gateway,
|
||||||
device_instance=device,
|
device_instance=device,
|
||||||
element_uid=multi_level_sensor,
|
element_uid=multi_level_sensor,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for device in hass.data[DOMAIN]["homecontrol"].devices.values():
|
for device in gateway.devices.values():
|
||||||
if hasattr(device, "consumption_property"):
|
if hasattr(device, "consumption_property"):
|
||||||
for consumption in device.consumption_property:
|
for consumption in device.consumption_property:
|
||||||
for consumption_type in ["current", "total"]:
|
for consumption_type in ["current", "total"]:
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloConsumptionEntity(
|
DevoloConsumptionEntity(
|
||||||
homecontrol=hass.data[DOMAIN]["homecontrol"],
|
homecontrol=gateway,
|
||||||
device_instance=device,
|
device_instance=device,
|
||||||
element_uid=consumption,
|
element_uid=consumption,
|
||||||
consumption=consumption_type,
|
consumption=consumption_type,
|
||||||
|
@ -53,11 +54,12 @@ async def async_setup_entry(
|
||||||
if hasattr(device, "battery_level"):
|
if hasattr(device, "battery_level"):
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloBatteryEntity(
|
DevoloBatteryEntity(
|
||||||
homecontrol=hass.data[DOMAIN]["homecontrol"],
|
homecontrol=gateway,
|
||||||
device_instance=device,
|
device_instance=device,
|
||||||
element_uid=f"devolo.BatterySensor:{device.uid}",
|
element_uid=f"devolo.BatterySensor:{device.uid}",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities, False)
|
async_add_entities(entities, False)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,21 +11,22 @@ async def async_setup_entry(
|
||||||
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
|
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Get all devices and setup the switch devices via config entry."""
|
"""Get all devices and setup the switch devices via config entry."""
|
||||||
devices = hass.data[DOMAIN]["homecontrol"].binary_switch_devices
|
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for device in devices:
|
|
||||||
|
for gateway in hass.data[DOMAIN][entry.entry_id]:
|
||||||
|
for device in gateway.binary_switch_devices:
|
||||||
for binary_switch in device.binary_switch_property:
|
for binary_switch in device.binary_switch_property:
|
||||||
# Exclude the binary switch which also has multi_level_switches here,
|
# Exclude the binary switch which also has multi_level_switches here,
|
||||||
# because those are implemented as light entities now.
|
# because those are implemented as light entities now.
|
||||||
if not hasattr(device, "multi_level_switch_property"):
|
if not hasattr(device, "multi_level_switch_property"):
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloSwitch(
|
DevoloSwitch(
|
||||||
homecontrol=hass.data[DOMAIN]["homecontrol"],
|
homecontrol=gateway,
|
||||||
device_instance=device,
|
device_instance=device,
|
||||||
element_uid=binary_switch,
|
element_uid=binary_switch,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue