Improve lists in integrations [N-O] (#113231)

pull/113270/head
Joost Lekkerkerker 2024-03-13 21:51:38 +01:00 committed by GitHub
parent 595d07f1c6
commit e6a692f354
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 254 additions and 310 deletions

View File

@ -367,12 +367,11 @@ async def async_setup_entry(
) )
ent_reg.async_update_entity(entity_id, new_unique_id=new_unique_id) ent_reg.async_update_entity(entity_id, new_unique_id=new_unique_id)
sensors: list[NAMSensor] = [] async_add_entities(
for description in SENSORS: NAMSensor(coordinator, description)
if getattr(coordinator.data, description.key) is not None: for description in SENSORS
sensors.append(NAMSensor(coordinator, description)) if getattr(coordinator.data, description.key) is not None
)
async_add_entities(sensors, False)
class NAMSensor(CoordinatorEntity[NAMDataUpdateCoordinator], SensorEntity): class NAMSensor(CoordinatorEntity[NAMDataUpdateCoordinator], SensorEntity):

View File

@ -29,12 +29,13 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up Neato camera with config entry.""" """Set up Neato camera with config entry."""
dev = []
neato: NeatoHub = hass.data[NEATO_LOGIN] neato: NeatoHub = hass.data[NEATO_LOGIN]
mapdata: dict[str, Any] | None = hass.data.get(NEATO_MAP_DATA) mapdata: dict[str, Any] | None = hass.data.get(NEATO_MAP_DATA)
for robot in hass.data[NEATO_ROBOTS]: dev = [
if "maps" in robot.traits: NeatoCleaningMap(neato, robot, mapdata)
dev.append(NeatoCleaningMap(neato, robot, mapdata)) for robot in hass.data[NEATO_ROBOTS]
if "maps" in robot.traits
]
if not dev: if not dev:
return return

View File

@ -30,10 +30,8 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up the Neato sensor using config entry.""" """Set up the Neato sensor using config entry."""
dev = []
neato: NeatoHub = hass.data[NEATO_LOGIN] neato: NeatoHub = hass.data[NEATO_LOGIN]
for robot in hass.data[NEATO_ROBOTS]: dev = [NeatoSensor(neato, robot) for robot in hass.data[NEATO_ROBOTS]]
dev.append(NeatoSensor(neato, robot))
if not dev: if not dev:
return return

View File

@ -32,12 +32,12 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up Neato switch with config entry.""" """Set up Neato switch with config entry."""
dev = []
neato: NeatoHub = hass.data[NEATO_LOGIN] neato: NeatoHub = hass.data[NEATO_LOGIN]
dev = [
for robot in hass.data[NEATO_ROBOTS]: NeatoConnectedSwitch(neato, robot, type_name)
for type_name in SWITCH_TYPES: for robot in hass.data[NEATO_ROBOTS]
dev.append(NeatoConnectedSwitch(neato, robot, type_name)) for type_name in SWITCH_TYPES
]
if not dev: if not dev:
return return

View File

@ -64,12 +64,13 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up Neato vacuum with config entry.""" """Set up Neato vacuum with config entry."""
dev = []
neato: NeatoHub = hass.data[NEATO_LOGIN] neato: NeatoHub = hass.data[NEATO_LOGIN]
mapdata: dict[str, Any] | None = hass.data.get(NEATO_MAP_DATA) mapdata: dict[str, Any] | None = hass.data.get(NEATO_MAP_DATA)
persistent_maps: dict[str, Any] | None = hass.data.get(NEATO_PERSISTENT_MAPS) persistent_maps: dict[str, Any] | None = hass.data.get(NEATO_PERSISTENT_MAPS)
for robot in hass.data[NEATO_ROBOTS]: dev = [
dev.append(NeatoConnectedVacuum(neato, robot, mapdata, persistent_maps)) NeatoConnectedVacuum(neato, robot, mapdata, persistent_maps)
for robot in hass.data[NEATO_ROBOTS]
]
if not dev: if not dev:
return return

View File

