mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Improve lists in integrations [C-D] (#113072)
This commit is contained in:
parent
4d77bec681
commit
c75342bd9a
@ -64,22 +64,22 @@ async def async_setup_entry(
|
||||
ffmpeg_arguments: str = entry.options.get(
|
||||
CONF_FFMPEG_ARGUMENTS, DEFAULT_FFMPEG_ARGUMENTS
|
||||
)
|
||||
cameras: list[CanaryCamera] = []
|
||||
|
||||
for location_id, location in coordinator.data["locations"].items():
|
||||
for device in location.devices:
|
||||
if device.is_online:
|
||||
cameras.append(
|
||||
CanaryCamera(
|
||||
hass,
|
||||
coordinator,
|
||||
location_id,
|
||||
device,
|
||||
ffmpeg_arguments,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(cameras, True)
|
||||
async_add_entities(
|
||||
(
|
||||
CanaryCamera(
|
||||
hass,
|
||||
coordinator,
|
||||
location_id,
|
||||
device,
|
||||
ffmpeg_arguments,
|
||||
)
|
||||
for location_id, location in coordinator.data["locations"].items()
|
||||
for device in location.devices
|
||||
if device.is_online
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class CanaryCamera(CoordinatorEntity[CanaryDataUpdateCoordinator], Camera):
|
||||
|
@ -75,11 +75,11 @@ async def async_setup_entry(
|
||||
for device in location.devices:
|
||||
if device.is_online:
|
||||
device_type = device.device_type
|
||||
for sensor_type in SENSOR_TYPES:
|
||||
if device_type.get("name") in sensor_type[4]:
|
||||
sensors.append(
|
||||
CanarySensor(coordinator, sensor_type, location, device)
|
||||
)
|
||||
sensors.extend(
|
||||
CanarySensor(coordinator, sensor_type, location, device)
|
||||
for sensor_type in SENSOR_TYPES
|
||||
if device_type.get("name") in sensor_type[4]
|
||||
)
|
||||
|
||||
async_add_entities(sensors, True)
|
||||
|
||||
|
@ -649,16 +649,14 @@ async def google_assistant_list(
|
||||
gconf = await cloud.client.get_google_config()
|
||||
entities = google_helpers.async_get_entities(hass, gconf)
|
||||
|
||||
result = []
|
||||
|
||||
for entity in entities:
|
||||
result.append(
|
||||
{
|
||||
"entity_id": entity.entity_id,
|
||||
"traits": [trait.name for trait in entity.traits()],
|
||||
"might_2fa": entity.might_2fa_traits(),
|
||||
}
|
||||
)
|
||||
result = [
|
||||
{
|
||||
"entity_id": entity.entity_id,
|
||||
"traits": [trait.name for trait in entity.traits()],
|
||||
"might_2fa": entity.might_2fa_traits(),
|
||||
}
|
||||
for entity in entities
|
||||
]
|
||||
|
||||
connection.send_result(msg["id"], result)
|
||||
|
||||
@ -743,16 +741,14 @@ async def alexa_list(
|
||||
alexa_config = await cloud.client.get_alexa_config()
|
||||
entities = alexa_entities.async_get_entities(hass, alexa_config)
|
||||
|
||||
result = []
|
||||
|
||||
for entity in entities:
|
||||
result.append(
|
||||
{
|
||||
"entity_id": entity.entity_id,
|
||||
"display_categories": entity.default_display_categories(),
|
||||
"interfaces": [ifc.name() for ifc in entity.interfaces()],
|
||||
}
|
||||
)
|
||||
result = [
|
||||
{
|
||||
"entity_id": entity.entity_id,
|
||||
"display_categories": entity.default_display_categories(),
|
||||
"interfaces": [ifc.name() for ifc in entity.interfaces()],
|
||||
}
|
||||
for entity in entities
|
||||
]
|
||||
|
||||
connection.send_result(msg["id"], result)
|
||||
|
||||
|
@ -85,13 +85,12 @@ async def async_setup_entry(
|
||||
entities.append(AccountSensor(instance, currency))
|
||||
|
||||
if CONF_EXCHANGE_RATES in config_entry.options:
|
||||
rate: str
|
||||
for rate in config_entry.options[CONF_EXCHANGE_RATES]:
|
||||
entities.append(
|
||||
ExchangeRateSensor(
|
||||
instance, rate, exchange_base_currency, exchange_precision
|
||||
)
|
||||
entities.extend(
|
||||
ExchangeRateSensor(
|
||||
instance, rate, exchange_base_currency, exchange_precision
|
||||
)
|
||||
for rate in config_entry.options[CONF_EXCHANGE_RATES]
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -138,11 +138,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def get_items_of_category(hass: HomeAssistant, entry: ConfigEntry, category: str):
|
||||
"""Return a list of all Control4 items with the specified category."""
|
||||
director_all_items = hass.data[DOMAIN][entry.entry_id][CONF_DIRECTOR_ALL_ITEMS]
|
||||
return_list = []
|
||||
for item in director_all_items:
|
||||
if "categories" in item and category in item["categories"]:
|
||||
return_list.append(item)
|
||||
return return_list
|
||||
return [
|
||||
item
|
||||
for item in director_all_items
|
||||
if "categories" in item and category in item["categories"]
|
||||
]
|
||||
|
||||
|
||||
class Control4Entity(CoordinatorEntity):
|
||||
|
@ -24,17 +24,18 @@ def list_ports_as_str(
|
||||
if no_usb_option:
|
||||
ports_as_string.append(DONT_USE_USB)
|
||||
|
||||
for port in serial_ports:
|
||||
ports_as_string.append(
|
||||
usb.human_readable_device_name(
|
||||
port.device,
|
||||
port.serial_number,
|
||||
port.manufacturer,
|
||||
port.description,
|
||||
f"{hex(port.vid)[2:]:0>4}".upper() if port.vid else None,
|
||||
f"{hex(port.pid)[2:]:0>4}".upper() if port.pid else None,
|
||||
)
|
||||
ports_as_string.extend(
|
||||
usb.human_readable_device_name(
|
||||
port.device,
|
||||
port.serial_number,
|
||||
port.manufacturer,
|
||||
port.description,
|
||||
f"{hex(port.vid)[2:]:0>4}".upper() if port.vid else None,
|
||||
f"{hex(port.pid)[2:]:0>4}".upper() if port.pid else None,
|
||||
)
|
||||
for port in serial_ports
|
||||
)
|
||||
|
||||
ports_as_string.append(MANUAL_PATH)
|
||||
ports_as_string.append(REFRESH_LIST)
|
||||
|
||||
|
@ -85,8 +85,10 @@ def setup_platform(
|
||||
dev.append(CupsSensor(data, printer))
|
||||
|
||||
if "marker-names" in data.attributes[printer]:
|
||||
for marker in data.attributes[printer]["marker-names"]:
|
||||
dev.append(MarkerSensor(data, printer, marker, True))
|
||||
dev.extend(
|
||||
MarkerSensor(data, printer, marker, True)
|
||||
for marker in data.attributes[printer]["marker-names"]
|
||||
)
|
||||
|
||||
add_entities(dev, True)
|
||||
return
|
||||
|
@ -48,12 +48,12 @@ def setup_platform(
|
||||
rest = CurrencylayerData(_RESOURCE, parameters)
|
||||
|
||||
response = requests.get(_RESOURCE, params=parameters, timeout=10)
|
||||
sensors = []
|
||||
for variable in config[CONF_QUOTE]:
|
||||
sensors.append(CurrencylayerSensor(rest, base, variable))
|
||||
if "error" in response.json():
|
||||
return
|
||||
add_entities(sensors, True)
|
||||
add_entities(
|
||||
(CurrencylayerSensor(rest, base, variable) for variable in config[CONF_QUOTE]),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class CurrencylayerSensor(SensorEntity):
|
||||
|
@ -33,12 +33,13 @@ def setup_platform(
|
||||
["Danfoss Air Away Mode Active", ReadCommand.away_mode, None],
|
||||
]
|
||||
|
||||
dev = []
|
||||
|
||||
for sensor in sensors:
|
||||
dev.append(DanfossAirBinarySensor(data, sensor[0], sensor[1], sensor[2]))
|
||||
|
||||
add_entities(dev, True)
|
||||
add_entities(
|
||||
(
|
||||
DanfossAirBinarySensor(data, sensor[0], sensor[1], sensor[2])
|
||||
for sensor in sensors
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class DanfossAirBinarySensor(BinarySensorEntity):
|
||||
|
@ -97,14 +97,13 @@ def setup_platform(
|
||||
],
|
||||
]
|
||||
|
||||
dev = []
|
||||
|
||||
for sensor in sensors:
|
||||
dev.append(
|
||||
add_entities(
|
||||
(
|
||||
DanfossAir(data, sensor[0], sensor[1], sensor[2], sensor[3], sensor[4])
|
||||
)
|
||||
|
||||
add_entities(dev, True)
|
||||
for sensor in sensors
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class DanfossAir(SensorEntity):
|
||||
|
@ -47,12 +47,10 @@ def setup_platform(
|
||||
],
|
||||
]
|
||||
|
||||
dev = []
|
||||
|
||||
for switch in switches:
|
||||
dev.append(DanfossAir(data, switch[0], switch[1], switch[2], switch[3]))
|
||||
|
||||
add_entities(dev)
|
||||
add_entities(
|
||||
DanfossAir(data, switch[0], switch[1], switch[2], switch[3])
|
||||
for switch in switches
|
||||
)
|
||||
|
||||
|
||||
class DanfossAir(SwitchEntity):
|
||||
|
@ -114,10 +114,7 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
LOGGER.debug("Discovered deCONZ gateways %s", pformat(self.bridges))
|
||||
|
||||
if self.bridges:
|
||||
hosts = []
|
||||
|
||||
for bridge in self.bridges:
|
||||
hosts.append(bridge[CONF_HOST])
|
||||
hosts = [bridge[CONF_HOST] for bridge in self.bridges]
|
||||
|
||||
hosts.append(CONF_MANUAL_INPUT)
|
||||
|
||||
|
@ -63,17 +63,18 @@ def setup_platform(
|
||||
|
||||
# Gather all the available devices...
|
||||
perms = session.user.get_residential_permissions()
|
||||
all_switches = []
|
||||
all_switches: list = []
|
||||
for permission in perms:
|
||||
if permission.residentialAccountId is not None:
|
||||
acct = ResidentialAccount(session, permission.residentialAccountId)
|
||||
for residence in acct.get_residences():
|
||||
for switch in residence.get_iot_switches():
|
||||
all_switches.append(switch)
|
||||
all_switches.extend(
|
||||
switch
|
||||
for residence in acct.get_residences()
|
||||
for switch in residence.get_iot_switches()
|
||||
)
|
||||
elif permission.residenceId is not None:
|
||||
residence = Residence(session, permission.residenceId)
|
||||
for switch in residence.get_iot_switches():
|
||||
all_switches.append(switch)
|
||||
all_switches.extend(residence.get_iot_switches())
|
||||
|
||||
add_entities(DecoraWifiLight(sw) for sw in all_switches)
|
||||
except ValueError:
|
||||
|
@ -64,9 +64,8 @@ async def async_setup_platform(
|
||||
|
||||
session = async_get_clientsession(hass)
|
||||
|
||||
sensors = []
|
||||
for nextpassage in config[CONF_NEXT_DEPARTURE]:
|
||||
sensors.append(
|
||||
async_add_entities(
|
||||
(
|
||||
DeLijnPublicTransportSensor(
|
||||
Passages(
|
||||
nextpassage[CONF_STOP_ID],
|
||||
@ -76,9 +75,10 @@ async def async_setup_platform(
|
||||
True,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(sensors, True)
|
||||
for nextpassage in config[CONF_NEXT_DEPARTURE]
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class DeLijnPublicTransportSensor(SensorEntity):
|
||||
|
@ -34,29 +34,27 @@ async def async_setup_entry(
|
||||
entities: list[BinarySensorEntity] = []
|
||||
|
||||
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(
|
||||
DevoloBinaryDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=binary_sensor,
|
||||
)
|
||||
)
|
||||
for device in gateway.devices.values():
|
||||
if hasattr(device, "remote_control_property"):
|
||||
for remote in device.remote_control_property:
|
||||
for index in range(
|
||||
1, device.remote_control_property[remote].key_count + 1
|
||||
):
|
||||
entities.append(
|
||||
DevoloRemoteControl(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=remote,
|
||||
key=index,
|
||||
)
|
||||
)
|
||||
entities.extend(
|
||||
DevoloBinaryDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=binary_sensor,
|
||||
)
|
||||
for device in gateway.binary_sensor_devices
|
||||
for binary_sensor in device.binary_sensor_property
|
||||
)
|
||||
entities.extend(
|
||||
DevoloRemoteControl(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=remote,
|
||||
key=index,
|
||||
)
|
||||
for device in gateway.devices.values()
|
||||
if hasattr(device, "remote_control_property")
|
||||
for remote in device.remote_control_property
|
||||
for index in range(1, device.remote_control_property[remote].key_count + 1)
|
||||
)
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
@ -26,26 +26,24 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Get all cover devices and setup them via config entry."""
|
||||
entities = []
|
||||
|
||||
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 (
|
||||
"devolo.model.Thermostat:Valve",
|
||||
"devolo.model.Room:Thermostat",
|
||||
"devolo.model.Eurotronic:Spirit:Device",
|
||||
"unk.model.Danfoss:Thermostat",
|
||||
):
|
||||
entities.append(
|
||||
DevoloClimateDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_switch,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
DevoloClimateDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_switch,
|
||||
)
|
||||
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 (
|
||||
"devolo.model.Thermostat:Valve",
|
||||
"devolo.model.Room:Thermostat",
|
||||
"devolo.model.Eurotronic:Spirit:Device",
|
||||
"unk.model.Danfoss:Thermostat",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class DevoloClimateDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, ClimateEntity):
|
||||
|
@ -21,21 +21,18 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Get all cover devices and setup them via config entry."""
|
||||
entities = []
|
||||
|
||||
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"):
|
||||
entities.append(
|
||||
DevoloCoverDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_switch,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
DevoloCoverDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_switch,
|
||||
)
|
||||
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")
|
||||
)
|
||||
|
||||
|
||||
class DevoloCoverDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, CoverEntity):
|
||||
|
@ -22,25 +22,24 @@ async def async_get_config_entry_diagnostics(
|
||||
"""Return diagnostics for a config entry."""
|
||||
gateways: list[HomeControl] = hass.data[DOMAIN][entry.entry_id]["gateways"]
|
||||
|
||||
device_info = []
|
||||
for gateway in gateways:
|
||||
device_info.append(
|
||||
{
|
||||
"gateway": {
|
||||
"local_connection": gateway.gateway.local_connection,
|
||||
"firmware_version": gateway.gateway.firmware_version,
|
||||
},
|
||||
"devices": [
|
||||
{
|
||||
"device_id": device_id,
|
||||
"device_model_uid": properties.device_model_uid,
|
||||
"device_type": properties.device_type,
|
||||
"name": properties.name,
|
||||
}
|
||||
for device_id, properties in gateway.devices.items()
|
||||
],
|
||||
}
|
||||
)
|
||||
device_info = [
|
||||
{
|
||||
"gateway": {
|
||||
"local_connection": gateway.gateway.local_connection,
|
||||
"firmware_version": gateway.gateway.firmware_version,
|
||||
},
|
||||
"devices": [
|
||||
{
|
||||
"device_id": device_id,
|
||||
"device_model_uid": properties.device_model_uid,
|
||||
"device_type": properties.device_type,
|
||||
"name": properties.name,
|
||||
}
|
||||
for device_id, properties in gateway.devices.items()
|
||||
],
|
||||
}
|
||||
for gateway in gateways
|
||||
]
|
||||
|
||||
diag_data = {
|
||||
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
|
||||
|
@ -20,21 +20,18 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Get all light devices and setup them via config entry."""
|
||||
entities = []
|
||||
|
||||
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":
|
||||
entities.append(
|
||||
DevoloLightDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_switch.element_uid,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
DevoloLightDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_switch.element_uid,
|
||||
)
|
||||
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"
|
||||
)
|
||||
|
||||
|
||||
class DevoloLightDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, LightEntity):
|
||||
|
@ -45,35 +45,36 @@ async def async_setup_entry(
|
||||
entities: list[SensorEntity] = []
|
||||
|
||||
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(
|
||||
DevoloGenericMultiLevelDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_sensor,
|
||||
)
|
||||
)
|
||||
for device in gateway.devices.values():
|
||||
if hasattr(device, "consumption_property"):
|
||||
for consumption in device.consumption_property:
|
||||
for consumption_type in ("current", "total"):
|
||||
entities.append(
|
||||
DevoloConsumptionEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=consumption,
|
||||
consumption=consumption_type,
|
||||
)
|
||||
)
|
||||
if hasattr(device, "battery_level"):
|
||||
entities.append(
|
||||
DevoloBatteryEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=f"devolo.BatterySensor:{device.uid}",
|
||||
)
|
||||
)
|
||||
entities.extend(
|
||||
DevoloGenericMultiLevelDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_sensor,
|
||||
)
|
||||
for device in gateway.multi_level_sensor_devices
|
||||
for multi_level_sensor in device.multi_level_sensor_property
|
||||
)
|
||||
entities.extend(
|
||||
DevoloConsumptionEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=consumption,
|
||||
consumption=consumption_type,
|
||||
)
|
||||
for device in gateway.devices.values()
|
||||
if hasattr(device, "consumption_property")
|
||||
for consumption in device.consumption_property
|
||||
for consumption_type in ("current", "total")
|
||||
)
|
||||
entities.extend(
|
||||
DevoloBatteryEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=f"devolo.BatterySensor:{device.uid}",
|
||||
)
|
||||
for device in gateway.devices.values()
|
||||
if hasattr(device, "battery_level")
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -18,21 +18,18 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""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]["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.SirenMultiLevelSwitch"):
|
||||
entities.append(
|
||||
DevoloSirenDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_switch,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
DevoloSirenDeviceEntity(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=multi_level_switch,
|
||||
)
|
||||
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.SirenMultiLevelSwitch")
|
||||
)
|
||||
|
||||
|
||||
class DevoloSirenDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, SirenEntity):
|
||||
|
@ -20,23 +20,20 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Get all devices and setup the switch devices via config entry."""
|
||||
entities = []
|
||||
|
||||
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,
|
||||
# because those are implemented as light entities now.
|
||||
if not hasattr(device, "multi_level_switch_property"):
|
||||
entities.append(
|
||||
DevoloSwitch(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=binary_switch,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
DevoloSwitch(
|
||||
homecontrol=gateway,
|
||||
device_instance=device,
|
||||
element_uid=binary_switch,
|
||||
)
|
||||
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,
|
||||
# because those are implemented as light entities now.
|
||||
if not hasattr(device, "multi_level_switch_property")
|
||||
)
|
||||
|
||||
|
||||
class DevoloSwitch(DevoloDeviceEntity, SwitchEntity):
|
||||
|
@ -60,18 +60,18 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Set up the DirecTV config entry."""
|
||||
dtv = hass.data[DOMAIN][entry.entry_id]
|
||||
entities = []
|
||||
|
||||
for location in dtv.device.locations:
|
||||
entities.append(
|
||||
async_add_entities(
|
||||
(
|
||||
DIRECTVMediaPlayer(
|
||||
dtv=dtv,
|
||||
name=str.title(location.name),
|
||||
address=location.address,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities, True)
|
||||
for location in dtv.device.locations
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class DIRECTVMediaPlayer(DIRECTVEntity, MediaPlayerEntity):
|
||||
|
@ -29,18 +29,18 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Load DirecTV remote based on a config entry."""
|
||||
dtv = hass.data[DOMAIN][entry.entry_id]
|
||||
entities = []
|
||||
|
||||
for location in dtv.device.locations:
|
||||
entities.append(
|
||||
async_add_entities(
|
||||
(
|
||||
DIRECTVRemote(
|
||||
dtv=dtv,
|
||||
name=str.title(location.name),
|
||||
address=location.address,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities, True)
|
||||
for location in dtv.device.locations
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class DIRECTVRemote(DIRECTVEntity, RemoteEntity):
|
||||
|
@ -24,13 +24,10 @@ def setup_platform(
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Dlib Face detection platform."""
|
||||
entities = []
|
||||
for camera in config[CONF_SOURCE]:
|
||||
entities.append(
|
||||
DlibFaceDetectEntity(camera[CONF_ENTITY_ID], camera.get(CONF_NAME))
|
||||
)
|
||||
|
||||
add_entities(entities)
|
||||
add_entities(
|
||||
DlibFaceDetectEntity(camera[CONF_ENTITY_ID], camera.get(CONF_NAME))
|
||||
for camera in config[CONF_SOURCE]
|
||||
)
|
||||
|
||||
|
||||
class DlibFaceDetectEntity(ImageProcessingFaceEntity):
|
||||
|
@ -38,18 +38,15 @@ def setup_platform(
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Dlib Face detection platform."""
|
||||
entities = []
|
||||
for camera in config[CONF_SOURCE]:
|
||||
entities.append(
|
||||
DlibFaceIdentifyEntity(
|
||||
camera[CONF_ENTITY_ID],
|
||||
config[CONF_FACES],
|
||||
camera.get(CONF_NAME),
|
||||
config[CONF_CONFIDENCE],
|
||||
)
|
||||
add_entities(
|
||||
DlibFaceIdentifyEntity(
|
||||
camera[CONF_ENTITY_ID],
|
||||
config[CONF_FACES],
|
||||
camera.get(CONF_NAME),
|
||||
config[CONF_CONFIDENCE],
|
||||
)
|
||||
|
||||
add_entities(entities)
|
||||
for camera in config[CONF_SOURCE]
|
||||
)
|
||||
|
||||
|
||||
class DlibFaceIdentifyEntity(ImageProcessingFaceEntity):
|
||||
|
@ -112,19 +112,17 @@ def setup_platform(
|
||||
)
|
||||
return
|
||||
|
||||
entities = []
|
||||
for camera in config[CONF_SOURCE]:
|
||||
entities.append(
|
||||
Doods(
|
||||
hass,
|
||||
camera[CONF_ENTITY_ID],
|
||||
camera.get(CONF_NAME),
|
||||
doods,
|
||||
detector,
|
||||
config,
|
||||
)
|
||||
add_entities(
|
||||
Doods(
|
||||
hass,
|
||||
camera[CONF_ENTITY_ID],
|
||||
camera.get(CONF_NAME),
|
||||
doods,
|
||||
detector,
|
||||
config,
|
||||
)
|
||||
add_entities(entities)
|
||||
for camera in config[CONF_SOURCE]
|
||||
)
|
||||
|
||||
|
||||
class Doods(ImageProcessingEntity):
|
||||
|
@ -531,9 +531,7 @@ async def async_setup_entry(
|
||||
add_entities_handler = None
|
||||
|
||||
if dsmr_version == "5B":
|
||||
mbus_entities = create_mbus_entities(hass, telegram, entry)
|
||||
for mbus_entity in mbus_entities:
|
||||
entities.append(mbus_entity)
|
||||
entities.extend(create_mbus_entities(hass, telegram, entry))
|
||||
|
||||
entities.extend(
|
||||
[
|
||||
|
@ -65,10 +65,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
async def dynalite_service(service_call: ServiceCall) -> None:
|
||||
data = service_call.data
|
||||
host = data.get(ATTR_HOST, "")
|
||||
bridges = []
|
||||
for cur_bridge in hass.data[DOMAIN].values():
|
||||
if not host or cur_bridge.host == host:
|
||||
bridges.append(cur_bridge)
|
||||
bridges = [
|
||||
bridge
|
||||
for bridge in hass.data[DOMAIN].values()
|
||||
if not host or bridge.host == host
|
||||
]
|
||||
LOGGER.debug("Selected bridged for service call: %s", bridges)
|
||||
if service_call.service == SERVICE_REQUEST_AREA_PRESET:
|
||||
bridge_attr = "request_area_preset"
|
||||
|
@ -31,9 +31,7 @@ def async_setup_entry_base(
|
||||
@callback
|
||||
def async_add_entities_platform(devices):
|
||||
# assumes it is called with a single platform
|
||||
added_entities = []
|
||||
for device in devices:
|
||||
added_entities.append(entity_from_device(device, bridge))
|
||||
added_entities = [entity_from_device(device, bridge) for device in devices]
|
||||
async_add_entities(added_entities)
|
||||
|
||||
bridge.register_add_devices(platform, async_add_entities_platform)
|
||||
|
@ -157,11 +157,12 @@ async def test_sync_turn_off(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
def _create_tuples(enum: Enum, constant_prefix: str) -> list[tuple[Enum, str]]:
|
||||
result = []
|
||||
for enum in enum:
|
||||
if enum not in [ClimateEntityFeature.TURN_ON, ClimateEntityFeature.TURN_OFF]:
|
||||
result.append((enum, constant_prefix))
|
||||
return result
|
||||
return [
|
||||
(enum_field, constant_prefix)
|
||||
for enum_field in enum
|
||||
if enum_field
|
||||
not in [ClimateEntityFeature.TURN_ON, ClimateEntityFeature.TURN_OFF]
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -140,10 +140,7 @@ def is_closing(hass, ent):
|
||||
|
||||
|
||||
def _create_tuples(enum: Enum, constant_prefix: str) -> list[tuple[Enum, str]]:
|
||||
result = []
|
||||
for enum in enum:
|
||||
result.append((enum, constant_prefix))
|
||||
return result
|
||||
return [(enum_field, constant_prefix) for enum_field in enum]
|
||||
|
||||
|
||||
def test_all() -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user