From 595d07f1c684cac83f4993917c92a6bfed59d478 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 13 Mar 2024 21:28:21 +0100 Subject: [PATCH] Improve lists in integrations [L-M] (#113227) * Improve lists in integrations [L-M] * Update homeassistant/components/mailbox/__init__.py Co-authored-by: Jan Bouwhuis * Fix --------- Co-authored-by: Jan Bouwhuis --- homeassistant/components/lamarzocco/number.py | 13 ++++---- .../components/landisgyr_heat_meter/sensor.py | 9 +++--- homeassistant/components/lcn/binary_sensor.py | 13 +++----- homeassistant/components/lcn/climate.py | 13 +++----- homeassistant/components/lcn/cover.py | 11 +++---- homeassistant/components/lcn/light.py | 11 +++---- homeassistant/components/lcn/scene.py | 11 +++---- homeassistant/components/lcn/sensor.py | 11 +++---- homeassistant/components/lcn/switch.py | 12 +++---- .../components/lg_soundbar/media_player.py | 20 ++++++------ homeassistant/components/lifx/coordinator.py | 3 +- homeassistant/components/logbook/helpers.py | 8 ++--- homeassistant/components/london_air/sensor.py | 15 +++++---- .../components/london_underground/sensor.py | 8 ++--- .../components/luci/device_tracker.py | 19 +++++------- .../components/lupusec/binary_sensor.py | 7 ++--- homeassistant/components/lupusec/switch.py | 7 ++--- .../lutron_caseta/device_trigger.py | 26 +++++++--------- homeassistant/components/lyric/climate.py | 31 +++++++++---------- homeassistant/components/lyric/sensor.py | 13 +++++++- homeassistant/components/mailbox/__init__.py | 10 +++--- homeassistant/components/matrix/__init__.py | 18 +++++------ homeassistant/components/maxcube/climate.py | 12 +++---- homeassistant/components/melissa/climate.py | 15 ++++----- homeassistant/components/melnor/models.py | 7 +++-- .../microsoft_face_detect/image_processing.py | 13 +++----- .../image_processing.py | 21 ++++++------- .../components/minecraft_server/api.py | 3 +- .../components/modbus/binary_sensor.py | 7 ++--- homeassistant/components/modbus/sensor.py | 7 ++--- homeassistant/components/mvglive/sensor.py | 11 ++++--- homeassistant/components/mystrom/sensor.py | 11 +++---- homeassistant/components/myuplink/update.py | 20 +++++------- tests/components/mqtt/test_discovery.py | 16 +++++----- 34 files changed, 200 insertions(+), 232 deletions(-) diff --git a/homeassistant/components/lamarzocco/number.py b/homeassistant/components/lamarzocco/number.py index 05f937f48f6..88a06a0c9d0 100644 --- a/homeassistant/components/lamarzocco/number.py +++ b/homeassistant/components/lamarzocco/number.py @@ -208,20 +208,19 @@ async def async_setup_entry( """Set up number entities.""" coordinator = hass.data[DOMAIN][config_entry.entry_id] - async_add_entities( + entities: list[NumberEntity] = [ LaMarzoccoNumberEntity(coordinator, description) for description in ENTITIES if description.supported_fn(coordinator) - ) + ] - entities: list[LaMarzoccoKeyNumberEntity] = [] for description in KEY_ENTITIES: if description.supported_fn(coordinator): num_keys = KEYS_PER_MODEL[coordinator.lm.model_name] - for key in range(min(num_keys, 1), num_keys + 1): - entities.append( - LaMarzoccoKeyNumberEntity(coordinator, description, key) - ) + entities.extend( + LaMarzoccoKeyNumberEntity(coordinator, description, key) + for key in range(min(num_keys, 1), num_keys + 1) + ) async_add_entities(entities) diff --git a/homeassistant/components/landisgyr_heat_meter/sensor.py b/homeassistant/components/landisgyr_heat_meter/sensor.py index 9078a46f876..dd76d3e53cc 100644 --- a/homeassistant/components/landisgyr_heat_meter/sensor.py +++ b/homeassistant/components/landisgyr_heat_meter/sensor.py @@ -286,11 +286,10 @@ async def async_setup_entry( name="Landis+Gyr Heat Meter", ) - sensors = [] - for description in HEAT_METER_SENSOR_TYPES: - sensors.append(HeatMeterSensor(coordinator, description, device)) - - async_add_entities(sensors) + async_add_entities( + HeatMeterSensor(coordinator, description, device) + for description in HEAT_METER_SENSOR_TYPES + ) class HeatMeterSensor( diff --git a/homeassistant/components/lcn/binary_sensor.py b/homeassistant/components/lcn/binary_sensor.py index 2670777d9b3..35836e4653e 100644 --- a/homeassistant/components/lcn/binary_sensor.py +++ b/homeassistant/components/lcn/binary_sensor.py @@ -43,15 +43,12 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up LCN switch entities from a config entry.""" - entities = [] - for entity_config in config_entry.data[CONF_ENTITIES]: - if entity_config[CONF_DOMAIN] == DOMAIN_BINARY_SENSOR: - entities.append( - create_lcn_binary_sensor_entity(hass, entity_config, config_entry) - ) - - async_add_entities(entities) + async_add_entities( + create_lcn_binary_sensor_entity(hass, entity_config, config_entry) + for entity_config in config_entry.data[CONF_ENTITIES] + if entity_config[CONF_DOMAIN] == DOMAIN_BINARY_SENSOR + ) class LcnRegulatorLockSensor(LcnEntity, BinarySensorEntity): diff --git a/homeassistant/components/lcn/climate.py b/homeassistant/components/lcn/climate.py index abe0080811d..c03061618f7 100644 --- a/homeassistant/components/lcn/climate.py +++ b/homeassistant/components/lcn/climate.py @@ -56,15 +56,12 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up LCN switch entities from a config entry.""" - entities = [] - for entity_config in config_entry.data[CONF_ENTITIES]: - if entity_config[CONF_DOMAIN] == DOMAIN_CLIMATE: - entities.append( - create_lcn_climate_entity(hass, entity_config, config_entry) - ) - - async_add_entities(entities) + async_add_entities( + create_lcn_climate_entity(hass, entity_config, config_entry) + for entity_config in config_entry.data[CONF_ENTITIES] + if entity_config[CONF_DOMAIN] == DOMAIN_CLIMATE + ) class LcnClimate(LcnEntity, ClimateEntity): diff --git a/homeassistant/components/lcn/cover.py b/homeassistant/components/lcn/cover.py index 6738add28e4..edc60a202a1 100644 --- a/homeassistant/components/lcn/cover.py +++ b/homeassistant/components/lcn/cover.py @@ -40,13 +40,12 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up LCN cover entities from a config entry.""" - entities = [] - for entity_config in config_entry.data[CONF_ENTITIES]: - if entity_config[CONF_DOMAIN] == DOMAIN_COVER: - entities.append(create_lcn_cover_entity(hass, entity_config, config_entry)) - - async_add_entities(entities) + async_add_entities( + create_lcn_cover_entity(hass, entity_config, config_entry) + for entity_config in config_entry.data[CONF_ENTITIES] + if entity_config[CONF_DOMAIN] == DOMAIN_COVER + ) class LcnOutputsCover(LcnEntity, CoverEntity): diff --git a/homeassistant/components/lcn/light.py b/homeassistant/components/lcn/light.py index 3f1467c74c1..584161a0829 100644 --- a/homeassistant/components/lcn/light.py +++ b/homeassistant/components/lcn/light.py @@ -53,13 +53,12 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up LCN light entities from a config entry.""" - entities = [] - for entity_config in config_entry.data[CONF_ENTITIES]: - if entity_config[CONF_DOMAIN] == DOMAIN_LIGHT: - entities.append(create_lcn_light_entity(hass, entity_config, config_entry)) - - async_add_entities(entities) + async_add_entities( + create_lcn_light_entity(hass, entity_config, config_entry) + for entity_config in config_entry.data[CONF_ENTITIES] + if entity_config[CONF_DOMAIN] == DOMAIN_LIGHT + ) class LcnOutputLight(LcnEntity, LightEntity): diff --git a/homeassistant/components/lcn/scene.py b/homeassistant/components/lcn/scene.py index fe8040bc291..7e476987c53 100644 --- a/homeassistant/components/lcn/scene.py +++ b/homeassistant/components/lcn/scene.py @@ -43,13 +43,12 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up LCN switch entities from a config entry.""" - entities = [] - for entity_config in config_entry.data[CONF_ENTITIES]: - if entity_config[CONF_DOMAIN] == DOMAIN_SCENE: - entities.append(create_lcn_scene_entity(hass, entity_config, config_entry)) - - async_add_entities(entities) + async_add_entities( + create_lcn_scene_entity(hass, entity_config, config_entry) + for entity_config in config_entry.data[CONF_ENTITIES] + if entity_config[CONF_DOMAIN] == DOMAIN_SCENE + ) class LcnScene(LcnEntity, Scene): diff --git a/homeassistant/components/lcn/sensor.py b/homeassistant/components/lcn/sensor.py index 38f76e8d2d1..32b97ab8317 100644 --- a/homeassistant/components/lcn/sensor.py +++ b/homeassistant/components/lcn/sensor.py @@ -56,13 +56,12 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up LCN switch entities from a config entry.""" - entities = [] - for entity_config in config_entry.data[CONF_ENTITIES]: - if entity_config[CONF_DOMAIN] == DOMAIN_SENSOR: - entities.append(create_lcn_sensor_entity(hass, entity_config, config_entry)) - - async_add_entities(entities) + async_add_entities( + create_lcn_sensor_entity(hass, entity_config, config_entry) + for entity_config in config_entry.data[CONF_ENTITIES] + if entity_config[CONF_DOMAIN] == DOMAIN_SENSOR + ) class LcnVariableSensor(LcnEntity, SensorEntity): diff --git a/homeassistant/components/lcn/switch.py b/homeassistant/components/lcn/switch.py index 05e8d8d3937..b82394ced0d 100644 --- a/homeassistant/components/lcn/switch.py +++ b/homeassistant/components/lcn/switch.py @@ -41,13 +41,11 @@ async def async_setup_entry( ) -> None: """Set up LCN switch entities from a config entry.""" - entities = [] - - for entity_config in config_entry.data[CONF_ENTITIES]: - if entity_config[CONF_DOMAIN] == DOMAIN_SWITCH: - entities.append(create_lcn_switch_entity(hass, entity_config, config_entry)) - - async_add_entities(entities) + async_add_entities( + create_lcn_switch_entity(hass, entity_config, config_entry) + for entity_config in config_entry.data[CONF_ENTITIES] + if entity_config[CONF_DOMAIN] == DOMAIN_SWITCH + ) class LcnOutputSwitch(LcnEntity, SwitchEntity): diff --git a/homeassistant/components/lg_soundbar/media_player.py b/homeassistant/components/lg_soundbar/media_player.py index 962f67f714d..61baed1198b 100644 --- a/homeassistant/components/lg_soundbar/media_player.py +++ b/homeassistant/components/lg_soundbar/media_player.py @@ -166,11 +166,11 @@ class LGDevice(MediaPlayerEntity): @property def sound_mode_list(self): """Return the available sound modes.""" - modes = [] - for equaliser in self._equalisers: - if equaliser < len(temescal.equalisers): - modes.append(temescal.equalisers[equaliser]) - return sorted(modes) + return sorted( + temescal.equalisers[equaliser] + for equaliser in self._equalisers + if equaliser < len(temescal.equalisers) + ) @property def source(self): @@ -182,11 +182,11 @@ class LGDevice(MediaPlayerEntity): @property def source_list(self): """List of available input sources.""" - sources = [] - for function in self._functions: - if function < len(temescal.functions): - sources.append(temescal.functions[function]) - return sorted(sources) + return sorted( + temescal.functions[function] + for function in self._functions + if function < len(temescal.functions) + ) def set_volume_level(self, volume: float) -> None: """Set volume level, range 0..1.""" diff --git a/homeassistant/components/lifx/coordinator.py b/homeassistant/components/lifx/coordinator.py index 2b15b65255f..63912cbb820 100644 --- a/homeassistant/components/lifx/coordinator.py +++ b/homeassistant/components/lifx/coordinator.py @@ -381,8 +381,7 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]): # pad the color list with blanks if necessary if len(colors) < 82: - for _ in range(82 - len(colors)): - colors.append((0, 0, 0, 0)) + colors.extend([(0, 0, 0, 0) for _ in range(82 - len(colors))]) await async_execute_lifx( partial( diff --git a/homeassistant/components/logbook/helpers.py b/homeassistant/components/logbook/helpers.py index e3288452fb7..1731fcaddd9 100644 --- a/homeassistant/components/logbook/helpers.py +++ b/homeassistant/components/logbook/helpers.py @@ -176,10 +176,10 @@ def async_subscribe_events( event_forwarder = event_forwarder_filtered( target, entities_filter, entity_ids, device_ids ) - for event_type in event_types: - subscriptions.append( - hass.bus.async_listen(event_type, event_forwarder, run_immediately=True) - ) + subscriptions.extend( + hass.bus.async_listen(event_type, event_forwarder, run_immediately=True) + for event_type in event_types + ) if device_ids and not entity_ids: # No entities to subscribe to but we are filtering diff --git a/homeassistant/components/london_air/sensor.py b/homeassistant/components/london_air/sensor.py index 39debb5ba4c..12d52b9a20a 100644 --- a/homeassistant/components/london_air/sensor.py +++ b/homeassistant/components/london_air/sensor.py @@ -72,11 +72,8 @@ def setup_platform( """Set up the London Air sensor.""" data = APIData() data.update() - sensors = [] - for name in config[CONF_LOCATIONS]: - sensors.append(AirSensor(name, data)) - add_entities(sensors, True) + add_entities((AirSensor(name, data) for name in config[CONF_LOCATIONS]), True) class APIData: @@ -141,14 +138,16 @@ class AirSensor(SensorEntity): def update(self) -> None: """Update the sensor.""" - sites_status = [] + sites_status: list = [] self._api_data.update() if self._api_data.data: self._site_data = self._api_data.data[self._name] self._updated = self._site_data[0]["updated"] - for site in self._site_data: - if site["pollutants_status"] != "no_species_data": - sites_status.append(site["pollutants_status"]) + sites_status.extend( + site["pollutants_status"] + for site in self._site_data + if site["pollutants_status"] != "no_species_data" + ) if sites_status: self._state = max(set(sites_status), key=sites_status.count) diff --git a/homeassistant/components/london_underground/sensor.py b/homeassistant/components/london_underground/sensor.py index 03bdc1c395f..e5735aa7fba 100644 --- a/homeassistant/components/london_underground/sensor.py +++ b/homeassistant/components/london_underground/sensor.py @@ -45,11 +45,9 @@ async def async_setup_platform( if not coordinator.last_update_success: raise PlatformNotReady - sensors = [] - for line in config[CONF_LINE]: - sensors.append(LondonTubeSensor(coordinator, line)) - - async_add_entities(sensors) + async_add_entities( + LondonTubeSensor(coordinator, line) for line in config[CONF_LINE] + ) class LondonTubeSensor(CoordinatorEntity[LondonTubeCoordinator], SensorEntity): diff --git a/homeassistant/components/luci/device_tracker.py b/homeassistant/components/luci/device_tracker.py index 528596d53c5..d62c1b07b5c 100644 --- a/homeassistant/components/luci/device_tracker.py +++ b/homeassistant/components/luci/device_tracker.py @@ -96,14 +96,11 @@ class LuciDeviceScanner(DeviceScanner): _LOGGER.debug("Luci get_all_connected_devices returned: %s", result) - last_results = [] - for device in result: - if ( - not hasattr(self.router.router.owrt_version, "release") - or not self.router.router.owrt_version.release - or self.router.router.owrt_version.release[0] < 19 - or device.reachable - ): - last_results.append(device) - - self.last_results = last_results + self.last_results = [ + device + for device in result + if not hasattr(self.router.router.owrt_version, "release") + or not self.router.router.owrt_version.release + or self.router.router.owrt_version.release[0] < 19 + or device.reachable + ] diff --git a/homeassistant/components/lupusec/binary_sensor.py b/homeassistant/components/lupusec/binary_sensor.py index e046d356327..b2413e2b462 100644 --- a/homeassistant/components/lupusec/binary_sensor.py +++ b/homeassistant/components/lupusec/binary_sensor.py @@ -35,13 +35,12 @@ async def async_setup_entry( device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR - sensors = [] partial_func = partial(data.get_devices, generic_type=device_types) devices = await hass.async_add_executor_job(partial_func) - for device in devices: - sensors.append(LupusecBinarySensor(device, config_entry.entry_id)) - async_add_entities(sensors) + async_add_entities( + LupusecBinarySensor(device, config_entry.entry_id) for device in devices + ) class LupusecBinarySensor(LupusecBaseSensor, BinarySensorEntity): diff --git a/homeassistant/components/lupusec/switch.py b/homeassistant/components/lupusec/switch.py index 3fa62235b9a..23f3c927880 100644 --- a/homeassistant/components/lupusec/switch.py +++ b/homeassistant/components/lupusec/switch.py @@ -30,13 +30,12 @@ async def async_setup_entry( device_types = CONST.TYPE_SWITCH - switches = [] partial_func = partial(data.get_devices, generic_type=device_types) devices = await hass.async_add_executor_job(partial_func) - for device in devices: - switches.append(LupusecSwitch(device, config_entry.entry_id)) - async_add_entities(switches) + async_add_entities( + LupusecSwitch(device, config_entry.entry_id) for device in devices + ) class LupusecSwitch(LupusecBaseSensor, SwitchEntity): diff --git a/homeassistant/components/lutron_caseta/device_trigger.py b/homeassistant/components/lutron_caseta/device_trigger.py index fd5d2ad222d..86b82e64127 100644 --- a/homeassistant/components/lutron_caseta/device_trigger.py +++ b/homeassistant/components/lutron_caseta/device_trigger.py @@ -379,8 +379,6 @@ async def async_get_triggers( hass: HomeAssistant, device_id: str ) -> list[dict[str, str]]: """List device triggers for lutron caseta devices.""" - triggers = [] - # Check if device is a valid keypad. Return empty if not. if not (data := get_lutron_data_by_dr_id(hass, device_id)) or not ( keypad := data.keypad_data.dr_device_id_to_keypad.get(device_id) @@ -395,19 +393,17 @@ async def async_get_triggers( keypad_button_names_to_leap[keypad["lutron_device_id"]], ) - for trigger in SUPPORTED_INPUTS_EVENTS_TYPES: - for subtype in valid_buttons: - triggers.append( - { - CONF_PLATFORM: "device", - CONF_DEVICE_ID: device_id, - CONF_DOMAIN: DOMAIN, - CONF_TYPE: trigger, - CONF_SUBTYPE: subtype, - } - ) - - return triggers + return [ + { + CONF_PLATFORM: "device", + CONF_DEVICE_ID: device_id, + CONF_DOMAIN: DOMAIN, + CONF_TYPE: trigger, + CONF_SUBTYPE: subtype, + } + for trigger in SUPPORTED_INPUTS_EVENTS_TYPES + for subtype in valid_buttons + ] async def async_attach_trigger( diff --git a/homeassistant/components/lyric/climate.py b/homeassistant/components/lyric/climate.py index 3bba2f677b0..f8ae978c2fd 100644 --- a/homeassistant/components/lyric/climate.py +++ b/homeassistant/components/lyric/climate.py @@ -126,23 +126,22 @@ async def async_setup_entry( """Set up the Honeywell Lyric climate platform based on a config entry.""" coordinator: DataUpdateCoordinator[Lyric] = hass.data[DOMAIN][entry.entry_id] - entities = [] - - for location in coordinator.data.locations: - for device in location.devices: - entities.append( - LyricClimate( - coordinator, - ClimateEntityDescription( - key=f"{device.macID}_thermostat", - name=device.name, - ), - location, - device, - ) + async_add_entities( + ( + LyricClimate( + coordinator, + ClimateEntityDescription( + key=f"{device.macID}_thermostat", + name=device.name, + ), + location, + device, ) - - async_add_entities(entities, True) + for location in coordinator.data.locations + for device in location.devices + ), + True, + ) platform = entity_platform.async_get_current_platform() diff --git a/homeassistant/components/lyric/sensor.py b/homeassistant/components/lyric/sensor.py index f1e9a8b3c3c..1072ca6c2ba 100644 --- a/homeassistant/components/lyric/sensor.py +++ b/homeassistant/components/lyric/sensor.py @@ -149,7 +149,18 @@ async def async_setup_entry( ) ) - async_add_entities(entities) + async_add_entities( + LyricSensor( + coordinator, + device_sensor, + location, + device, + ) + for location in coordinator.data.locations + for device in location.devices + for device_sensor in DEVICE_SENSORS + if device_sensor.suitable_fn(device) + ) class LyricSensor(LyricDeviceEntity, SensorEntity): diff --git a/homeassistant/components/mailbox/__init__.py b/homeassistant/components/mailbox/__init__.py index ef9a36ca20c..4d585413519 100644 --- a/homeassistant/components/mailbox/__init__.py +++ b/homeassistant/components/mailbox/__init__.py @@ -232,16 +232,16 @@ class MailboxPlatformsView(MailboxView): async def get(self, request: web.Request) -> web.Response: """Retrieve list of platforms.""" - platforms: list[dict[str, Any]] = [] - for mailbox in self.mailboxes: - platforms.append( + return self.json( + [ { "name": mailbox.name, "has_media": mailbox.has_media, "can_delete": mailbox.can_delete, } - ) - return self.json(platforms) + for mailbox in self.mailboxes + ] + ) class MailboxMessageView(MailboxView): diff --git a/homeassistant/components/matrix/__init__.py b/homeassistant/components/matrix/__init__.py index 5c7d66b7a0b..b8f1ec08fe0 100644 --- a/homeassistant/components/matrix/__init__.py +++ b/homeassistant/components/matrix/__init__.py @@ -432,18 +432,16 @@ class MatrixBot: self, target_rooms: Sequence[RoomAnyID], message_type: str, content: dict ) -> None: """Wrap _handle_room_send for multiple target_rooms.""" - _tasks = [] - for target_room in target_rooms: - _tasks.append( - self.hass.async_create_task( - self._handle_room_send( - target_room=target_room, - message_type=message_type, - content=content, - ) + await asyncio.wait( + self.hass.async_create_task( + self._handle_room_send( + target_room=target_room, + message_type=message_type, + content=content, ) ) - await asyncio.wait(_tasks) + for target_room in target_rooms + ) async def _send_image( self, image_path: str, target_rooms: Sequence[RoomAnyID] diff --git a/homeassistant/components/maxcube/climate.py b/homeassistant/components/maxcube/climate.py index 1b7dc6b901d..b14efbbe073 100644 --- a/homeassistant/components/maxcube/climate.py +++ b/homeassistant/components/maxcube/climate.py @@ -54,13 +54,13 @@ def setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Iterate through all MAX! Devices and add thermostats.""" - devices = [] - for handler in hass.data[DATA_KEY].values(): - for device in handler.cube.devices: - if device.is_thermostat() or device.is_wallthermostat(): - devices.append(MaxCubeClimate(handler, device)) - add_entities(devices) + add_entities( + MaxCubeClimate(handler, device) + for handler in hass.data[DATA_KEY].values() + for device in handler.cube.devices + if device.is_thermostat() or device.is_wallthermostat() + ) class MaxCubeClimate(ClimateEntity): diff --git a/homeassistant/components/melissa/climate.py b/homeassistant/components/melissa/climate.py index 73b04ff8c1d..fcb0820a6f0 100644 --- a/homeassistant/components/melissa/climate.py +++ b/homeassistant/components/melissa/climate.py @@ -44,13 +44,14 @@ async def async_setup_platform( api = hass.data[DATA_MELISSA] devices = (await api.async_fetch_devices()).values() - all_devices = [] - - for device in devices: - if device["type"] == "melissa": - all_devices.append(MelissaClimate(api, device["serial_number"], device)) - - async_add_entities(all_devices, True) + async_add_entities( + ( + MelissaClimate(api, device["serial_number"], device) + for device in devices + if device["type"] == "melissa" + ), + True, + ) class MelissaClimate(ClimateEntity): diff --git a/homeassistant/components/melnor/models.py b/homeassistant/components/melnor/models.py index beb8b42a4a3..ffcccccb789 100644 --- a/homeassistant/components/melnor/models.py +++ b/homeassistant/components/melnor/models.py @@ -117,14 +117,15 @@ def get_entities_for_valves( ], ) -> list[CoordinatorEntity[MelnorDataUpdateCoordinator]]: """Get descriptions for valves.""" - entities = [] + entities: list[CoordinatorEntity[MelnorDataUpdateCoordinator]] = [] # This device may not have 4 valves total, but the library will only expose the right number of valves for i in range(1, 5): valve = coordinator.data[f"zone{i}"] if valve is not None: - for description in descriptions: - entities.append(function(valve, description)) + entities.extend( + function(valve, description) for description in descriptions + ) return entities diff --git a/homeassistant/components/microsoft_face_detect/image_processing.py b/homeassistant/components/microsoft_face_detect/image_processing.py index 536557bdddb..ef8a4f5df4b 100644 --- a/homeassistant/components/microsoft_face_detect/image_processing.py +++ b/homeassistant/components/microsoft_face_detect/image_processing.py @@ -56,15 +56,12 @@ async def async_setup_platform( api = hass.data[DATA_MICROSOFT_FACE] attributes = config[CONF_ATTRIBUTES] - entities = [] - for camera in config[CONF_SOURCE]: - entities.append( - MicrosoftFaceDetectEntity( - camera[CONF_ENTITY_ID], api, attributes, camera.get(CONF_NAME) - ) + async_add_entities( + MicrosoftFaceDetectEntity( + camera[CONF_ENTITY_ID], api, attributes, camera.get(CONF_NAME) ) - - async_add_entities(entities) + for camera in config[CONF_SOURCE] + ) class MicrosoftFaceDetectEntity(ImageProcessingFaceEntity): diff --git a/homeassistant/components/microsoft_face_identify/image_processing.py b/homeassistant/components/microsoft_face_identify/image_processing.py index 7903df22996..d1af1d4a827 100644 --- a/homeassistant/components/microsoft_face_identify/image_processing.py +++ b/homeassistant/components/microsoft_face_identify/image_processing.py @@ -38,19 +38,16 @@ async def async_setup_platform( face_group = config[CONF_GROUP] confidence = config[CONF_CONFIDENCE] - entities = [] - for camera in config[CONF_SOURCE]: - entities.append( - MicrosoftFaceIdentifyEntity( - camera[CONF_ENTITY_ID], - api, - face_group, - confidence, - camera.get(CONF_NAME), - ) + async_add_entities( + MicrosoftFaceIdentifyEntity( + camera[CONF_ENTITY_ID], + api, + face_group, + confidence, + camera.get(CONF_NAME), ) - - async_add_entities(entities) + for camera in config[CONF_SOURCE] + ) class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity): diff --git a/homeassistant/components/minecraft_server/api.py b/homeassistant/components/minecraft_server/api.py index 7b0d7475f84..3155d83a736 100644 --- a/homeassistant/components/minecraft_server/api.py +++ b/homeassistant/components/minecraft_server/api.py @@ -140,8 +140,7 @@ class MinecraftServer: players_list: list[str] = [] if players := status_response.players.sample: - for player in players: - players_list.append(player.name) + players_list.extend(player.name for player in players) players_list.sort() return MinecraftServerData( diff --git a/homeassistant/components/modbus/binary_sensor.py b/homeassistant/components/modbus/binary_sensor.py index 0de7a87f219..23192244332 100644 --- a/homeassistant/components/modbus/binary_sensor.py +++ b/homeassistant/components/modbus/binary_sensor.py @@ -93,10 +93,9 @@ class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity): name=name, ) - slaves: list[SlaveSensor] = [] - for idx in range(0, slave_count): - slaves.append(SlaveSensor(self._coordinator, idx, entry)) - return slaves + return [ + SlaveSensor(self._coordinator, idx, entry) for idx in range(0, slave_count) + ] async def async_added_to_hass(self) -> None: """Handle entity which will be added.""" diff --git a/homeassistant/components/modbus/sensor.py b/homeassistant/components/modbus/sensor.py index b21a001c935..f74c4bf4e1b 100644 --- a/homeassistant/components/modbus/sensor.py +++ b/homeassistant/components/modbus/sensor.py @@ -94,10 +94,9 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreSensor, SensorEntity): name=name, ) - slaves: list[SlaveSensor] = [] - for idx in range(0, slave_count): - slaves.append(SlaveSensor(self._coordinator, idx, entry)) - return slaves + return [ + SlaveSensor(self._coordinator, idx, entry) for idx in range(0, slave_count) + ] async def async_added_to_hass(self) -> None: """Handle entity which will be added.""" diff --git a/homeassistant/components/mvglive/sensor.py b/homeassistant/components/mvglive/sensor.py index 39d77edbfa7..6aefa83d4bb 100644 --- a/homeassistant/components/mvglive/sensor.py +++ b/homeassistant/components/mvglive/sensor.py @@ -71,9 +71,8 @@ def setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the MVGLive sensor.""" - sensors = [] - for nextdeparture in config[CONF_NEXT_DEPARTURE]: - sensors.append( + add_entities( + ( MVGLiveSensor( nextdeparture.get(CONF_STATION), nextdeparture.get(CONF_DESTINATIONS), @@ -84,8 +83,10 @@ def setup_platform( nextdeparture.get(CONF_NUMBER), nextdeparture.get(CONF_NAME), ) - ) - add_entities(sensors, True) + for nextdeparture in config[CONF_NEXT_DEPARTURE] + ), + True, + ) class MVGLiveSensor(SensorEntity): diff --git a/homeassistant/components/mystrom/sensor.py b/homeassistant/components/mystrom/sensor.py index f7805cd9012..5c096c87993 100644 --- a/homeassistant/components/mystrom/sensor.py +++ b/homeassistant/components/mystrom/sensor.py @@ -52,13 +52,12 @@ async def async_setup_entry( ) -> None: """Set up the myStrom entities.""" device: MyStromSwitch = hass.data[DOMAIN][entry.entry_id].device - sensors = [] - for description in SENSOR_TYPES: - if description.value_fn(device) is not None: - sensors.append(MyStromSwitchSensor(device, entry.title, description)) - - async_add_entities(sensors) + async_add_entities( + MyStromSwitchSensor(device, entry.title, description) + for description in SENSOR_TYPES + if description.value_fn(device) is not None + ) class MyStromSwitchSensor(SensorEntity): diff --git a/homeassistant/components/myuplink/update.py b/homeassistant/components/myuplink/update.py index 2b779e83386..6a38741a562 100644 --- a/homeassistant/components/myuplink/update.py +++ b/homeassistant/components/myuplink/update.py @@ -25,21 +25,17 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up update entity.""" - entities: list[UpdateEntity] = [] coordinator: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id] - # Setup update entities - for device_id in coordinator.data.devices: - entities.append( - MyUplinkDeviceUpdate( - coordinator=coordinator, - device_id=device_id, - entity_description=UPDATE_DESCRIPTION, - unique_id_suffix="upd", - ) + async_add_entities( + MyUplinkDeviceUpdate( + coordinator=coordinator, + device_id=device_id, + entity_description=UPDATE_DESCRIPTION, + unique_id_suffix="upd", ) - - async_add_entities(entities) + for device_id in coordinator.data.devices + ) class MyUplinkDeviceUpdate(MyUplinkEntity, UpdateEntity): diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index e1fbb95791e..3d3baf1307c 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -1399,15 +1399,13 @@ async def test_missing_discover_abbreviations( continue with open(fil, encoding="utf-8") as file: matches = re.findall(regex, file.read()) - for match in matches: - if ( - match[1] not in ABBREVIATIONS.values() - and match[1] not in DEVICE_ABBREVIATIONS.values() - and match[0] not in ABBREVIATIONS_WHITE_LIST - ): - missing.append( - f"{fil}: no abbreviation for {match[1]} ({match[0]})" - ) + missing.extend( + f"{fil}: no abbreviation for {match[1]} ({match[0]})" + for match in matches + if match[1] not in ABBREVIATIONS.values() + and match[1] not in DEVICE_ABBREVIATIONS.values() + and match[0] not in ABBREVIATIONS_WHITE_LIST + ) assert not missing