Improve lists in integrations [N-O] (#113231)
parent
595d07f1c6
commit
e6a692f354
|
@ -367,12 +367,11 @@ async def async_setup_entry(
|
|||
)
|
||||
ent_reg.async_update_entity(entity_id, new_unique_id=new_unique_id)
|
||||
|
||||
sensors: list[NAMSensor] = []
|
||||
for description in SENSORS:
|
||||
if getattr(coordinator.data, description.key) is not None:
|
||||
sensors.append(NAMSensor(coordinator, description))
|
||||
|
||||
async_add_entities(sensors, False)
|
||||
async_add_entities(
|
||||
NAMSensor(coordinator, description)
|
||||
for description in SENSORS
|
||||
if getattr(coordinator.data, description.key) is not None
|
||||
)
|
||||
|
||||
|
||||
class NAMSensor(CoordinatorEntity[NAMDataUpdateCoordinator], SensorEntity):
|
||||
|
|
|
@ -29,12 +29,13 @@ async def async_setup_entry(
|
|||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up Neato camera with config entry."""
|
||||
dev = []
|
||||
neato: NeatoHub = hass.data[NEATO_LOGIN]
|
||||
mapdata: dict[str, Any] | None = hass.data.get(NEATO_MAP_DATA)
|
||||
for robot in hass.data[NEATO_ROBOTS]:
|
||||
if "maps" in robot.traits:
|
||||
dev.append(NeatoCleaningMap(neato, robot, mapdata))
|
||||
dev = [
|
||||
NeatoCleaningMap(neato, robot, mapdata)
|
||||
for robot in hass.data[NEATO_ROBOTS]
|
||||
if "maps" in robot.traits
|
||||
]
|
||||
|
||||
if not dev:
|
||||
return
|
||||
|
|
|
@ -30,10 +30,8 @@ async def async_setup_entry(
|
|||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up the Neato sensor using config entry."""
|
||||
dev = []
|
||||
neato: NeatoHub = hass.data[NEATO_LOGIN]
|
||||
for robot in hass.data[NEATO_ROBOTS]:
|
||||
dev.append(NeatoSensor(neato, robot))
|
||||
dev = [NeatoSensor(neato, robot) for robot in hass.data[NEATO_ROBOTS]]
|
||||
|
||||
if not dev:
|
||||
return
|
||||
|
|
|
@ -32,12 +32,12 @@ async def async_setup_entry(
|
|||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up Neato switch with config entry."""
|
||||
dev = []
|
||||
neato: NeatoHub = hass.data[NEATO_LOGIN]
|
||||
|
||||
for robot in hass.data[NEATO_ROBOTS]:
|
||||
for type_name in SWITCH_TYPES:
|
||||
dev.append(NeatoConnectedSwitch(neato, robot, type_name))
|
||||
dev = [
|
||||
NeatoConnectedSwitch(neato, robot, type_name)
|
||||
for robot in hass.data[NEATO_ROBOTS]
|
||||
for type_name in SWITCH_TYPES
|
||||
]
|
||||
|
||||
if not dev:
|
||||
return
|
||||
|
|
|
@ -64,12 +64,13 @@ async def async_setup_entry(
|
|||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up Neato vacuum with config entry."""
|
||||
dev = []
|
||||
neato: NeatoHub = hass.data[NEATO_LOGIN]
|
||||
mapdata: dict[str, Any] | None = hass.data.get(NEATO_MAP_DATA)
|
||||
persistent_maps: dict[str, Any] | None = hass.data.get(NEATO_PERSISTENT_MAPS)
|
||||
for robot in hass.data[NEATO_ROBOTS]:
|
||||
dev.append(NeatoConnectedVacuum(neato, robot, mapdata, persistent_maps))
|
||||
dev = [
|
||||
NeatoConnectedVacuum(neato, robot, mapdata, persistent_maps)
|
||||
for robot in hass.data[NEATO_ROBOTS]
|
||||
]
|
||||
|
||||
if not dev:
|
||||
return
|
||||
|
|
|
@ -135,8 +135,7 @@ class NSDepartureSensor(SensorEntity):
|
|||
|
||||
if self._trips[0].trip_parts:
|
||||
route = [self._trips[0].departure]
|
||||
for k in self._trips[0].trip_parts:
|
||||
route.append(k.destination)
|
||||
route.extend(k.destination for k in self._trips[0].trip_parts)
|
||||
|
||||
# Static attributes
|
||||
attributes = {
|
||||
|
|
|
@ -48,14 +48,12 @@ async def async_setup_entry(
|
|||
device_manager: DeviceManager = hass.data[DOMAIN][entry.entry_id][
|
||||
DATA_DEVICE_MANAGER
|
||||
]
|
||||
entities = []
|
||||
for device in device_manager.devices.values():
|
||||
if (
|
||||
CameraImageTrait.NAME in device.traits
|
||||
async_add_entities(
|
||||
NestCamera(device)
|
||||
for device in device_manager.devices.values()
|
||||
if CameraImageTrait.NAME in device.traits
|
||||
or CameraLiveStreamTrait.NAME in device.traits
|
||||
):
|
||||
entities.append(NestCamera(device))
|
||||
async_add_entities(entities)
|
||||
)
|
||||
|
||||
|
||||
class NestCamera(Camera):
|
||||
|
|
|
@ -86,11 +86,12 @@ async def async_setup_entry(
|
|||
device_manager: DeviceManager = hass.data[DOMAIN][entry.entry_id][
|
||||
DATA_DEVICE_MANAGER
|
||||
]
|
||||
entities = []
|
||||
for device in device_manager.devices.values():
|
||||
if ThermostatHvacTrait.NAME in device.traits:
|
||||
entities.append(ThermostatEntity(device))
|
||||
async_add_entities(entities)
|
||||
|
||||
async_add_entities(
|
||||
ThermostatEntity(device)
|
||||
for device in device_manager.devices.values()
|
||||
if ThermostatHvacTrait.NAME in device.traits
|
||||
)
|
||||
|
||||
|
||||
class ThermostatEntity(ClimateEntity):
|
||||
|
@ -217,13 +218,13 @@ class ThermostatEntity(ClimateEntity):
|
|||
@property
|
||||
def preset_modes(self) -> list[str]:
|
||||
"""Return the available presets."""
|
||||
modes = []
|
||||
if ThermostatEcoTrait.NAME in self._device.traits:
|
||||
trait = self._device.traits[ThermostatEcoTrait.NAME]
|
||||
for mode in trait.available_modes:
|
||||
if mode in PRESET_MODE_MAP:
|
||||
modes.append(PRESET_MODE_MAP[mode])
|
||||
return modes
|
||||
if ThermostatEcoTrait.NAME not in self._device.traits:
|
||||
return []
|
||||
return [
|
||||
PRESET_MODE_MAP[mode]
|
||||
for mode in self._device.traits[ThermostatEcoTrait.NAME].available_modes
|
||||
if mode in PRESET_MODE_MAP
|
||||
]
|
||||
|
||||
@property
|
||||
def fan_mode(self) -> str:
|
||||
|
|
|
@ -71,10 +71,11 @@ def _generate_subscription_id(cloud_project_id: str) -> str:
|
|||
|
||||
def generate_config_title(structures: Iterable[Structure]) -> str | None:
|
||||
"""Pick a user friendly config title based on the Google Home name(s)."""
|
||||
names: list[str] = []
|
||||
for structure in structures:
|
||||
if (trait := structure.traits.get(InfoTrait.NAME)) and trait.custom_name:
|
||||
names.append(trait.custom_name)
|
||||
names: list[str] = [
|
||||
trait.custom_name
|
||||
for structure in structures
|
||||
if (trait := structure.traits.get(InfoTrait.NAME)) and trait.custom_name
|
||||
]
|
||||
if not names:
|
||||
return None
|
||||
return ", ".join(names)
|
||||
|
|
|
@ -490,9 +490,10 @@ def _browse_clip_preview(
|
|||
event_id: MediaId, device: Device, event: ClipPreviewSession
|
||||
) -> BrowseMediaSource:
|
||||
"""Build a BrowseMediaSource for a specific clip preview event."""
|
||||
types = []
|
||||
for event_type in event.event_types:
|
||||
types.append(MEDIA_SOURCE_EVENT_TITLE_MAP.get(event_type, "Event"))
|
||||
types = [
|
||||
MEDIA_SOURCE_EVENT_TITLE_MAP.get(event_type, "Event")
|
||||
for event_type in event.event_types
|
||||
]
|
||||
return BrowseMediaSource(
|
||||
domain=DOMAIN,
|
||||
identifier=event_id.identifier,
|
||||
|
|
|
@ -96,7 +96,7 @@ async def async_get_triggers(
|
|||
"""List device triggers for Netatmo devices."""
|
||||
registry = er.async_get(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
triggers = []
|
||||
triggers: list[dict[str, str]] = []
|
||||
|
||||
for entry in er.async_entries_for_device(registry, device_id):
|
||||
if (
|
||||
|
@ -106,8 +106,7 @@ async def async_get_triggers(
|
|||
|
||||
for trigger in DEVICES.get(device.model, []):
|
||||
if trigger in SUBTYPES:
|
||||
for subtype in SUBTYPES[trigger]:
|
||||
triggers.append(
|
||||
triggers.extend(
|
||||
{
|
||||
CONF_PLATFORM: "device",
|
||||
CONF_DEVICE_ID: device_id,
|
||||
|
@ -116,6 +115,7 @@ async def async_get_triggers(
|
|||
CONF_TYPE: trigger,
|
||||
CONF_SUBTYPE: subtype,
|
||||
}
|
||||
for subtype in SUBTYPES[trigger]
|
||||
)
|
||||
else:
|
||||
triggers.append(
|
||||
|
|
|
@ -280,31 +280,17 @@ async def async_setup_entry(
|
|||
coordinator_utilization = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_UTIL]
|
||||
coordinator_link = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_LINK]
|
||||
|
||||
# Router entities
|
||||
router_entities = []
|
||||
|
||||
for description in SENSOR_TRAFFIC_TYPES:
|
||||
router_entities.append(
|
||||
NetgearRouterSensorEntity(coordinator_traffic, router, description)
|
||||
async_add_entities(
|
||||
NetgearRouterSensorEntity(coordinator, router, description)
|
||||
for (coordinator, descriptions) in (
|
||||
(coordinator_traffic, SENSOR_TRAFFIC_TYPES),
|
||||
(coordinator_speed, SENSOR_SPEED_TYPES),
|
||||
(coordinator_utilization, SENSOR_UTILIZATION),
|
||||
(coordinator_link, SENSOR_LINK_TYPES),
|
||||
)
|
||||
|
||||
for description in SENSOR_SPEED_TYPES:
|
||||
router_entities.append(
|
||||
NetgearRouterSensorEntity(coordinator_speed, router, description)
|
||||
for description in descriptions
|
||||
)
|
||||
|
||||
for description in SENSOR_UTILIZATION:
|
||||
router_entities.append(
|
||||
NetgearRouterSensorEntity(coordinator_utilization, router, description)
|
||||
)
|
||||
|
||||
for description in SENSOR_LINK_TYPES:
|
||||
router_entities.append(
|
||||
NetgearRouterSensorEntity(coordinator_link, router, description)
|
||||
)
|
||||
|
||||
async_add_entities(router_entities)
|
||||
|
||||
# Entities per network device
|
||||
tracked = set()
|
||||
sensors = ["type", "link_rate", "signal"]
|
||||
|
@ -317,17 +303,15 @@ async def async_setup_entry(
|
|||
if not coordinator.data:
|
||||
return
|
||||
|
||||
new_entities = []
|
||||
new_entities: list[NetgearSensorEntity] = []
|
||||
|
||||
for mac, device in router.devices.items():
|
||||
if mac in tracked:
|
||||
continue
|
||||
|
||||
new_entities.extend(
|
||||
[
|
||||
NetgearSensorEntity(coordinator, router, device, attribute)
|
||||
for attribute in sensors
|
||||
]
|
||||
)
|
||||
tracked.add(mac)
|
||||
|
||||
|
|
|
@ -104,13 +104,10 @@ async def async_setup_entry(
|
|||
"""Set up switches for Netgear component."""
|
||||
router = hass.data[DOMAIN][entry.entry_id][KEY_ROUTER]
|
||||
|
||||
# Router entities
|
||||
router_entities = []
|
||||
|
||||
for description in ROUTER_SWITCH_TYPES:
|
||||
router_entities.append(NetgearRouterSwitchEntity(router, description))
|
||||
|
||||
async_add_entities(router_entities)
|
||||
async_add_entities(
|
||||
NetgearRouterSwitchEntity(router, description)
|
||||
for description in ROUTER_SWITCH_TYPES
|
||||
)
|
||||
|
||||
# Entities per network device
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR]
|
||||
|
|
|
@ -131,10 +131,8 @@ async def async_get_announce_addresses(hass: HomeAssistant) -> list[str]:
|
|||
for adapter in adapters:
|
||||
if not adapter["enabled"]:
|
||||
continue
|
||||
for ips in adapter["ipv4"]:
|
||||
addresses.append(str(IPv4Address(ips["address"])))
|
||||
for ips in adapter["ipv6"]:
|
||||
addresses.append(str(IPv6Address(ips["address"])))
|
||||
addresses.extend(str(IPv4Address(ips["address"])) for ips in adapter["ipv4"])
|
||||
addresses.extend(str(IPv6Address(ips["address"])) for ips in adapter["ipv6"])
|
||||
|
||||
# Puts the default IPv4 address first in the list to preserve compatibility,
|
||||
# because some mDNS implementations ignores anything but the first announced
|
||||
|
|
|
@ -68,11 +68,9 @@ async def async_setup_entry(
|
|||
ATTR_CONNECTION
|
||||
]
|
||||
|
||||
sensors: list[NextDnsBinarySensor] = []
|
||||
for description in SENSORS:
|
||||
sensors.append(NextDnsBinarySensor(coordinator, description))
|
||||
|
||||
async_add_entities(sensors)
|
||||
async_add_entities(
|
||||
NextDnsBinarySensor(coordinator, description) for description in SENSORS
|
||||
)
|
||||
|
||||
|
||||
class NextDnsBinarySensor(
|
||||
|
|
|
@ -538,11 +538,9 @@ async def async_setup_entry(
|
|||
ATTR_SETTINGS
|
||||
]
|
||||
|
||||
switches: list[NextDnsSwitch] = []
|
||||
for description in SWITCHES:
|
||||
switches.append(NextDnsSwitch(coordinator, description))
|
||||
|
||||
async_add_entities(switches)
|
||||
async_add_entities(
|
||||
NextDnsSwitch(coordinator, description) for description in SWITCHES
|
||||
)
|
||||
|
||||
|
||||
class NextDnsSwitch(CoordinatorEntity[NextDnsSettingsUpdateCoordinator], SwitchEntity):
|
||||
|
|
|
@ -44,16 +44,12 @@ async def async_setup_entry(
|
|||
regions: dict[str, str] = config_entry.data[CONF_REGIONS]
|
||||
message_slots: int = config_entry.data[CONF_MESSAGE_SLOTS]
|
||||
|
||||
entities: list[NINAMessage] = []
|
||||
|
||||
for ent in coordinator.data:
|
||||
for i in range(0, message_slots):
|
||||
entities.append(
|
||||
async_add_entities(
|
||||
NINAMessage(coordinator, ent, regions[ent], i + 1, config_entry)
|
||||
for ent in coordinator.data
|
||||
for i in range(0, message_slots)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class NINAMessage(CoordinatorEntity[NINADataUpdateCoordinator], BinarySensorEntity):
|
||||
"""Representation of an NINA warning."""
|
||||
|
|
|
@ -24,16 +24,16 @@ async def async_setup_entry(
|
|||
|
||||
requester: ObihaiConnection = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
sensors = []
|
||||
for key in requester.services:
|
||||
sensors.append(ObihaiServiceSensors(requester, key))
|
||||
sensors = [ObihaiServiceSensors(requester, key) for key in requester.services]
|
||||
|
||||
sensors.extend(
|
||||
ObihaiServiceSensors(requester, key) for key in requester.call_direction
|
||||
)
|
||||
|
||||
if requester.line_services is not None:
|
||||
for key in requester.line_services:
|
||||
sensors.append(ObihaiServiceSensors(requester, key))
|
||||
|
||||
for key in requester.call_direction:
|
||||
sensors.append(ObihaiServiceSensors(requester, key))
|
||||
sensors.extend(
|
||||
ObihaiServiceSensors(requester, key) for key in requester.line_services
|
||||
)
|
||||
|
||||
async_add_entities(sensors, update_before_add=True)
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ async def async_setup_entry(
|
|||
if not coordinator.data["printer"]:
|
||||
return
|
||||
|
||||
new_tools = []
|
||||
new_tools: list[OctoPrintTemperatureSensor] = []
|
||||
for tool in [
|
||||
tool
|
||||
for tool in coordinator.data["printer"].temperatures
|
||||
|
@ -63,14 +63,14 @@ async def async_setup_entry(
|
|||
]:
|
||||
assert device_id is not None
|
||||
known_tools.add(tool.name)
|
||||
for temp_type in ("actual", "target"):
|
||||
new_tools.append(
|
||||
new_tools.extend(
|
||||
OctoPrintTemperatureSensor(
|
||||
coordinator,
|
||||
tool.name,
|
||||
temp_type,
|
||||
device_id,
|
||||
)
|
||||
for temp_type in ("actual", "target")
|
||||
)
|
||||
async_add_entities(new_tools)
|
||||
|
||||
|
|
|
@ -80,16 +80,13 @@ async def async_setup_platform(
|
|||
"country": config[CONF_REGION],
|
||||
}
|
||||
|
||||
entities = []
|
||||
for camera in config[CONF_SOURCE]:
|
||||
entities.append(
|
||||
async_add_entities(
|
||||
OpenAlprCloudEntity(
|
||||
camera[CONF_ENTITY_ID], params, confidence, camera.get(CONF_NAME)
|
||||
)
|
||||
for camera in config[CONF_SOURCE]
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ImageProcessingAlprEntity(ImageProcessingEntity):
|
||||
"""Base entity class for ALPR image processing."""
|
||||
|
|
|
@ -109,24 +109,21 @@ def setup_platform(
|
|||
)
|
||||
return
|
||||
|
||||
entities = []
|
||||
if CONF_CLASSIFIER not in config:
|
||||
dest_path = hass.config.path(DEFAULT_CLASSIFIER_PATH)
|
||||
_get_default_classifier(dest_path)
|
||||
config[CONF_CLASSIFIER] = {"Face": dest_path}
|
||||
|
||||
for camera in config[CONF_SOURCE]:
|
||||
entities.append(
|
||||
add_entities(
|
||||
OpenCVImageProcessor(
|
||||
hass,
|
||||
camera[CONF_ENTITY_ID],
|
||||
camera.get(CONF_NAME),
|
||||
config[CONF_CLASSIFIER],
|
||||
)
|
||||
for camera in config[CONF_SOURCE]
|
||||
)
|
||||
|
||||
add_entities(entities)
|
||||
|
||||
|
||||
class OpenCVImageProcessor(ImageProcessingEntity):
|
||||
"""Representation of an OpenCV image processor."""
|
||||
|
|
|
@ -28,26 +28,20 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the OpenTherm Gateway binary sensors."""
|
||||
sensors = []
|
||||
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]]
|
||||
for var, info in BINARY_SENSOR_INFO.items():
|
||||
device_class = info[0]
|
||||
friendly_name_format = info[1]
|
||||
status_sources = info[2]
|
||||
|
||||
for source in status_sources:
|
||||
sensors.append(
|
||||
async_add_entities(
|
||||
OpenThermBinarySensor(
|
||||
gw_dev,
|
||||
var,
|
||||
source,
|
||||
device_class,
|
||||
friendly_name_format,
|
||||
info[0],
|
||||
info[1],
|
||||
)
|
||||
for var, info in BINARY_SENSOR_INFO.items()
|
||||
for source in info[2]
|
||||
)
|
||||
|
||||
async_add_entities(sensors)
|
||||
|
||||
|
||||
class OpenThermBinarySensor(BinarySensorEntity):
|
||||
"""Represent an OpenTherm Gateway binary sensor."""
|
||||
|
|
|
@ -23,30 +23,22 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the OpenTherm Gateway sensors."""
|
||||
sensors = []
|
||||
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]]
|
||||
for var, info in SENSOR_INFO.items():
|
||||
device_class = info[0]
|
||||
unit = info[1]
|
||||
friendly_name_format = info[2]
|
||||
suggested_display_precision = info[3]
|
||||
status_sources = info[4]
|
||||
|
||||
for source in status_sources:
|
||||
sensors.append(
|
||||
async_add_entities(
|
||||
OpenThermSensor(
|
||||
gw_dev,
|
||||
var,
|
||||
source,
|
||||
device_class,
|
||||
unit,
|
||||
friendly_name_format,
|
||||
suggested_display_precision,
|
||||
info[0],
|
||||
info[1],
|
||||
info[2],
|
||||
info[3],
|
||||
)
|
||||
for var, info in SENSOR_INFO.items()
|
||||
for source in info[4]
|
||||
)
|
||||
|
||||
async_add_entities(sensors)
|
||||
|
||||
|
||||
class OpenThermSensor(SensorEntity):
|
||||
"""Representation of an OpenTherm Gateway sensor."""
|
||||
|
|
|
@ -187,8 +187,7 @@ async def async_setup_entry(
|
|||
and forecast.unit_of_measure in [UnitOfMeasure.THERM, UnitOfMeasure.CCF]
|
||||
):
|
||||
sensors = GAS_SENSORS
|
||||
for sensor in sensors:
|
||||
entities.append(
|
||||
entities.extend(
|
||||
OpowerSensor(
|
||||
coordinator,
|
||||
sensor,
|
||||
|
@ -196,6 +195,7 @@ async def async_setup_entry(
|
|||
device,
|
||||
device_id,
|
||||
)
|
||||
for sensor in sensors
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
|
@ -45,11 +45,9 @@ async def async_setup_entry(
|
|||
"""Set up OSO Energy heater based on a config entry."""
|
||||
osoenergy = hass.data[DOMAIN][entry.entry_id]
|
||||
devices = osoenergy.session.device_list.get("water_heater")
|
||||
entities = []
|
||||
if devices:
|
||||
for dev in devices:
|
||||
entities.append(OSOEnergyWaterHeater(osoenergy, dev))
|
||||
async_add_entities(entities, True)
|
||||
if not devices:
|
||||
return
|
||||
async_add_entities((OSOEnergyWaterHeater(osoenergy, dev) for dev in devices), True)
|
||||
|
||||
|
||||
class OSOEnergyWaterHeater(
|
||||
|
|
|
@ -221,21 +221,19 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the Overkiz alarm control panel from a config entry."""
|
||||
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
||||
entities: list[OverkizAlarmControlPanel] = []
|
||||
|
||||
for device in data.platforms[Platform.ALARM_CONTROL_PANEL]:
|
||||
if description := SUPPORTED_DEVICES.get(device.widget) or SUPPORTED_DEVICES.get(
|
||||
device.ui_class
|
||||
):
|
||||
entities.append(
|
||||
async_add_entities(
|
||||
OverkizAlarmControlPanel(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
for device in data.platforms[Platform.ALARM_CONTROL_PANEL]
|
||||
if (
|
||||
description := SUPPORTED_DEVICES.get(device.widget)
|
||||
or SUPPORTED_DEVICES.get(device.ui_class)
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class OverkizAlarmControlPanel(OverkizDescriptiveEntity, AlarmControlPanelEntity):
|
||||
|
|
|
@ -128,14 +128,14 @@ async def async_setup_entry(
|
|||
):
|
||||
continue
|
||||
|
||||
for state in device.definition.states:
|
||||
if description := SUPPORTED_STATES.get(state.qualified_name):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
OverkizBinarySensor(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
for state in device.definition.states
|
||||
if (description := SUPPORTED_STATES.get(state.qualified_name))
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
|
@ -95,14 +95,14 @@ async def async_setup_entry(
|
|||
):
|
||||
continue
|
||||
|
||||
for command in device.definition.commands:
|
||||
if description := SUPPORTED_COMMANDS.get(command.command_name):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
OverkizButton(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
for command in device.definition.commands
|
||||
if (description := SUPPORTED_COMMANDS.get(command.command_name))
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
|
@ -183,14 +183,14 @@ async def async_setup_entry(
|
|||
):
|
||||
continue
|
||||
|
||||
for state in device.definition.states:
|
||||
if description := SUPPORTED_STATES.get(state.qualified_name):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
OverkizNumber(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
for state in device.definition.states
|
||||
if (description := SUPPORTED_STATES.get(state.qualified_name))
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
|
@ -143,14 +143,14 @@ async def async_setup_entry(
|
|||
):
|
||||
continue
|
||||
|
||||
for state in device.definition.states:
|
||||
if description := SUPPORTED_STATES.get(state.qualified_name):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
OverkizSelect(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
for state in device.definition.states
|
||||
if (description := SUPPORTED_STATES.get(state.qualified_name))
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
|
@ -459,14 +459,14 @@ async def async_setup_entry(
|
|||
):
|
||||
continue
|
||||
|
||||
for state in device.definition.states:
|
||||
if description := SUPPORTED_STATES.get(state.qualified_name):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
OverkizStateSensor(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
for state in device.definition.states
|
||||
if (description := SUPPORTED_STATES.get(state.qualified_name))
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
|
@ -116,21 +116,19 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the Overkiz switch from a config entry."""
|
||||
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
||||
entities: list[OverkizSwitch] = []
|
||||
|
||||
for device in data.platforms[Platform.SWITCH]:
|
||||
if description := SUPPORTED_DEVICES.get(device.widget) or SUPPORTED_DEVICES.get(
|
||||
device.ui_class
|
||||
):
|
||||
entities.append(
|
||||
async_add_entities(
|
||||
OverkizSwitch(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
for device in data.platforms[Platform.SWITCH]
|
||||
if (
|
||||
description := SUPPORTED_DEVICES.get(device.widget)
|
||||
or SUPPORTED_DEVICES.get(device.ui_class)
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class OverkizSwitch(OverkizDescriptiveEntity, SwitchEntity):
|
||||
|
|
|
@ -187,11 +187,7 @@ async def handle_webhook(hass, webhook_id, request):
|
|||
|
||||
async_dispatcher_send(hass, DOMAIN, hass, context, message)
|
||||
|
||||
response = []
|
||||
|
||||
for person in hass.states.async_all("person"):
|
||||
if "latitude" in person.attributes and "longitude" in person.attributes:
|
||||
response.append(
|
||||
response = [
|
||||
{
|
||||
"_type": "location",
|
||||
"lat": person.attributes["latitude"],
|
||||
|
@ -199,7 +195,9 @@ async def handle_webhook(hass, webhook_id, request):
|
|||
"tid": "".join(p[0] for p in person.name.split(" ")[:2]),
|
||||
"tst": int(person.last_updated.timestamp()),
|
||||
}
|
||||
)
|
||||
for person in hass.states.async_all("person")
|
||||
if "latitude" in person.attributes and "longitude" in person.attributes
|
||||
]
|
||||
|
||||
if message["_type"] == "encrypted" and context.secret:
|
||||
return json_response(
|
||||
|
|
|
@ -63,8 +63,7 @@ async def test_get_triggers(
|
|||
expected_triggers = []
|
||||
for event_type in event_types:
|
||||
if event_type in SUBTYPES:
|
||||
for subtype in SUBTYPES[event_type]:
|
||||
expected_triggers.append(
|
||||
expected_triggers.extend(
|
||||
{
|
||||
"platform": "device",
|
||||
"domain": NETATMO_DOMAIN,
|
||||
|
@ -74,6 +73,7 @@ async def test_get_triggers(
|
|||
"entity_id": entity_entry.id,
|
||||
"metadata": {"secondary": False},
|
||||
}
|
||||
for subtype in SUBTYPES[event_type]
|
||||
)
|
||||
else:
|
||||
expected_triggers.append(
|
||||
|
|
|
@ -102,7 +102,9 @@ def _setup_owproxy_mock_device_reads(
|
|||
device_sensors = mock_device.get(platform, [])
|
||||
if platform is Platform.SENSOR and device_id.startswith("12"):
|
||||
# We need to check if there is TAI8570 plugged in
|
||||
for expected_sensor in device_sensors:
|
||||
sub_read_side_effect.append(expected_sensor[ATTR_INJECT_READS])
|
||||
for expected_sensor in device_sensors:
|
||||
sub_read_side_effect.append(expected_sensor[ATTR_INJECT_READS])
|
||||
sub_read_side_effect.extend(
|
||||
expected_sensor[ATTR_INJECT_READS] for expected_sensor in device_sensors
|
||||
)
|
||||
sub_read_side_effect.extend(
|
||||
expected_sensor[ATTR_INJECT_READS] for expected_sensor in device_sensors
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue