diff --git a/homeassistant/components/garages_amsterdam/sensor.py b/homeassistant/components/garages_amsterdam/sensor.py index d17a8705275..b6fc950a843 100644 --- a/homeassistant/components/garages_amsterdam/sensor.py +++ b/homeassistant/components/garages_amsterdam/sensor.py @@ -27,17 +27,11 @@ async def async_setup_entry( """Defer sensor setup to the shared sensor module.""" coordinator = await get_coordinator(hass) - entities: list[GaragesAmsterdamSensor] = [] - - for info_type in SENSORS: - if getattr(coordinator.data[config_entry.data["garage_name"]], info_type) != "": - entities.append( - GaragesAmsterdamSensor( - coordinator, config_entry.data["garage_name"], info_type - ) - ) - - async_add_entities(entities) + async_add_entities( + GaragesAmsterdamSensor(coordinator, config_entry.data["garage_name"], info_type) + for info_type in SENSORS + if getattr(coordinator.data[config_entry.data["garage_name"]], info_type) != "" + ) class GaragesAmsterdamSensor(GaragesAmsterdamEntity, SensorEntity): diff --git a/homeassistant/components/greeneye_monitor/sensor.py b/homeassistant/components/greeneye_monitor/sensor.py index c11e08eaa84..1290fc9459a 100644 --- a/homeassistant/components/greeneye_monitor/sensor.py +++ b/homeassistant/components/greeneye_monitor/sensor.py @@ -62,48 +62,46 @@ async def async_setup_platform( None, ) if monitor_config: - entities: list[GEMSensor] = [] - channel_configs = monitor_config[CONF_CHANNELS] - for sensor in channel_configs: - entities.append( - CurrentSensor( - monitor, - sensor[CONF_NUMBER], - sensor[CONF_NAME], - sensor[CONF_NET_METERING], - ) + entities: list[GEMSensor] = [ + CurrentSensor( + monitor, + sensor[CONF_NUMBER], + sensor[CONF_NAME], + sensor[CONF_NET_METERING], ) + for sensor in channel_configs + ] pulse_counter_configs = monitor_config[CONF_PULSE_COUNTERS] - for sensor in pulse_counter_configs: - entities.append( - PulseCounter( - monitor, - sensor[CONF_NUMBER], - sensor[CONF_NAME], - sensor[CONF_COUNTED_QUANTITY], - sensor[CONF_TIME_UNIT], - sensor[CONF_COUNTED_QUANTITY_PER_PULSE], - ) + entities.extend( + PulseCounter( + monitor, + sensor[CONF_NUMBER], + sensor[CONF_NAME], + sensor[CONF_COUNTED_QUANTITY], + sensor[CONF_TIME_UNIT], + sensor[CONF_COUNTED_QUANTITY_PER_PULSE], ) + for sensor in pulse_counter_configs + ) temperature_sensor_configs = monitor_config[CONF_TEMPERATURE_SENSORS] - for sensor in temperature_sensor_configs[CONF_SENSORS]: - entities.append( - TemperatureSensor( - monitor, - sensor[CONF_NUMBER], - sensor[CONF_NAME], - temperature_sensor_configs[CONF_TEMPERATURE_UNIT], - ) + entities.extend( + TemperatureSensor( + monitor, + sensor[CONF_NUMBER], + sensor[CONF_NAME], + temperature_sensor_configs[CONF_TEMPERATURE_UNIT], ) + for sensor in temperature_sensor_configs[CONF_SENSORS] + ) voltage_sensor_configs = monitor_config[CONF_VOLTAGE_SENSORS] - for sensor in voltage_sensor_configs: - entities.append( - VoltageSensor(monitor, sensor[CONF_NUMBER], sensor[CONF_NAME]) - ) + entities.extend( + VoltageSensor(monitor, sensor[CONF_NUMBER], sensor[CONF_NAME]) + for sensor in voltage_sensor_configs + ) async_add_entities(entities) monitor_configs.remove(monitor_config) diff --git a/homeassistant/components/group/__init__.py b/homeassistant/components/group/__init__.py index cc060be88cc..55a4ab4ad17 100644 --- a/homeassistant/components/group/__init__.py +++ b/homeassistant/components/group/__init__.py @@ -185,13 +185,11 @@ def groups_with_entity(hass: HomeAssistant, entity_id: str) -> list[str]: if DOMAIN not in hass.data: return [] - groups = [] - - for group in hass.data[DOMAIN].entities: - if entity_id in group.tracking: - groups.append(group.entity_id) - - return groups + return [ + group.entity_id + for group in hass.data[DOMAIN].entities + if entity_id in group.tracking + ] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/homeassistant/components/group/reproduce_state.py b/homeassistant/components/group/reproduce_state.py index 3646f957597..eb81ab258e9 100644 --- a/homeassistant/components/group/reproduce_state.py +++ b/homeassistant/components/group/reproduce_state.py @@ -19,20 +19,18 @@ async def async_reproduce_states( reproduce_options: dict[str, Any] | None = None, ) -> None: """Reproduce component states.""" - states_copy = [] - for state in states: - members = get_entity_ids(hass, state.entity_id) - for member in members: - states_copy.append( - State( - member, - state.state, - state.attributes, - last_changed=state.last_changed, - last_updated=state.last_updated, - context=state.context, - ) - ) + states_copy = [ + State( + member, + state.state, + state.attributes, + last_changed=state.last_changed, + last_updated=state.last_updated, + context=state.context, + ) + for state in states + for member in get_entity_ids(hass, state.entity_id) + ] await async_reproduce_state( hass, states_copy, context=context, reproduce_options=reproduce_options ) diff --git a/homeassistant/components/habitica/sensor.py b/homeassistant/components/habitica/sensor.py index eb37f585899..4d48ec199ec 100644 --- a/homeassistant/components/habitica/sensor.py +++ b/homeassistant/components/habitica/sensor.py @@ -87,14 +87,16 @@ async def async_setup_entry( ) -> None: """Set up the habitica sensors.""" - entities: list[SensorEntity] = [] name = config_entry.data[CONF_NAME] sensor_data = HabitipyData(hass.data[DOMAIN][config_entry.entry_id]) await sensor_data.update() - for sensor_type in SENSORS_TYPES: - entities.append(HabitipySensor(name, sensor_type, sensor_data)) - for task_type in TASKS_TYPES: - entities.append(HabitipyTaskSensor(name, task_type, sensor_data)) + + entities: list[SensorEntity] = [ + HabitipySensor(name, sensor_type, sensor_data) for sensor_type in SENSORS_TYPES + ] + entities.extend( + HabitipyTaskSensor(name, task_type, sensor_data) for task_type in TASKS_TYPES + ) async_add_entities(entities, True) diff --git a/homeassistant/components/hassio/sensor.py b/homeassistant/components/hassio/sensor.py index 5a981d6c96c..039bf483682 100644 --- a/homeassistant/components/hassio/sensor.py +++ b/homeassistant/components/hassio/sensor.py @@ -118,50 +118,48 @@ async def async_setup_entry( entities: list[ HassioOSSensor | HassioAddonSensor | CoreSensor | SupervisorSensor | HostSensor - ] = [] - - for addon in coordinator.data[DATA_KEY_ADDONS].values(): - for entity_description in ADDON_ENTITY_DESCRIPTIONS: - entities.append( - HassioAddonSensor( - addon=addon, - coordinator=coordinator, - entity_description=entity_description, - ) - ) - - for entity_description in CORE_ENTITY_DESCRIPTIONS: - entities.append( - CoreSensor( - coordinator=coordinator, - entity_description=entity_description, - ) + ] = [ + HassioAddonSensor( + addon=addon, + coordinator=coordinator, + entity_description=entity_description, ) + for addon in coordinator.data[DATA_KEY_ADDONS].values() + for entity_description in ADDON_ENTITY_DESCRIPTIONS + ] - for entity_description in SUPERVISOR_ENTITY_DESCRIPTIONS: - entities.append( - SupervisorSensor( - coordinator=coordinator, - entity_description=entity_description, - ) + entities.extend( + CoreSensor( + coordinator=coordinator, + entity_description=entity_description, ) + for entity_description in CORE_ENTITY_DESCRIPTIONS + ) - for entity_description in HOST_ENTITY_DESCRIPTIONS: - entities.append( - HostSensor( - coordinator=coordinator, - entity_description=entity_description, - ) + entities.extend( + SupervisorSensor( + coordinator=coordinator, + entity_description=entity_description, ) + for entity_description in SUPERVISOR_ENTITY_DESCRIPTIONS + ) + + entities.extend( + HostSensor( + coordinator=coordinator, + entity_description=entity_description, + ) + for entity_description in HOST_ENTITY_DESCRIPTIONS + ) if coordinator.is_hass_os: - for entity_description in OS_ENTITY_DESCRIPTIONS: - entities.append( - HassioOSSensor( - coordinator=coordinator, - entity_description=entity_description, - ) + entities.extend( + HassioOSSensor( + coordinator=coordinator, + entity_description=entity_description, ) + for entity_description in OS_ENTITY_DESCRIPTIONS + ) async_add_entities(entities) diff --git a/homeassistant/components/hassio/update.py b/homeassistant/components/hassio/update.py index 6a3bba90234..8e7650a9225 100644 --- a/homeassistant/components/hassio/update.py +++ b/homeassistant/components/hassio/update.py @@ -67,14 +67,14 @@ async def async_setup_entry( ), ] - for addon in coordinator.data[DATA_KEY_ADDONS].values(): - entities.append( - SupervisorAddonUpdateEntity( - addon=addon, - coordinator=coordinator, - entity_description=ENTITY_DESCRIPTION, - ) + entities.extend( + SupervisorAddonUpdateEntity( + addon=addon, + coordinator=coordinator, + entity_description=ENTITY_DESCRIPTION, ) + for addon in coordinator.data[DATA_KEY_ADDONS].values() + ) if coordinator.is_hass_os: entities.append( diff --git a/homeassistant/components/haveibeenpwned/sensor.py b/homeassistant/components/haveibeenpwned/sensor.py index c0a55279b82..9933ba11945 100644 --- a/homeassistant/components/haveibeenpwned/sensor.py +++ b/homeassistant/components/haveibeenpwned/sensor.py @@ -49,11 +49,7 @@ def setup_platform( api_key = config[CONF_API_KEY] data = HaveIBeenPwnedData(emails, api_key) - devices = [] - for email in emails: - devices.append(HaveIBeenPwnedSensor(data, email)) - - add_entities(devices) + add_entities(HaveIBeenPwnedSensor(data, email) for email in emails) class HaveIBeenPwnedSensor(SensorEntity): diff --git a/homeassistant/components/hddtemp/sensor.py b/homeassistant/components/hddtemp/sensor.py index 27a514bd58f..3dda9f44004 100644 --- a/homeassistant/components/hddtemp/sensor.py +++ b/homeassistant/components/hddtemp/sensor.py @@ -66,11 +66,7 @@ def setup_platform( if not disks: disks = [next(iter(hddtemp.data)).split("|")[0]] - dev = [] - for disk in disks: - dev.append(HddTempSensor(name, disk, hddtemp)) - - add_entities(dev, True) + add_entities((HddTempSensor(name, disk, hddtemp) for disk in disks), True) class HddTempSensor(SensorEntity): diff --git a/homeassistant/components/here_travel_time/sensor.py b/homeassistant/components/here_travel_time/sensor.py index 190a8455e83..4d7566ef2e2 100644 --- a/homeassistant/components/here_travel_time/sensor.py +++ b/homeassistant/components/here_travel_time/sensor.py @@ -86,16 +86,15 @@ async def async_setup_entry( name = config_entry.data[CONF_NAME] coordinator = hass.data[DOMAIN][entry_id] - sensors: list[HERETravelTimeSensor] = [] - for sensor_description in sensor_descriptions(config_entry.data[CONF_MODE]): - sensors.append( - HERETravelTimeSensor( - entry_id, - name, - sensor_description, - coordinator, - ) + sensors: list[HERETravelTimeSensor] = [ + HERETravelTimeSensor( + entry_id, + name, + sensor_description, + coordinator, ) + for sensor_description in sensor_descriptions(config_entry.data[CONF_MODE]) + ] sensors.append(OriginSensor(entry_id, name, coordinator)) sensors.append(DestinationSensor(entry_id, name, coordinator)) async_add_entities(sensors) diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index 472395afa9e..af1df7d4d62 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -52,13 +52,17 @@ async def async_setup_entry( hive = hass.data[DOMAIN][entry.entry_id] devices = hive.session.deviceList.get("binary_sensor") - entities = [] - if devices: - for description in BINARY_SENSOR_TYPES: - for dev in devices: - if dev["hiveType"] == description.key: - entities.append(HiveBinarySensorEntity(hive, dev, description)) - async_add_entities(entities, True) + if not devices: + return + async_add_entities( + ( + HiveBinarySensorEntity(hive, dev, description) + for dev in devices + for description in BINARY_SENSOR_TYPES + if dev["hiveType"] == description.key + ), + True, + ) class HiveBinarySensorEntity(HiveEntity, BinarySensorEntity): diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index 8c674605b11..cb1cc15a5bf 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -59,11 +59,8 @@ async def async_setup_entry( hive = hass.data[DOMAIN][entry.entry_id] devices = hive.session.deviceList.get("climate") - entities = [] if devices: - for dev in devices: - entities.append(HiveClimateEntity(hive, dev)) - async_add_entities(entities, True) + async_add_entities((HiveClimateEntity(hive, dev) for dev in devices), True) platform = entity_platform.async_get_current_platform() diff --git a/homeassistant/components/hive/light.py b/homeassistant/components/hive/light.py index ebf9efb3d26..1ce49599262 100644 --- a/homeassistant/components/hive/light.py +++ b/homeassistant/components/hive/light.py @@ -34,11 +34,9 @@ async def async_setup_entry( hive: Hive = hass.data[DOMAIN][entry.entry_id] devices = hive.session.deviceList.get("light") - entities = [] - if devices: - for dev in devices: - entities.append(HiveDeviceLight(hive, dev)) - async_add_entities(entities, True) + if not devices: + return + async_add_entities((HiveDeviceLight(hive, dev) for dev in devices), True) class HiveDeviceLight(HiveEntity, LightEntity): diff --git a/homeassistant/components/hive/sensor.py b/homeassistant/components/hive/sensor.py index e52e608af43..5f750642385 100644 --- a/homeassistant/components/hive/sensor.py +++ b/homeassistant/components/hive/sensor.py @@ -54,13 +54,17 @@ async def async_setup_entry( """Set up Hive thermostat based on a config entry.""" hive = hass.data[DOMAIN][entry.entry_id] devices = hive.session.deviceList.get("sensor") - entities = [] - if devices: - for description in SENSOR_TYPES: - for dev in devices: - if dev["hiveType"] == description.key: - entities.append(HiveSensorEntity(hive, dev, description)) - async_add_entities(entities, True) + if not devices: + return + async_add_entities( + ( + HiveSensorEntity(hive, dev, description) + for dev in devices + for description in SENSOR_TYPES + if dev["hiveType"] == description.key + ), + True, + ) class HiveSensorEntity(HiveEntity, SensorEntity): diff --git a/homeassistant/components/hive/switch.py b/homeassistant/components/hive/switch.py index 9f97c8e920b..6bcbfc6345c 100644 --- a/homeassistant/components/hive/switch.py +++ b/homeassistant/components/hive/switch.py @@ -36,13 +36,17 @@ async def async_setup_entry( hive = hass.data[DOMAIN][entry.entry_id] devices = hive.session.deviceList.get("switch") - entities = [] - if devices: - for description in SWITCH_TYPES: - for dev in devices: - if dev["hiveType"] == description.key: - entities.append(HiveSwitch(hive, dev, description)) - async_add_entities(entities, True) + if not devices: + return + async_add_entities( + ( + HiveSwitch(hive, dev, description) + for dev in devices + for description in SWITCH_TYPES + if dev["hiveType"] == description.key + ), + True, + ) class HiveSwitch(HiveEntity, SwitchEntity): diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index 11f8dddb3bd..127fb80ef18 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -49,11 +49,8 @@ async def async_setup_entry( hive = hass.data[DOMAIN][entry.entry_id] devices = hive.session.deviceList.get("water_heater") - entities = [] if devices: - for dev in devices: - entities.append(HiveWaterHeater(hive, dev)) - async_add_entities(entities, True) + async_add_entities((HiveWaterHeater(hive, dev) for dev in devices), True) platform = entity_platform.async_get_current_platform() diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 3f7b210832d..901dd5ec2fb 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -928,13 +928,15 @@ class HomeKit: connection: tuple[str, str], ) -> None: """Purge bridges that exist from failed pairing or manual resets.""" - devices_to_purge = [] - for entry in dev_reg.devices.values(): - if self._entry_id in entry.config_entries and ( + devices_to_purge = [ + entry.id + for entry in dev_reg.devices.values() + if self._entry_id in entry.config_entries + and ( identifier not in entry.identifiers # type: ignore[comparison-overlap] or connection not in entry.connections - ): - devices_to_purge.append(entry.id) + ) + ] for device_id in devices_to_purge: dev_reg.async_remove_device(device_id) diff --git a/homeassistant/components/homekit/util.py b/homeassistant/components/homekit/util.py index 2d0eccf9b7c..031cdbbc9bd 100644 --- a/homeassistant/components/homekit/util.py +++ b/homeassistant/components/homekit/util.py @@ -326,10 +326,7 @@ def validate_media_player_features(state: State, feature_list: str) -> bool: # Auto detected return True - error_list = [] - for feature in feature_list: - if feature not in supported_modes: - error_list.append(feature) + error_list = [feature for feature in feature_list if feature not in supported_modes] if error_list: _LOGGER.error( diff --git a/homeassistant/components/homekit_controller/device_trigger.py b/homeassistant/components/homekit_controller/device_trigger.py index c88928e1c2e..a68241d7fc0 100644 --- a/homeassistant/components/homekit_controller/device_trigger.py +++ b/homeassistant/components/homekit_controller/device_trigger.py @@ -160,7 +160,7 @@ def enumerate_stateless_switch_group(service: Service) -> list[dict[str, Any]]: ) ) - results = [] + results: list[dict[str, Any]] = [] for idx, switch in enumerate(switches): char = switch[CharacteristicsTypes.INPUT_EVENT] @@ -168,15 +168,15 @@ def enumerate_stateless_switch_group(service: Service) -> list[dict[str, Any]]: # manufacturer might not - clamp options to what they say. all_values = clamp_enum_to_char(InputEventValues, char) - for event_type in all_values: - results.append( - { - "characteristic": char.iid, - "value": event_type, - "type": f"button{idx + 1}", - "subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type], - } - ) + results.extend( + { + "characteristic": char.iid, + "value": event_type, + "type": f"button{idx + 1}", + "subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type], + } + for event_type in all_values + ) return results @@ -188,17 +188,15 @@ def enumerate_doorbell(service: Service) -> list[dict[str, Any]]: # manufacturer might not - clamp options to what they say. all_values = clamp_enum_to_char(InputEventValues, input_event) - results = [] - for event_type in all_values: - results.append( - { - "characteristic": input_event.iid, - "value": event_type, - "type": "doorbell", - "subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type], - } - ) - return results + return [ + { + "characteristic": input_event.iid, + "value": event_type, + "type": "doorbell", + "subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type], + } + for event_type in all_values + ] TRIGGER_FINDERS = { diff --git a/homeassistant/components/homekit_controller/event.py b/homeassistant/components/homekit_controller/event.py index 7c9052f984b..890c12c9bab 100644 --- a/homeassistant/components/homekit_controller/event.py +++ b/homeassistant/components/homekit_controller/event.py @@ -118,21 +118,21 @@ async def async_setup_entry( ) ) - for switch in switches: - # The Apple docs say that if we number the buttons ourselves - # We do it in service label index order. `switches` is already in - # that order. - entities.append( - HomeKitEventEntity( - conn, - switch, - EventEntityDescription( - key=f"{service.accessory.aid}_{service.iid}", - device_class=EventDeviceClass.BUTTON, - translation_key="button", - ), - ) + # The Apple docs say that if we number the buttons ourselves + # We do it in service label index order. `switches` is already in + # that order. + entities.extend( + HomeKitEventEntity( + conn, + switch, + EventEntityDescription( + key=f"{service.accessory.aid}_{service.iid}", + device_class=EventDeviceClass.BUTTON, + translation_key="button", + ), ) + for switch in switches + ) elif service.type == ServicesTypes.STATELESS_PROGRAMMABLE_SWITCH: # A stateless switch that has a SERVICE_LABEL_INDEX is part of a group diff --git a/homeassistant/components/homematic/__init__.py b/homeassistant/components/homematic/__init__.py index 6eb01728df0..80345866b1f 100644 --- a/homeassistant/components/homematic/__init__.py +++ b/homeassistant/components/homematic/__init__.py @@ -259,9 +259,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, hass.data[DATA_HOMEMATIC].stop) # Init homematic hubs - entity_hubs = [] - for hub_name in conf[CONF_HOSTS]: - entity_hubs.append(HMHub(hass, homematic, hub_name)) + entity_hubs = [HMHub(hass, homematic, hub_name) for hub_name in conf[CONF_HOSTS]] def _hm_service_virtualkey(service: ServiceCall) -> None: """Service to handle virtualkey servicecalls.""" diff --git a/homeassistant/components/homematic/climate.py b/homeassistant/components/homematic/climate.py index f0e15b7a055..efdb9324f76 100644 --- a/homeassistant/components/homematic/climate.py +++ b/homeassistant/components/homematic/climate.py @@ -113,11 +113,7 @@ class HMThermostat(HMDevice, ClimateEntity): @property def preset_modes(self): """Return a list of available preset modes.""" - preset_modes = [] - for mode in self._hmdevice.ACTIONNODE: - if mode in HM_PRESET_MAP: - preset_modes.append(HM_PRESET_MAP[mode]) - return preset_modes + return [HM_PRESET_MAP[mode] for mode in self._hmdevice.ACTIONNODE] @property def current_humidity(self): diff --git a/homeassistant/components/homematic/lock.py b/homeassistant/components/homematic/lock.py index bcd5c7ce7a0..b79f28f2bc7 100644 --- a/homeassistant/components/homematic/lock.py +++ b/homeassistant/components/homematic/lock.py @@ -23,11 +23,7 @@ def setup_platform( if discovery_info is None: return - devices = [] - for conf in discovery_info[ATTR_DISCOVER_DEVICES]: - devices.append(HMLock(conf)) - - add_entities(devices, True) + add_entities((HMLock(conf) for conf in discovery_info[ATTR_DISCOVER_DEVICES]), True) class HMLock(HMDevice, LockEntity): diff --git a/homeassistant/components/homematicip_cloud/binary_sensor.py b/homeassistant/components/homematicip_cloud/binary_sensor.py index b3322107bfa..29d8576f060 100644 --- a/homeassistant/components/homematicip_cloud/binary_sensor.py +++ b/homeassistant/components/homematicip_cloud/binary_sensor.py @@ -86,15 +86,15 @@ async def async_setup_entry( if isinstance(device, AsyncTiltVibrationSensor): entities.append(HomematicipTiltVibrationSensor(hap, device)) if isinstance(device, AsyncWiredInput32): - for channel in range(1, 33): - entities.append( - HomematicipMultiContactInterface(hap, device, channel=channel) - ) + entities.extend( + HomematicipMultiContactInterface(hap, device, channel=channel) + for channel in range(1, 33) + ) elif isinstance(device, AsyncFullFlushContactInterface6): - for channel in range(1, 7): - entities.append( - HomematicipMultiContactInterface(hap, device, channel=channel) - ) + entities.extend( + HomematicipMultiContactInterface(hap, device, channel=channel) + for channel in range(1, 7) + ) elif isinstance( device, (AsyncContactInterface, AsyncFullFlushContactInterface) ): diff --git a/homeassistant/components/homematicip_cloud/button.py b/homeassistant/components/homematicip_cloud/button.py index 7537c15fc9b..c2707f68a89 100644 --- a/homeassistant/components/homematicip_cloud/button.py +++ b/homeassistant/components/homematicip_cloud/button.py @@ -20,13 +20,12 @@ async def async_setup_entry( ) -> None: """Set up the HomematicIP button from a config entry.""" hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id] - entities: list[HomematicipGenericEntity] = [] - for device in hap.home.devices: - if isinstance(device, AsyncWallMountedGarageDoorController): - entities.append(HomematicipGarageDoorControllerButton(hap, device)) - if entities: - async_add_entities(entities) + async_add_entities( + HomematicipGarageDoorControllerButton(hap, device) + for device in hap.home.devices + if isinstance(device, AsyncWallMountedGarageDoorController) + ) class HomematicipGarageDoorControllerButton(HomematicipGenericEntity, ButtonEntity): diff --git a/homeassistant/components/homematicip_cloud/climate.py b/homeassistant/components/homematicip_cloud/climate.py index c4304284892..b0eb2a9edfa 100644 --- a/homeassistant/components/homematicip_cloud/climate.py +++ b/homeassistant/components/homematicip_cloud/climate.py @@ -51,12 +51,12 @@ async def async_setup_entry( ) -> None: """Set up the HomematicIP climate from a config entry.""" hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id] - entities = [] - for device in hap.home.groups: - if isinstance(device, AsyncHeatingGroup): - entities.append(HomematicipHeatingGroup(hap, device)) - async_add_entities(entities) + async_add_entities( + HomematicipHeatingGroup(hap, device) + for device in hap.home.groups + if isinstance(device, AsyncHeatingGroup) + ) class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity): diff --git a/homeassistant/components/homematicip_cloud/cover.py b/homeassistant/components/homematicip_cloud/cover.py index 17e1b7a94f1..b0cff8b6a10 100644 --- a/homeassistant/components/homematicip_cloud/cover.py +++ b/homeassistant/components/homematicip_cloud/cover.py @@ -41,15 +41,19 @@ async def async_setup_entry( ) -> None: """Set up the HomematicIP cover from a config entry.""" hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id] - entities: list[HomematicipGenericEntity] = [] + entities: list[HomematicipGenericEntity] = [ + HomematicipCoverShutterGroup(hap, group) + for group in hap.home.groups + if isinstance(group, AsyncExtendedLinkedShutterGroup) + ] for device in hap.home.devices: if isinstance(device, AsyncBlindModule): entities.append(HomematicipBlindModule(hap, device)) elif isinstance(device, AsyncDinRailBlind4): - for channel in range(1, 5): - entities.append( - HomematicipMultiCoverSlats(hap, device, channel=channel) - ) + entities.extend( + HomematicipMultiCoverSlats(hap, device, channel=channel) + for channel in range(1, 5) + ) elif isinstance(device, AsyncFullFlushBlind): entities.append(HomematicipCoverSlats(hap, device)) elif isinstance(device, AsyncFullFlushShutter): @@ -59,10 +63,6 @@ async def async_setup_entry( ): entities.append(HomematicipGarageDoorModule(hap, device)) - for group in hap.home.groups: - if isinstance(group, AsyncExtendedLinkedShutterGroup): - entities.append(HomematicipCoverShutterGroup(hap, group)) - async_add_entities(entities) diff --git a/homeassistant/components/homematicip_cloud/light.py b/homeassistant/components/homematicip_cloud/light.py index 6a9bd5a3c4e..17daafc5896 100644 --- a/homeassistant/components/homematicip_cloud/light.py +++ b/homeassistant/components/homematicip_cloud/light.py @@ -56,8 +56,10 @@ async def async_setup_entry( ) ) elif isinstance(device, (AsyncWiredDimmer3, AsyncDinRailDimmer3)): - for channel in range(1, 4): - entities.append(HomematicipMultiDimmer(hap, device, channel=channel)) + entities.extend( + HomematicipMultiDimmer(hap, device, channel=channel) + for channel in range(1, 4) + ) elif isinstance( device, (AsyncDimmer, AsyncPluggableDimmer, AsyncBrandDimmer, AsyncFullFlushDimmer), diff --git a/homeassistant/components/homematicip_cloud/switch.py b/homeassistant/components/homematicip_cloud/switch.py index 1fa3007c863..9aa60d45d93 100644 --- a/homeassistant/components/homematicip_cloud/switch.py +++ b/homeassistant/components/homematicip_cloud/switch.py @@ -39,7 +39,11 @@ async def async_setup_entry( ) -> None: """Set up the HomematicIP switch from a config entry.""" hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id] - entities: list[HomematicipGenericEntity] = [] + entities: list[HomematicipGenericEntity] = [ + HomematicipGroupSwitch(hap, group) + for group in hap.home.groups + if isinstance(group, (AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup)) + ] for device in hap.home.devices: if isinstance(device, AsyncBrandSwitchMeasuring): # BrandSwitchMeasuring inherits PlugableSwitchMeasuring @@ -51,13 +55,17 @@ async def async_setup_entry( ): entities.append(HomematicipSwitchMeasuring(hap, device)) elif isinstance(device, AsyncWiredSwitch8): - for channel in range(1, 9): - entities.append(HomematicipMultiSwitch(hap, device, channel=channel)) + entities.extend( + HomematicipMultiSwitch(hap, device, channel=channel) + for channel in range(1, 9) + ) elif isinstance(device, AsyncDinRailSwitch): entities.append(HomematicipMultiSwitch(hap, device, channel=1)) elif isinstance(device, AsyncDinRailSwitch4): - for channel in range(1, 5): - entities.append(HomematicipMultiSwitch(hap, device, channel=channel)) + entities.extend( + HomematicipMultiSwitch(hap, device, channel=channel) + for channel in range(1, 5) + ) elif isinstance( device, ( @@ -68,8 +76,10 @@ async def async_setup_entry( ): entities.append(HomematicipSwitch(hap, device)) elif isinstance(device, AsyncOpenCollector8Module): - for channel in range(1, 9): - entities.append(HomematicipMultiSwitch(hap, device, channel=channel)) + entities.extend( + HomematicipMultiSwitch(hap, device, channel=channel) + for channel in range(1, 9) + ) elif isinstance( device, ( @@ -79,12 +89,10 @@ async def async_setup_entry( AsyncMultiIOBox, ), ): - for channel in range(1, 3): - entities.append(HomematicipMultiSwitch(hap, device, channel=channel)) - - for group in hap.home.groups: - if isinstance(group, (AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup)): - entities.append(HomematicipGroupSwitch(hap, group)) + entities.extend( + HomematicipMultiSwitch(hap, device, channel=channel) + for channel in range(1, 3) + ) async_add_entities(entities) diff --git a/homeassistant/components/honeywell/sensor.py b/homeassistant/components/honeywell/sensor.py index 030f8be779b..31ed8d646c5 100644 --- a/homeassistant/components/honeywell/sensor.py +++ b/homeassistant/components/honeywell/sensor.py @@ -86,14 +86,13 @@ async def async_setup_entry( ) -> None: """Set up the Honeywell thermostat.""" data: HoneywellData = hass.data[DOMAIN][config_entry.entry_id] - sensors = [] - for device in data.devices.values(): - for description in SENSOR_TYPES: - if getattr(device, description.key) is not None: - sensors.append(HoneywellSensor(device, description)) - - async_add_entities(sensors) + async_add_entities( + HoneywellSensor(device, description) + for device in data.devices.values() + for description in SENSOR_TYPES + if getattr(device, description.key) is not None + ) class HoneywellSensor(SensorEntity): diff --git a/homeassistant/components/huawei_lte/sensor.py b/homeassistant/components/huawei_lte/sensor.py index a52aff5fd68..e75fef42ef3 100644 --- a/homeassistant/components/huawei_lte/sensor.py +++ b/homeassistant/components/huawei_lte/sensor.py @@ -674,17 +674,17 @@ async def async_setup_entry( items = filter(key_meta.include.search, items) if key_meta.exclude: items = [x for x in items if not key_meta.exclude.search(x)] - for item in items: - sensors.append( - HuaweiLteSensor( - router, - key, - item, - SENSOR_META[key].descriptions.get( - item, HuaweiSensorEntityDescription(key=item) - ), - ) + sensors.extend( + HuaweiLteSensor( + router, + key, + item, + SENSOR_META[key].descriptions.get( + item, HuaweiSensorEntityDescription(key=item) + ), ) + for item in items + ) async_add_entities(sensors, True) diff --git a/homeassistant/components/hue/event.py b/homeassistant/components/hue/event.py index c12468c0f36..1ba974fa167 100644 --- a/homeassistant/components/hue/event.py +++ b/homeassistant/components/hue/event.py @@ -81,12 +81,12 @@ class HueButtonEventEntity(HueBaseEntity, EventEntity): # fill the event types based on the features the switch supports hue_dev_id = self.controller.get_device(self.resource.id).id model_id = self.bridge.api.devices[hue_dev_id].product_data.product_name - event_types: list[str] = [] - for event_type in DEVICE_SPECIFIC_EVENT_TYPES.get( - model_id, DEFAULT_BUTTON_EVENT_TYPES - ): - event_types.append(event_type.value) - self._attr_event_types = event_types + self._attr_event_types: list[str] = [ + event_type.value + for event_type in DEVICE_SPECIFIC_EVENT_TYPES.get( + model_id, DEFAULT_BUTTON_EVENT_TYPES + ) + ] self._attr_translation_placeholders = { "button_id": self.resource.metadata.control_id } diff --git a/homeassistant/components/hue/v2/device_trigger.py b/homeassistant/components/hue/v2/device_trigger.py index eca7908e930..c35093a9f9c 100644 --- a/homeassistant/components/hue/v2/device_trigger.py +++ b/homeassistant/components/hue/v2/device_trigger.py @@ -90,39 +90,39 @@ def async_get_triggers( # Get Hue device id from device identifier hue_dev_id = get_hue_device_id(device_entry) # extract triggers from all button resources of this Hue device - triggers = [] + triggers: list[dict[str, Any]] = [] model_id = api.devices[hue_dev_id].product_data.product_name for resource in api.devices.get_sensors(hue_dev_id): # button triggers if resource.type == ResourceTypes.BUTTON: - for event_type in DEVICE_SPECIFIC_EVENT_TYPES.get( - model_id, DEFAULT_BUTTON_EVENT_TYPES - ): - triggers.append( - { - CONF_DEVICE_ID: device_entry.id, - CONF_DOMAIN: DOMAIN, - CONF_PLATFORM: "device", - CONF_TYPE: event_type.value, - CONF_SUBTYPE: resource.metadata.control_id, - CONF_UNIQUE_ID: resource.id, - } + triggers.extend( + { + CONF_DEVICE_ID: device_entry.id, + CONF_DOMAIN: DOMAIN, + CONF_PLATFORM: "device", + CONF_TYPE: event_type.value, + CONF_SUBTYPE: resource.metadata.control_id, + CONF_UNIQUE_ID: resource.id, + } + for event_type in DEVICE_SPECIFIC_EVENT_TYPES.get( + model_id, DEFAULT_BUTTON_EVENT_TYPES ) + ) # relative_rotary triggers elif resource.type == ResourceTypes.RELATIVE_ROTARY: - for event_type in DEFAULT_ROTARY_EVENT_TYPES: - for sub_type in DEFAULT_ROTARY_EVENT_SUBTYPES: - triggers.append( - { - CONF_DEVICE_ID: device_entry.id, - CONF_DOMAIN: DOMAIN, - CONF_PLATFORM: "device", - CONF_TYPE: event_type.value, - CONF_SUBTYPE: sub_type.value, - CONF_UNIQUE_ID: resource.id, - } - ) + triggers.extend( + { + CONF_DEVICE_ID: device_entry.id, + CONF_DOMAIN: DOMAIN, + CONF_PLATFORM: "device", + CONF_TYPE: event_type.value, + CONF_SUBTYPE: sub_type.value, + CONF_UNIQUE_ID: resource.id, + } + for event_type in DEFAULT_ROTARY_EVENT_TYPES + for sub_type in DEFAULT_ROTARY_EVENT_SUBTYPES + ) return triggers diff --git a/homeassistant/components/hunterdouglas_powerview/button.py b/homeassistant/components/hunterdouglas_powerview/button.py index 1ce30e8df81..f7c90f3420b 100644 --- a/homeassistant/components/hunterdouglas_powerview/button.py +++ b/homeassistant/components/hunterdouglas_powerview/button.py @@ -85,19 +85,18 @@ async def async_setup_entry( entities: list[ButtonEntity] = [] for shade in pv_entry.shade_data.values(): room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "") - for description in BUTTONS_SHADE: - if description.create_entity_fn(shade): - entities.append( - PowerviewShadeButton( - pv_entry.coordinator, - pv_entry.device_info, - room_name, - shade, - shade.name, - description, - ) - ) - + entities.extend( + PowerviewShadeButton( + pv_entry.coordinator, + pv_entry.device_info, + room_name, + shade, + shade.name, + description, + ) + for description in BUTTONS_SHADE + if description.create_entity_fn(shade) + ) async_add_entities(entities) diff --git a/homeassistant/components/hunterdouglas_powerview/number.py b/homeassistant/components/hunterdouglas_powerview/number.py index 6b18f663c71..b37331c08df 100644 --- a/homeassistant/components/hunterdouglas_powerview/number.py +++ b/homeassistant/components/hunterdouglas_powerview/number.py @@ -66,19 +66,18 @@ async def async_setup_entry( entities: list[PowerViewNumber] = [] for shade in pv_entry.shade_data.values(): room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "") - for description in NUMBERS: - if description.create_entity_fn(shade): - entities.append( - PowerViewNumber( - pv_entry.coordinator, - pv_entry.device_info, - room_name, - shade, - shade.name, - description, - ) - ) - + entities.extend( + PowerViewNumber( + pv_entry.coordinator, + pv_entry.device_info, + room_name, + shade, + shade.name, + description, + ) + for description in NUMBERS + if description.create_entity_fn(shade) + ) async_add_entities(entities) diff --git a/homeassistant/components/hunterdouglas_powerview/select.py b/homeassistant/components/hunterdouglas_powerview/select.py index c902c2b1a58..66207f6da7c 100644 --- a/homeassistant/components/hunterdouglas_powerview/select.py +++ b/homeassistant/components/hunterdouglas_powerview/select.py @@ -68,19 +68,18 @@ async def async_setup_entry( if not shade.has_battery_info(): continue room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "") - for description in DROPDOWNS: - if description.create_entity_fn(shade): - entities.append( - PowerViewSelect( - pv_entry.coordinator, - pv_entry.device_info, - room_name, - shade, - shade.name, - description, - ) - ) - + entities.extend( + PowerViewSelect( + pv_entry.coordinator, + pv_entry.device_info, + room_name, + shade, + shade.name, + description, + ) + for description in DROPDOWNS + if description.create_entity_fn(shade) + ) async_add_entities(entities) diff --git a/homeassistant/components/hunterdouglas_powerview/sensor.py b/homeassistant/components/hunterdouglas_powerview/sensor.py index 02b4ae7c557..c1371a1e848 100644 --- a/homeassistant/components/hunterdouglas_powerview/sensor.py +++ b/homeassistant/components/hunterdouglas_powerview/sensor.py @@ -88,19 +88,18 @@ async def async_setup_entry( entities: list[PowerViewSensor] = [] for shade in pv_entry.shade_data.values(): room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "") - for description in SENSORS: - if description.create_entity_fn(shade): - entities.append( - PowerViewSensor( - pv_entry.coordinator, - pv_entry.device_info, - room_name, - shade, - shade.name, - description, - ) - ) - + entities.extend( + PowerViewSensor( + pv_entry.coordinator, + pv_entry.device_info, + room_name, + shade, + shade.name, + description, + ) + for description in SENSORS + if description.create_entity_fn(shade) + ) async_add_entities(entities) diff --git a/homeassistant/components/hydrawise/binary_sensor.py b/homeassistant/components/hydrawise/binary_sensor.py index 7740334e7fb..e75cf56ac75 100644 --- a/homeassistant/components/hydrawise/binary_sensor.py +++ b/homeassistant/components/hydrawise/binary_sensor.py @@ -75,11 +75,11 @@ async def async_setup_entry( entities.append( HydrawiseBinarySensor(coordinator, BINARY_SENSOR_STATUS, controller) ) - for zone in controller.zones: - for description in BINARY_SENSOR_TYPES: - entities.append( - HydrawiseBinarySensor(coordinator, description, controller, zone) - ) + entities.extend( + HydrawiseBinarySensor(coordinator, description, controller, zone) + for zone in controller.zones + for description in BINARY_SENSOR_TYPES + ) async_add_entities(entities) diff --git a/homeassistant/components/hyperion/switch.py b/homeassistant/components/hyperion/switch.py index dbe0bbb5c70..94cbf2aba29 100644 --- a/homeassistant/components/hyperion/switch.py +++ b/homeassistant/components/hyperion/switch.py @@ -100,18 +100,16 @@ async def async_setup_entry( def instance_add(instance_num: int, instance_name: str) -> None: """Add entities for a new Hyperion instance.""" assert server_id - switches = [] - for component in COMPONENT_SWITCHES: - switches.append( - HyperionComponentSwitch( - server_id, - instance_num, - instance_name, - component, - entry_data[CONF_INSTANCE_CLIENTS][instance_num], - ), + async_add_entities( + HyperionComponentSwitch( + server_id, + instance_num, + instance_name, + component, + entry_data[CONF_INSTANCE_CLIENTS][instance_num], ) - async_add_entities(switches) + for component in COMPONENT_SWITCHES + ) @callback def instance_remove(instance_num: int) -> None: diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py index 8e120728a8b..13574bb2bb2 100644 --- a/tests/components/history/test_init.py +++ b/tests/components/history/test_init.py @@ -241,9 +241,7 @@ def test_get_significant_states_only(hass_history) -> None: return hass.states.get(entity_id) start = dt_util.utcnow() - timedelta(minutes=4) - points = [] - for i in range(1, 4): - points.append(start + timedelta(minutes=i)) + points = [start + timedelta(minutes=i) for i in range(1, 4)] states = [] with freeze_time(start) as freezer: diff --git a/tests/components/history/test_init_db_schema_30.py b/tests/components/history/test_init_db_schema_30.py index b0c07cf25af..0bbd913ce2b 100644 --- a/tests/components/history/test_init_db_schema_30.py +++ b/tests/components/history/test_init_db_schema_30.py @@ -257,9 +257,7 @@ def test_get_significant_states_only(legacy_hass_history) -> None: return hass.states.get(entity_id) start = dt_util.utcnow() - timedelta(minutes=4) - points = [] - for i in range(1, 4): - points.append(start + timedelta(minutes=i)) + points = [start + timedelta(minutes=i) for i in range(1, 4)] states = [] with freeze_time(start) as freezer: diff --git a/tests/components/homekit_controller/test_device_trigger.py b/tests/components/homekit_controller/test_device_trigger.py index 0437958edae..40f565ec88b 100644 --- a/tests/components/homekit_controller/test_device_trigger.py +++ b/tests/components/homekit_controller/test_device_trigger.py @@ -116,18 +116,18 @@ async def test_enumerate_remote( }, ] - for button in ("button1", "button2", "button3", "button4"): - for subtype in ("single_press", "double_press", "long_press"): - expected.append( - { - "device_id": device.id, - "domain": "homekit_controller", - "platform": "device", - "type": button, - "subtype": subtype, - "metadata": {}, - } - ) + expected.extend( + { + "device_id": device.id, + "domain": "homekit_controller", + "platform": "device", + "type": button, + "subtype": subtype, + "metadata": {}, + } + for button in ("button1", "button2", "button3", "button4") + for subtype in ("single_press", "double_press", "long_press") + ) triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device.id @@ -167,17 +167,17 @@ async def test_enumerate_button( }, ] - for subtype in ("single_press", "double_press", "long_press"): - expected.append( - { - "device_id": device.id, - "domain": "homekit_controller", - "platform": "device", - "type": "button1", - "subtype": subtype, - "metadata": {}, - } - ) + expected.extend( + { + "device_id": device.id, + "domain": "homekit_controller", + "platform": "device", + "type": "button1", + "subtype": subtype, + "metadata": {}, + } + for subtype in ("single_press", "double_press", "long_press") + ) triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device.id @@ -217,17 +217,17 @@ async def test_enumerate_doorbell( }, ] - for subtype in ("single_press", "double_press", "long_press"): - expected.append( - { - "device_id": device.id, - "domain": "homekit_controller", - "platform": "device", - "type": "doorbell", - "subtype": subtype, - "metadata": {}, - } - ) + expected.extend( + { + "device_id": device.id, + "domain": "homekit_controller", + "platform": "device", + "type": "doorbell", + "subtype": subtype, + "metadata": {}, + } + for subtype in ("single_press", "double_press", "long_press") + ) triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device.id diff --git a/tests/components/homematicip_cloud/helper.py b/tests/components/homematicip_cloud/helper.py index 5bc11b77d32..4632b9107af 100644 --- a/tests/components/homematicip_cloud/helper.py +++ b/tests/components/homematicip_cloud/helper.py @@ -171,15 +171,9 @@ class HomeTemplate(Home): def _generate_mocks(self): """Generate mocks for groups and devices.""" - mock_devices = [] - for device in self.devices: - mock_devices.append(_get_mock(device)) - self.devices = mock_devices + self.devices = [_get_mock(device) for device in self.devices] - mock_groups = [] - for group in self.groups: - mock_groups.append(_get_mock(group)) - self.groups = mock_groups + self.groups = [_get_mock(group) for group in self.groups] def download_configuration(self): """Return the initial json config.""" diff --git a/tests/components/humidifier/test_init.py b/tests/components/humidifier/test_init.py index 33ea6d14a19..b90e7084dd1 100644 --- a/tests/components/humidifier/test_init.py +++ b/tests/components/humidifier/test_init.py @@ -49,10 +49,7 @@ async def test_sync_turn_off(hass: HomeAssistant) -> None: def _create_tuples(enum: Enum, constant_prefix: str) -> list[tuple[Enum, str]]: - result = [] - for enum in enum: - result.append((enum, constant_prefix)) - return result + return [(enum_field, constant_prefix) for enum_field in enum] @pytest.mark.parametrize(