@ -135,8 +135,7 @@ class NSDepartureSensor(SensorEntity):
if self._trips[0].trip_parts: if self._trips[0].trip_parts:
route = [self._trips[0].departure] route = [self._trips[0].departure]
for k in self._trips[0].trip_parts: route.extend(k.destination for k in self._trips[0].trip_parts)
route.append(k.destination)
# Static attributes # Static attributes
attributes = { attributes = {

View File

@ -48,14 +48,12 @@ async def async_setup_entry(
device_manager: DeviceManager = hass.data[DOMAIN][entry.entry_id][ device_manager: DeviceManager = hass.data[DOMAIN][entry.entry_id][
DATA_DEVICE_MANAGER DATA_DEVICE_MANAGER
] ]
entities = [] async_add_entities(
for device in device_manager.devices.values(): NestCamera(device)
if ( for device in device_manager.devices.values()
CameraImageTrait.NAME in device.traits if CameraImageTrait.NAME in device.traits
or CameraLiveStreamTrait.NAME in device.traits or CameraLiveStreamTrait.NAME in device.traits
): )
entities.append(NestCamera(device))
async_add_entities(entities)
class NestCamera(Camera): class NestCamera(Camera):

View File

@ -86,11 +86,12 @@ async def async_setup_entry(
device_manager: DeviceManager = hass.data[DOMAIN][entry.entry_id][ device_manager: DeviceManager = hass.data[DOMAIN][entry.entry_id][
DATA_DEVICE_MANAGER DATA_DEVICE_MANAGER
] ]
entities = []
for device in device_manager.devices.values(): async_add_entities(
if ThermostatHvacTrait.NAME in device.traits: ThermostatEntity(device)
entities.append(ThermostatEntity(device)) for device in device_manager.devices.values()
async_add_entities(entities) if ThermostatHvacTrait.NAME in device.traits
)
class ThermostatEntity(ClimateEntity): class ThermostatEntity(ClimateEntity):
@ -217,13 +218,13 @@ class ThermostatEntity(ClimateEntity):
@property @property
def preset_modes(self) -> list[str]: def preset_modes(self) -> list[str]:
"""Return the available presets.""" """Return the available presets."""
modes = [] if ThermostatEcoTrait.NAME not in self._device.traits:
if ThermostatEcoTrait.NAME in self._device.traits: return []
trait = self._device.traits[ThermostatEcoTrait.NAME] return [
for mode in trait.available_modes: PRESET_MODE_MAP[mode]
if mode in PRESET_MODE_MAP: for mode in self._device.traits[ThermostatEcoTrait.NAME].available_modes
modes.append(PRESET_MODE_MAP[mode]) if mode in PRESET_MODE_MAP
return modes ]
@property @property
def fan_mode(self) -> str: def fan_mode(self) -> str:

View File

@ -71,10 +71,11 @@ def _generate_subscription_id(cloud_project_id: str) -> str:
def generate_config_title(structures: Iterable[Structure]) -> str | None: def generate_config_title(structures: Iterable[Structure]) -> str | None:
"""Pick a user friendly config title based on the Google Home name(s).""" """Pick a user friendly config title based on the Google Home name(s)."""
names: list[str] = [] names: list[str] = [
for structure in structures: trait.custom_name
if (trait := structure.traits.get(InfoTrait.NAME)) and trait.custom_name: for structure in structures
names.append(trait.custom_name) if (trait := structure.traits.get(InfoTrait.NAME)) and trait.custom_name
]
if not names: if not names:
return None return None
return ", ".join(names) return ", ".join(names)

View File

@ -490,9 +490,10 @@ def _browse_clip_preview(
event_id: MediaId, device: Device, event: ClipPreviewSession event_id: MediaId, device: Device, event: ClipPreviewSession
) -> BrowseMediaSource: ) -> BrowseMediaSource:
"""Build a BrowseMediaSource for a specific clip preview event.""" """Build a BrowseMediaSource for a specific clip preview event."""
types = [] types = [
for event_type in event.event_types: MEDIA_SOURCE_EVENT_TITLE_MAP.get(event_type, "Event")
types.append(MEDIA_SOURCE_EVENT_TITLE_MAP.get(event_type, "Event")) for event_type in event.event_types
]
return BrowseMediaSource( return BrowseMediaSource(
domain=DOMAIN, domain=DOMAIN,
identifier=event_id.identifier, identifier=event_id.identifier,

View File

@ -96,7 +96,7 @@ async def async_get_triggers(
"""List device triggers for Netatmo devices.""" """List device triggers for Netatmo devices."""
registry = er.async_get(hass) registry = er.async_get(hass)
device_registry = dr.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): for entry in er.async_entries_for_device(registry, device_id):
if ( if (
@ -106,17 +106,17 @@ async def async_get_triggers(
for trigger in DEVICES.get(device.model, []): for trigger in DEVICES.get(device.model, []):
if trigger in SUBTYPES: if trigger in SUBTYPES:
for subtype in SUBTYPES[trigger]: triggers.extend(
triggers.append( {
{ CONF_PLATFORM: "device",
CONF_PLATFORM: "device", CONF_DEVICE_ID: device_id,
CONF_DEVICE_ID: device_id, CONF_DOMAIN: DOMAIN,
CONF_DOMAIN: DOMAIN, CONF_ENTITY_ID: entry.id,
CONF_ENTITY_ID: entry.id, CONF_TYPE: trigger,
CONF_TYPE: trigger, CONF_SUBTYPE: subtype,
CONF_SUBTYPE: subtype, }
} for subtype in SUBTYPES[trigger]
) )
else: else:
triggers.append( triggers.append(
{ {

View File

@ -280,30 +280,16 @@ async def async_setup_entry(
coordinator_utilization = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_UTIL] coordinator_utilization = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_UTIL]
coordinator_link = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_LINK] coordinator_link = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_LINK]
# Router entities async_add_entities(
router_entities = [] NetgearRouterSensorEntity(coordinator, router, description)
for (coordinator, descriptions) in (
for description in SENSOR_TRAFFIC_TYPES: (coordinator_traffic, SENSOR_TRAFFIC_TYPES),
router_entities.append( (coordinator_speed, SENSOR_SPEED_TYPES),
NetgearRouterSensorEntity(coordinator_traffic, router, description) (coordinator_utilization, SENSOR_UTILIZATION),
(coordinator_link, SENSOR_LINK_TYPES),
) )
for description in descriptions
for description in SENSOR_SPEED_TYPES: )
router_entities.append(
NetgearRouterSensorEntity(coordinator_speed, router, description)
)
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 # Entities per network device
tracked = set() tracked = set()
@ -317,17 +303,15 @@ async def async_setup_entry(
if not coordinator.data: if not coordinator.data:
return return
new_entities = [] new_entities: list[NetgearSensorEntity] = []
for mac, device in router.devices.items(): for mac, device in router.devices.items():
if mac in tracked: if mac in tracked:
continue continue
new_entities.extend( new_entities.extend(
[ NetgearSensorEntity(coordinator, router, device, attribute)
NetgearSensorEntity(coordinator, router, device, attribute) for attribute in sensors
for attribute in sensors
]
) )
tracked.add(mac) tracked.add(mac)

View File

@ -104,13 +104,10 @@ async def async_setup_entry(
"""Set up switches for Netgear component.""" """Set up switches for Netgear component."""
router = hass.data[DOMAIN][entry.entry_id][KEY_ROUTER] router = hass.data[DOMAIN][entry.entry_id][KEY_ROUTER]
# Router entities async_add_entities(
router_entities = [] NetgearRouterSwitchEntity(router, description)
for description in ROUTER_SWITCH_TYPES
for description in ROUTER_SWITCH_TYPES: )
router_entities.append(NetgearRouterSwitchEntity(router, description))
async_add_entities(router_entities)
# Entities per network device # Entities per network device
coordinator = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR] coordinator = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR]

View File

@ -131,10 +131,8 @@ async def async_get_announce_addresses(hass: HomeAssistant) -> list[str]:
for adapter in adapters: for adapter in adapters:
if not adapter["enabled"]: if not adapter["enabled"]:
continue continue
for ips in adapter["ipv4"]: addresses.extend(str(IPv4Address(ips["address"])) for ips in adapter["ipv4"])
addresses.append(str(IPv4Address(ips["address"]))) addresses.extend(str(IPv6Address(ips["address"])) for ips in adapter["ipv6"])
for ips in adapter["ipv6"]:
addresses.append(str(IPv6Address(ips["address"])))
# Puts the default IPv4 address first in the list to preserve compatibility, # Puts the default IPv4 address first in the list to preserve compatibility,
# because some mDNS implementations ignores anything but the first announced # because some mDNS implementations ignores anything but the first announced

View File

@ -68,11 +68,9 @@ async def async_setup_entry(
ATTR_CONNECTION ATTR_CONNECTION
] ]
sensors: list[NextDnsBinarySensor] = [] async_add_entities(
for description in SENSORS: NextDnsBinarySensor(coordinator, description) for description in SENSORS
sensors.append(NextDnsBinarySensor(coordinator, description)) )
async_add_entities(sensors)
class NextDnsBinarySensor( class NextDnsBinarySensor(

View File

@ -538,11 +538,9 @@ async def async_setup_entry(
ATTR_SETTINGS ATTR_SETTINGS
] ]
switches: list[NextDnsSwitch] = [] async_add_entities(
for description in SWITCHES: NextDnsSwitch(coordinator, description) for description in SWITCHES
switches.append(NextDnsSwitch(coordinator, description)) )
async_add_entities(switches)
class NextDnsSwitch(CoordinatorEntity[NextDnsSettingsUpdateCoordinator], SwitchEntity): class NextDnsSwitch(CoordinatorEntity[NextDnsSettingsUpdateCoordinator], SwitchEntity):

View File

@ -44,15 +44,11 @@ async def async_setup_entry(
regions: dict[str, str] = config_entry.data[CONF_REGIONS] regions: dict[str, str] = config_entry.data[CONF_REGIONS]
message_slots: int = config_entry.data[CONF_MESSAGE_SLOTS] message_slots: int = config_entry.data[CONF_MESSAGE_SLOTS]
entities: list[NINAMessage] = [] async_add_entities(
NINAMessage(coordinator, ent, regions[ent], i + 1, config_entry)
for ent in coordinator.data: for ent in coordinator.data
for i in range(0, message_slots): for i in range(0, message_slots)
entities.append( )
NINAMessage(coordinator, ent, regions[ent], i + 1, config_entry)
)
async_add_entities(entities)
class NINAMessage(CoordinatorEntity[NINADataUpdateCoordinator], BinarySensorEntity): class NINAMessage(CoordinatorEntity[NINADataUpdateCoordinator], BinarySensorEntity):

View File

@ -24,16 +24,16 @@ async def async_setup_entry(
requester: ObihaiConnection = hass.data[DOMAIN][entry.entry_id] requester: ObihaiConnection = hass.data[DOMAIN][entry.entry_id]
sensors = [] sensors = [ObihaiServiceSensors(requester, key) for key in requester.services]
for key in requester.services:
sensors.append(ObihaiServiceSensors(requester, key)) sensors.extend(
ObihaiServiceSensors(requester, key) for key in requester.call_direction
)
if requester.line_services is not None: if requester.line_services is not None:
for key in requester.line_services: sensors.extend(
sensors.append(ObihaiServiceSensors(requester, key)) ObihaiServiceSensors(requester, key) for key in requester.line_services
)
for key in requester.call_direction:
sensors.append(ObihaiServiceSensors(requester, key))
async_add_entities(sensors, update_before_add=True) async_add_entities(sensors, update_before_add=True)

View File

@ -55,7 +55,7 @@ async def async_setup_entry(
if not coordinator.data["printer"]: if not coordinator.data["printer"]:
return return
new_tools = [] new_tools: list[OctoPrintTemperatureSensor] = []
for tool in [ for tool in [
tool tool
for tool in coordinator.data["printer"].temperatures for tool in coordinator.data["printer"].temperatures
@ -63,15 +63,15 @@ async def async_setup_entry(
]: ]:
assert device_id is not None assert device_id is not None
known_tools.add(tool.name) known_tools.add(tool.name)
for temp_type in ("actual", "target"): new_tools.extend(
new_tools.append( OctoPrintTemperatureSensor(
OctoPrintTemperatureSensor( coordinator,
coordinator, tool.name,
tool.name, temp_type,
temp_type, device_id,
device_id,
)
) )
for temp_type in ("actual", "target")
)
async_add_entities(new_tools) async_add_entities(new_tools)
config_entry.async_on_unload(coordinator.async_add_listener(async_add_tool_sensors)) config_entry.async_on_unload(coordinator.async_add_listener(async_add_tool_sensors))

View File

@ -80,15 +80,12 @@ async def async_setup_platform(
"country": config[CONF_REGION], "country": config[CONF_REGION],
} }
entities = [] async_add_entities(
for camera in config[CONF_SOURCE]: OpenAlprCloudEntity(
entities.append( camera[CONF_ENTITY_ID], params, confidence, camera.get(CONF_NAME)
OpenAlprCloudEntity(
camera[CONF_ENTITY_ID], params, confidence, camera.get(CONF_NAME)
)
) )
for camera in config[CONF_SOURCE]
async_add_entities(entities) )
class ImageProcessingAlprEntity(ImageProcessingEntity): class ImageProcessingAlprEntity(ImageProcessingEntity):

View File

@ -109,23 +109,20 @@ def setup_platform(
) )
return return
entities = []
if CONF_CLASSIFIER not in config: if CONF_CLASSIFIER not in config:
dest_path = hass.config.path(DEFAULT_CLASSIFIER_PATH) dest_path = hass.config.path(DEFAULT_CLASSIFIER_PATH)
_get_default_classifier(dest_path) _get_default_classifier(dest_path)
config[CONF_CLASSIFIER] = {"Face": dest_path} config[CONF_CLASSIFIER] = {"Face": dest_path}
for camera in config[CONF_SOURCE]: add_entities(
entities.append( OpenCVImageProcessor(
OpenCVImageProcessor( hass,
hass, camera[CONF_ENTITY_ID],
camera[CONF_ENTITY_ID], camera.get(CONF_NAME),
camera.get(CONF_NAME), config[CONF_CLASSIFIER],
config[CONF_CLASSIFIER],
)
) )
for camera in config[CONF_SOURCE]
add_entities(entities) )
class OpenCVImageProcessor(ImageProcessingEntity): class OpenCVImageProcessor(ImageProcessingEntity):

View File

@ -28,25 +28,19 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback, async_add_entities: AddEntitiesCallback,
) -> None: ) -> None:
"""Set up the OpenTherm Gateway binary sensors.""" """Set up the OpenTherm Gateway binary sensors."""
sensors = []
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]] 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: async_add_entities(
sensors.append( OpenThermBinarySensor(
OpenThermBinarySensor( gw_dev,
gw_dev, var,
var, source,
source, info[0],
device_class, info[1],
friendly_name_format, )
) for var, info in BINARY_SENSOR_INFO.items()
) for source in info[2]
)
async_add_entities(sensors)
class OpenThermBinarySensor(BinarySensorEntity): class OpenThermBinarySensor(BinarySensorEntity):

View File

@ -23,29 +23,21 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback, async_add_entities: AddEntitiesCallback,
) -> None: ) -> None:
"""Set up the OpenTherm Gateway sensors.""" """Set up the OpenTherm Gateway sensors."""
sensors = []
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]] 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: async_add_entities(
sensors.append( OpenThermSensor(
OpenThermSensor( gw_dev,
gw_dev, var,
var, source,
source, info[0],
device_class, info[1],
unit, info[2],
friendly_name_format, info[3],
suggested_display_precision, )
) for var, info in SENSOR_INFO.items()
) for source in info[4]
)
async_add_entities(sensors)
class OpenThermSensor(SensorEntity): class OpenThermSensor(SensorEntity):

View File

@ -187,16 +187,16 @@ async def async_setup_entry(
and forecast.unit_of_measure in [UnitOfMeasure.THERM, UnitOfMeasure.CCF] and forecast.unit_of_measure in [UnitOfMeasure.THERM, UnitOfMeasure.CCF]
): ):
sensors = GAS_SENSORS sensors = GAS_SENSORS
for sensor in sensors: entities.extend(
entities.append( OpowerSensor(
OpowerSensor( coordinator,
coordinator, sensor,
sensor, forecast.account.utility_account_id,
forecast.account.utility_account_id, device,
device, device_id,
device_id,
)
) )
for sensor in sensors
)
async_add_entities(entities) async_add_entities(entities)

