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