diff --git a/homeassistant/components/baf/sensor.py b/homeassistant/components/baf/sensor.py index 7a7845c2f67..fc052b1e48b 100644 --- a/homeassistant/components/baf/sensor.py +++ b/homeassistant/components/baf/sensor.py @@ -100,10 +100,11 @@ async def async_setup_entry( """Set up BAF fan sensors.""" data: BAFData = hass.data[DOMAIN][entry.entry_id] device = data.device - sensors_descriptions: list[BAFSensorDescription] = [] - for description in DEFINED_ONLY_SENSORS: - if getattr(device, description.key): - sensors_descriptions.append(description) + sensors_descriptions: list[BAFSensorDescription] = [ + description + for description in DEFINED_ONLY_SENSORS + if getattr(device, description.key) + ] if device.has_auto_comfort: sensors_descriptions.extend(AUTO_COMFORT_SENSORS) if device.has_fan: diff --git a/homeassistant/components/bayesian/binary_sensor.py b/homeassistant/components/bayesian/binary_sensor.py index cccb08c5540..b6298040b6b 100644 --- a/homeassistant/components/bayesian/binary_sensor.py +++ b/homeassistant/components/bayesian/binary_sensor.py @@ -313,9 +313,9 @@ class BayesianBinarySensor(BinarySensorEntity): self.hass, observations, text=f"{self._attr_name}/{entity}" ) - all_template_observations: list[Observation] = [] - for observations in self.observations_by_template.values(): - all_template_observations.append(observations[0]) + all_template_observations: list[Observation] = [ + observations[0] for observations in self.observations_by_template.values() + ] if len(all_template_observations) == 2: raise_mirrored_entries( self.hass, diff --git a/homeassistant/components/blue_current/sensor.py b/homeassistant/components/blue_current/sensor.py index 4d6c82ee530..b544b69d2ff 100644 --- a/homeassistant/components/blue_current/sensor.py +++ b/homeassistant/components/blue_current/sensor.py @@ -217,13 +217,13 @@ async def async_setup_entry( ) -> None: """Set up Blue Current sensors.""" connector: Connector = hass.data[DOMAIN][entry.entry_id] - sensor_list: list[SensorEntity] = [] - for evse_id in connector.charge_points: - for sensor in SENSORS: - sensor_list.append(ChargePointSensor(connector, sensor, evse_id)) + sensor_list: list[SensorEntity] = [ + ChargePointSensor(connector, sensor, evse_id) + for evse_id in connector.charge_points + for sensor in SENSORS + ] - for grid_sensor in GRID_SENSORS: - sensor_list.append(GridSensor(connector, grid_sensor)) + sensor_list.extend(GridSensor(connector, sensor) for sensor in GRID_SENSORS) async_add_entities(sensor_list) diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index a054dadcbc9..357f971f574 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -686,20 +686,15 @@ class BluesoundPlayer(MediaPlayerEntity): if self._status is None or (self.is_grouped and not self.is_master): return None - sources = [] + sources = [source["title"] for source in self._preset_items] - for source in self._preset_items: - sources.append(source["title"]) + sources.extend( + source["title"] + for source in self._services_items + if source["type"] in ("LocalMusic", "RadioService") + ) - for source in [ - x - for x in self._services_items - if x["type"] in ("LocalMusic", "RadioService") - ]: - sources.append(source["title"]) - - for source in self._capture_items: - sources.append(source["title"]) + sources.extend(source["title"] for source in self._capture_items) return sources diff --git a/homeassistant/components/bluetooth/match.py b/homeassistant/components/bluetooth/match.py index 6eba9b65cbb..a5e1159e04e 100644 --- a/homeassistant/components/bluetooth/match.py +++ b/homeassistant/components/bluetooth/match.py @@ -249,39 +249,47 @@ class BluetoothMatcherIndexBase(Generic[_T]): def match(self, service_info: BluetoothServiceInfoBleak) -> list[_T]: """Check for a match.""" - matches = [] + matches: list[_T] = [] if (name := service_info.name) and ( local_name_matchers := self.local_name.get( name[:LOCAL_NAME_MIN_MATCH_LENGTH] ) ): - for matcher in local_name_matchers: - if ble_device_matches(matcher, service_info): - matches.append(matcher) + matches.extend( + matcher + for matcher in local_name_matchers + if ble_device_matches(matcher, service_info) + ) if self.service_data_uuid_set and service_info.service_data: - for service_data_uuid in self.service_data_uuid_set.intersection( - service_info.service_data - ): - for matcher in self.service_data_uuid[service_data_uuid]: - if ble_device_matches(matcher, service_info): - matches.append(matcher) + matches.extend( + matcher + for service_data_uuid in self.service_data_uuid_set.intersection( + service_info.service_data + ) + for matcher in self.service_data_uuid[service_data_uuid] + if ble_device_matches(matcher, service_info) + ) if self.manufacturer_id_set and service_info.manufacturer_data: - for manufacturer_id in self.manufacturer_id_set.intersection( - service_info.manufacturer_data - ): - for matcher in self.manufacturer_id[manufacturer_id]: - if ble_device_matches(matcher, service_info): - matches.append(matcher) + matches.extend( + matcher + for manufacturer_id in self.manufacturer_id_set.intersection( + service_info.manufacturer_data + ) + for matcher in self.manufacturer_id[manufacturer_id] + if ble_device_matches(matcher, service_info) + ) if self.service_uuid_set and service_info.service_uuids: - for service_uuid in self.service_uuid_set.intersection( - service_info.service_uuids - ): - for matcher in self.service_uuid[service_uuid]: - if ble_device_matches(matcher, service_info): - matches.append(matcher) + matches.extend( + matcher + for service_uuid in self.service_uuid_set.intersection( + service_info.service_uuids + ) + for matcher in self.service_uuid[service_uuid] + if ble_device_matches(matcher, service_info) + ) return matches diff --git a/homeassistant/components/bmw_connected_drive/lock.py b/homeassistant/components/bmw_connected_drive/lock.py index d7898f98bc8..3de41bfb911 100644 --- a/homeassistant/components/bmw_connected_drive/lock.py +++ b/homeassistant/components/bmw_connected_drive/lock.py @@ -31,17 +31,10 @@ async def async_setup_entry( """Set up the MyBMW lock from config entry.""" coordinator: BMWDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id] - entities: list[BMWLock] = [] - - for vehicle in coordinator.account.vehicles: - if not coordinator.read_only: - entities.append( - BMWLock( - coordinator, - vehicle, - ) - ) - async_add_entities(entities) + if not coordinator.read_only: + async_add_entities( + BMWLock(coordinator, vehicle) for vehicle in coordinator.account.vehicles + ) class BMWLock(BMWBaseEntity, LockEntity): diff --git a/homeassistant/components/bosch_shc/binary_sensor.py b/homeassistant/components/bosch_shc/binary_sensor.py index 9a016e47f9d..342a3e3e417 100644 --- a/homeassistant/components/bosch_shc/binary_sensor.py +++ b/homeassistant/components/bosch_shc/binary_sensor.py @@ -23,39 +23,38 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the SHC binary sensor platform.""" - entities: list[BinarySensorEntity] = [] session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION] - for binary_sensor in ( - session.device_helper.shutter_contacts + session.device_helper.shutter_contacts2 - ): - entities.append( - ShutterContactSensor( - device=binary_sensor, - parent_id=session.information.unique_id, - entry_id=config_entry.entry_id, - ) + entities: list[BinarySensorEntity] = [ + ShutterContactSensor( + device=binary_sensor, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, ) + for binary_sensor in ( + session.device_helper.shutter_contacts + + session.device_helper.shutter_contacts2 + ) + ] - for binary_sensor in ( - session.device_helper.motion_detectors - + session.device_helper.shutter_contacts - + session.device_helper.shutter_contacts2 - + session.device_helper.smoke_detectors - + session.device_helper.thermostats - + session.device_helper.twinguards - + session.device_helper.universal_switches - + session.device_helper.wallthermostats - + session.device_helper.water_leakage_detectors - ): - if binary_sensor.supports_batterylevel: - entities.append( - BatterySensor( - device=binary_sensor, - parent_id=session.information.unique_id, - entry_id=config_entry.entry_id, - ) - ) + entities.extend( + BatterySensor( + device=binary_sensor, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, + ) + for binary_sensor in ( + session.device_helper.motion_detectors + + session.device_helper.shutter_contacts + + session.device_helper.shutter_contacts2 + + session.device_helper.smoke_detectors + + session.device_helper.thermostats + + session.device_helper.twinguards + + session.device_helper.universal_switches + + session.device_helper.wallthermostats + + session.device_helper.water_leakage_detectors + ) + ) async_add_entities(entities) diff --git a/homeassistant/components/bosch_shc/cover.py b/homeassistant/components/bosch_shc/cover.py index c135cdfa186..5377f0c6a8f 100644 --- a/homeassistant/components/bosch_shc/cover.py +++ b/homeassistant/components/bosch_shc/cover.py @@ -25,19 +25,16 @@ async def async_setup_entry( ) -> None: """Set up the SHC cover platform.""" - entities = [] session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION] - for cover in session.device_helper.shutter_controls: - entities.append( - ShutterControlCover( - device=cover, - parent_id=session.information.unique_id, - entry_id=config_entry.entry_id, - ) + async_add_entities( + ShutterControlCover( + device=cover, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, ) - - async_add_entities(entities) + for cover in session.device_helper.shutter_controls + ) class ShutterControlCover(SHCEntity, CoverEntity): diff --git a/homeassistant/components/bosch_shc/switch.py b/homeassistant/components/bosch_shc/switch.py index 6f815d8f66c..e6ccd2aa9aa 100644 --- a/homeassistant/components/bosch_shc/switch.py +++ b/homeassistant/components/bosch_shc/switch.py @@ -84,65 +84,66 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the SHC switch platform.""" - entities: list[SwitchEntity] = [] session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION] - for switch in session.device_helper.smart_plugs: - entities.append( - SHCSwitch( - device=switch, - parent_id=session.information.unique_id, - entry_id=config_entry.entry_id, - description=SWITCH_TYPES["smartplug"], - ) - ) - entities.append( - SHCRoutingSwitch( - device=switch, - parent_id=session.information.unique_id, - entry_id=config_entry.entry_id, - ) + entities: list[SwitchEntity] = [ + SHCSwitch( + device=switch, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, + description=SWITCH_TYPES["smartplug"], ) + for switch in session.device_helper.smart_plugs + ] - for switch in session.device_helper.light_switches_bsm: - entities.append( - SHCSwitch( - device=switch, - parent_id=session.information.unique_id, - entry_id=config_entry.entry_id, - description=SWITCH_TYPES["lightswitch"], - ) + entities.extend( + SHCRoutingSwitch( + device=switch, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, ) + for switch in session.device_helper.smart_plugs + ) - for switch in session.device_helper.smart_plugs_compact: - entities.append( - SHCSwitch( - device=switch, - parent_id=session.information.unique_id, - entry_id=config_entry.entry_id, - description=SWITCH_TYPES["smartplugcompact"], - ) + entities.extend( + SHCSwitch( + device=switch, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, + description=SWITCH_TYPES["lightswitch"], ) + for switch in session.device_helper.light_switches_bsm + ) - for switch in session.device_helper.camera_eyes: - entities.append( - SHCSwitch( - device=switch, - parent_id=session.information.unique_id, - entry_id=config_entry.entry_id, - description=SWITCH_TYPES["cameraeyes"], - ) + entities.extend( + SHCSwitch( + device=switch, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, + description=SWITCH_TYPES["smartplugcompact"], ) + for switch in session.device_helper.smart_plugs_compact + ) - for switch in session.device_helper.camera_360: - entities.append( - SHCSwitch( - device=switch, - parent_id=session.information.unique_id, - entry_id=config_entry.entry_id, - description=SWITCH_TYPES["camera360"], - ) + entities.extend( + SHCSwitch( + device=switch, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, + description=SWITCH_TYPES["cameraeyes"], ) + for switch in session.device_helper.camera_eyes + ) + + entities.extend( + SHCSwitch( + device=switch, + parent_id=session.information.unique_id, + entry_id=config_entry.entry_id, + description=SWITCH_TYPES["camera360"], + ) + for switch in session.device_helper.camera_360 + ) async_add_entities(entities) diff --git a/homeassistant/components/brother/sensor.py b/homeassistant/components/brother/sensor.py index 12b5bd0fb59..6f56eb680be 100644 --- a/homeassistant/components/brother/sensor.py +++ b/homeassistant/components/brother/sensor.py @@ -339,12 +339,11 @@ async def async_setup_entry( ) entity_registry.async_update_entity(entity_id, new_unique_id=new_unique_id) - sensors = [] - - for description in SENSOR_TYPES: - if description.value(coordinator.data) is not None: - sensors.append(BrotherPrinterSensor(coordinator, description)) - async_add_entities(sensors, False) + async_add_entities( + BrotherPrinterSensor(coordinator, description) + for description in SENSOR_TYPES + if description.value(coordinator.data) is not None + ) class BrotherPrinterSensor(