View File

@ -45,11 +45,9 @@ async def async_setup_entry(
"""Set up OSO Energy heater based on a config entry.""" """Set up OSO Energy heater based on a config entry."""
osoenergy = hass.data[DOMAIN][entry.entry_id] osoenergy = hass.data[DOMAIN][entry.entry_id]
devices = osoenergy.session.device_list.get("water_heater") devices = osoenergy.session.device_list.get("water_heater")
entities = [] if not devices:
if devices: return
for dev in devices: async_add_entities((OSOEnergyWaterHeater(osoenergy, dev) for dev in devices), True)
entities.append(OSOEnergyWaterHeater(osoenergy, dev))
async_add_entities(entities, True)
class OSOEnergyWaterHeater( class OSOEnergyWaterHeater(

View File

@ -221,21 +221,19 @@ async def async_setup_entry(
) -> None: ) -> None:
"""Set up the Overkiz alarm control panel from a config entry.""" """Set up the Overkiz alarm control panel from a config entry."""
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
entities: list[OverkizAlarmControlPanel] = []
for device in data.platforms[Platform.ALARM_CONTROL_PANEL]: async_add_entities(
if description := SUPPORTED_DEVICES.get(device.widget) or SUPPORTED_DEVICES.get( OverkizAlarmControlPanel(
device.ui_class device.device_url,
): data.coordinator,
entities.append( description,
OverkizAlarmControlPanel( )
device.device_url, for device in data.platforms[Platform.ALARM_CONTROL_PANEL]
data.coordinator, if (
description, description := SUPPORTED_DEVICES.get(device.widget)
) or SUPPORTED_DEVICES.get(device.ui_class)
) )
)
async_add_entities(entities)
class OverkizAlarmControlPanel(OverkizDescriptiveEntity, AlarmControlPanelEntity): class OverkizAlarmControlPanel(OverkizDescriptiveEntity, AlarmControlPanelEntity):

View File

@ -128,15 +128,15 @@ async def async_setup_entry(
): ):
continue continue
for state in device.definition.states: entities.extend(
if description := SUPPORTED_STATES.get(state.qualified_name): OverkizBinarySensor(
entities.append( device.device_url,
OverkizBinarySensor( data.coordinator,
device.device_url, description,
data.coordinator, )
description, for state in device.definition.states
) if (description := SUPPORTED_STATES.get(state.qualified_name))
) )
async_add_entities(entities) async_add_entities(entities)

View File

@ -95,15 +95,15 @@ async def async_setup_entry(
): ):
continue continue
for command in device.definition.commands: entities.extend(
if description := SUPPORTED_COMMANDS.get(command.command_name): OverkizButton(
entities.append( device.device_url,
OverkizButton( data.coordinator,
device.device_url, description,
data.coordinator, )
description, for command in device.definition.commands
) if (description := SUPPORTED_COMMANDS.get(command.command_name))
) )
async_add_entities(entities) async_add_entities(entities)

View File

@ -183,15 +183,15 @@ async def async_setup_entry(
): ):
continue continue
for state in device.definition.states: entities.extend(
if description := SUPPORTED_STATES.get(state.qualified_name): OverkizNumber(
entities.append( device.device_url,
OverkizNumber( data.coordinator,
device.device_url, description,
data.coordinator, )
description, for state in device.definition.states
) if (description := SUPPORTED_STATES.get(state.qualified_name))
) )
async_add_entities(entities) async_add_entities(entities)

View File

@ -143,15 +143,15 @@ async def async_setup_entry(
): ):
continue continue
for state in device.definition.states: entities.extend(
if description := SUPPORTED_STATES.get(state.qualified_name): OverkizSelect(
entities.append( device.device_url,
OverkizSelect( data.coordinator,
device.device_url, description,
data.coordinator, )
description, for state in device.definition.states
) if (description := SUPPORTED_STATES.get(state.qualified_name))
) )
async_add_entities(entities) async_add_entities(entities)

View File

@ -459,15 +459,15 @@ async def async_setup_entry(
): ):
continue continue
for state in device.definition.states: entities.extend(
if description := SUPPORTED_STATES.get(state.qualified_name): OverkizStateSensor(
entities.append( device.device_url,
OverkizStateSensor( data.coordinator,
device.device_url, description,
data.coordinator, )
description, for state in device.definition.states
) if (description := SUPPORTED_STATES.get(state.qualified_name))
) )
async_add_entities(entities) async_add_entities(entities)

View File

@ -116,21 +116,19 @@ async def async_setup_entry(
) -> None: ) -> None:
"""Set up the Overkiz switch from a config entry.""" """Set up the Overkiz switch from a config entry."""
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
entities: list[OverkizSwitch] = []
for device in data.platforms[Platform.SWITCH]: async_add_entities(
if description := SUPPORTED_DEVICES.get(device.widget) or SUPPORTED_DEVICES.get( OverkizSwitch(
device.ui_class device.device_url,
): data.coordinator,
entities.append( description,
OverkizSwitch( )
device.device_url, for device in data.platforms[Platform.SWITCH]
data.coordinator, if (
description, description := SUPPORTED_DEVICES.get(device.widget)
) or SUPPORTED_DEVICES.get(device.ui_class)
) )
)
async_add_entities(entities)
class OverkizSwitch(OverkizDescriptiveEntity, SwitchEntity): class OverkizSwitch(OverkizDescriptiveEntity, SwitchEntity):

View File

@ -187,19 +187,17 @@ async def handle_webhook(hass, webhook_id, request):
async_dispatcher_send(hass, DOMAIN, hass, context, message) async_dispatcher_send(hass, DOMAIN, hass, context, message)
response = [] response = [
{
for person in hass.states.async_all("person"): "_type": "location",
if "latitude" in person.attributes and "longitude" in person.attributes: "lat": person.attributes["latitude"],
response.append( "lon": person.attributes["longitude"],
{ "tid": "".join(p[0] for p in person.name.split(" ")[:2]),
"_type": "location", "tst": int(person.last_updated.timestamp()),
"lat": person.attributes["latitude"], }
"lon": person.attributes["longitude"], for person in hass.states.async_all("person")
"tid": "".join(p[0] for p in person.name.split(" ")[:2]), if "latitude" in person.attributes and "longitude" in person.attributes
"tst": int(person.last_updated.timestamp()), ]
}
)
if message["_type"] == "encrypted" and context.secret: if message["_type"] == "encrypted" and context.secret:
return json_response( return json_response(

View File

@ -63,18 +63,18 @@ async def test_get_triggers(
expected_triggers = [] expected_triggers = []
for event_type in event_types: for event_type in event_types:
if event_type in SUBTYPES: if event_type in SUBTYPES:
for subtype in SUBTYPES[event_type]: expected_triggers.extend(
expected_triggers.append( {
{ "platform": "device",
"platform": "device", "domain": NETATMO_DOMAIN,
"domain": NETATMO_DOMAIN, "type": event_type,
"type": event_type, "subtype": subtype,
"subtype": subtype, "device_id": device_entry.id,
"device_id": device_entry.id, "entity_id": entity_entry.id,
"entity_id": entity_entry.id, "metadata": {"secondary": False},
"metadata": {"secondary": False}, }
} for subtype in SUBTYPES[event_type]
) )
else: else:
expected_triggers.append( expected_triggers.append(
{ {

View File

@ -102,7 +102,9 @@ def _setup_owproxy_mock_device_reads(
device_sensors = mock_device.get(platform, []) device_sensors = mock_device.get(platform, [])
if platform is Platform.SENSOR and device_id.startswith("12"): if platform is Platform.SENSOR and device_id.startswith("12"):
# We need to check if there is TAI8570 plugged in # We need to check if there is TAI8570 plugged in
for expected_sensor in device_sensors: sub_read_side_effect.extend(
sub_read_side_effect.append(expected_sensor[ATTR_INJECT_READS]) expected_sensor[ATTR_INJECT_READS] for expected_sensor in device_sensors
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
)