diff --git a/homeassistant/components/canary/camera.py b/homeassistant/components/canary/camera.py index f1aac2b17a0..e081d24e06a 100644 --- a/homeassistant/components/canary/camera.py +++ b/homeassistant/components/canary/camera.py @@ -64,22 +64,22 @@ async def async_setup_entry( ffmpeg_arguments: str = entry.options.get( CONF_FFMPEG_ARGUMENTS, DEFAULT_FFMPEG_ARGUMENTS ) - cameras: list[CanaryCamera] = [] - for location_id, location in coordinator.data["locations"].items(): - for device in location.devices: - if device.is_online: - cameras.append( - CanaryCamera( - hass, - coordinator, - location_id, - device, - ffmpeg_arguments, - ) - ) - - async_add_entities(cameras, True) + async_add_entities( + ( + CanaryCamera( + hass, + coordinator, + location_id, + device, + ffmpeg_arguments, + ) + for location_id, location in coordinator.data["locations"].items() + for device in location.devices + if device.is_online + ), + True, + ) class CanaryCamera(CoordinatorEntity[CanaryDataUpdateCoordinator], Camera): diff --git a/homeassistant/components/canary/sensor.py b/homeassistant/components/canary/sensor.py index 1fcce204d3c..905214e0d1d 100644 --- a/homeassistant/components/canary/sensor.py +++ b/homeassistant/components/canary/sensor.py @@ -75,11 +75,11 @@ async def async_setup_entry( for device in location.devices: if device.is_online: device_type = device.device_type - for sensor_type in SENSOR_TYPES: - if device_type.get("name") in sensor_type[4]: - sensors.append( - CanarySensor(coordinator, sensor_type, location, device) - ) + sensors.extend( + CanarySensor(coordinator, sensor_type, location, device) + for sensor_type in SENSOR_TYPES + if device_type.get("name") in sensor_type[4] + ) async_add_entities(sensors, True) diff --git a/homeassistant/components/cloud/http_api.py b/homeassistant/components/cloud/http_api.py index 87e5d00ff8f..a45077c79c4 100644 --- a/homeassistant/components/cloud/http_api.py +++ b/homeassistant/components/cloud/http_api.py @@ -649,16 +649,14 @@ async def google_assistant_list( gconf = await cloud.client.get_google_config() entities = google_helpers.async_get_entities(hass, gconf) - result = [] - - for entity in entities: - result.append( - { - "entity_id": entity.entity_id, - "traits": [trait.name for trait in entity.traits()], - "might_2fa": entity.might_2fa_traits(), - } - ) + result = [ + { + "entity_id": entity.entity_id, + "traits": [trait.name for trait in entity.traits()], + "might_2fa": entity.might_2fa_traits(), + } + for entity in entities + ] connection.send_result(msg["id"], result) @@ -743,16 +741,14 @@ async def alexa_list( alexa_config = await cloud.client.get_alexa_config() entities = alexa_entities.async_get_entities(hass, alexa_config) - result = [] - - for entity in entities: - result.append( - { - "entity_id": entity.entity_id, - "display_categories": entity.default_display_categories(), - "interfaces": [ifc.name() for ifc in entity.interfaces()], - } - ) + result = [ + { + "entity_id": entity.entity_id, + "display_categories": entity.default_display_categories(), + "interfaces": [ifc.name() for ifc in entity.interfaces()], + } + for entity in entities + ] connection.send_result(msg["id"], result) diff --git a/homeassistant/components/coinbase/sensor.py b/homeassistant/components/coinbase/sensor.py index 16fb8006fe9..83c63fa55fb 100644 --- a/homeassistant/components/coinbase/sensor.py +++ b/homeassistant/components/coinbase/sensor.py @@ -85,13 +85,12 @@ async def async_setup_entry( entities.append(AccountSensor(instance, currency)) if CONF_EXCHANGE_RATES in config_entry.options: - rate: str - for rate in config_entry.options[CONF_EXCHANGE_RATES]: - entities.append( - ExchangeRateSensor( - instance, rate, exchange_base_currency, exchange_precision - ) + entities.extend( + ExchangeRateSensor( + instance, rate, exchange_base_currency, exchange_precision ) + for rate in config_entry.options[CONF_EXCHANGE_RATES] + ) async_add_entities(entities) diff --git a/homeassistant/components/control4/__init__.py b/homeassistant/components/control4/__init__.py index f63d437dd4c..6776483e7e3 100644 --- a/homeassistant/components/control4/__init__.py +++ b/homeassistant/components/control4/__init__.py @@ -138,11 +138,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def get_items_of_category(hass: HomeAssistant, entry: ConfigEntry, category: str): """Return a list of all Control4 items with the specified category.""" director_all_items = hass.data[DOMAIN][entry.entry_id][CONF_DIRECTOR_ALL_ITEMS] - return_list = [] - for item in director_all_items: - if "categories" in item and category in item["categories"]: - return_list.append(item) - return return_list + return [ + item + for item in director_all_items + if "categories" in item and category in item["categories"] + ] class Control4Entity(CoordinatorEntity): diff --git a/homeassistant/components/crownstone/helpers.py b/homeassistant/components/crownstone/helpers.py index aeb26b19ac3..0dc86ea5f36 100644 --- a/homeassistant/components/crownstone/helpers.py +++ b/homeassistant/components/crownstone/helpers.py @@ -24,17 +24,18 @@ def list_ports_as_str( if no_usb_option: ports_as_string.append(DONT_USE_USB) - for port in serial_ports: - ports_as_string.append( - usb.human_readable_device_name( - port.device, - port.serial_number, - port.manufacturer, - port.description, - f"{hex(port.vid)[2:]:0>4}".upper() if port.vid else None, - f"{hex(port.pid)[2:]:0>4}".upper() if port.pid else None, - ) + ports_as_string.extend( + usb.human_readable_device_name( + port.device, + port.serial_number, + port.manufacturer, + port.description, + f"{hex(port.vid)[2:]:0>4}".upper() if port.vid else None, + f"{hex(port.pid)[2:]:0>4}".upper() if port.pid else None, ) + for port in serial_ports + ) + ports_as_string.append(MANUAL_PATH) ports_as_string.append(REFRESH_LIST) diff --git a/homeassistant/components/cups/sensor.py b/homeassistant/components/cups/sensor.py index 91c0bb5c4b8..36f108a1c14 100644 --- a/homeassistant/components/cups/sensor.py +++ b/homeassistant/components/cups/sensor.py @@ -85,8 +85,10 @@ def setup_platform( dev.append(CupsSensor(data, printer)) if "marker-names" in data.attributes[printer]: - for marker in data.attributes[printer]["marker-names"]: - dev.append(MarkerSensor(data, printer, marker, True)) + dev.extend( + MarkerSensor(data, printer, marker, True) + for marker in data.attributes[printer]["marker-names"] + ) add_entities(dev, True) return diff --git a/homeassistant/components/currencylayer/sensor.py b/homeassistant/components/currencylayer/sensor.py index f5ef455ddfe..2fdf521ad9f 100644 --- a/homeassistant/components/currencylayer/sensor.py +++ b/homeassistant/components/currencylayer/sensor.py @@ -48,12 +48,12 @@ def setup_platform( rest = CurrencylayerData(_RESOURCE, parameters) response = requests.get(_RESOURCE, params=parameters, timeout=10) - sensors = [] - for variable in config[CONF_QUOTE]: - sensors.append(CurrencylayerSensor(rest, base, variable)) if "error" in response.json(): return - add_entities(sensors, True) + add_entities( + (CurrencylayerSensor(rest, base, variable) for variable in config[CONF_QUOTE]), + True, + ) class CurrencylayerSensor(SensorEntity): diff --git a/homeassistant/components/danfoss_air/binary_sensor.py b/homeassistant/components/danfoss_air/binary_sensor.py index c8da17bfddc..358d6ca07ab 100644 --- a/homeassistant/components/danfoss_air/binary_sensor.py +++ b/homeassistant/components/danfoss_air/binary_sensor.py @@ -33,12 +33,13 @@ def setup_platform( ["Danfoss Air Away Mode Active", ReadCommand.away_mode, None], ] - dev = [] - - for sensor in sensors: - dev.append(DanfossAirBinarySensor(data, sensor[0], sensor[1], sensor[2])) - - add_entities(dev, True) + add_entities( + ( + DanfossAirBinarySensor(data, sensor[0], sensor[1], sensor[2]) + for sensor in sensors + ), + True, + ) class DanfossAirBinarySensor(BinarySensorEntity): diff --git a/homeassistant/components/danfoss_air/sensor.py b/homeassistant/components/danfoss_air/sensor.py index 3f1e2b577a6..85b4e89d434 100644 --- a/homeassistant/components/danfoss_air/sensor.py +++ b/homeassistant/components/danfoss_air/sensor.py @@ -97,14 +97,13 @@ def setup_platform( ], ] - dev = [] - - for sensor in sensors: - dev.append( + add_entities( + ( DanfossAir(data, sensor[0], sensor[1], sensor[2], sensor[3], sensor[4]) - ) - - add_entities(dev, True) + for sensor in sensors + ), + True, + ) class DanfossAir(SensorEntity): diff --git a/homeassistant/components/danfoss_air/switch.py b/homeassistant/components/danfoss_air/switch.py index c014f226384..dc3277078b0 100644 --- a/homeassistant/components/danfoss_air/switch.py +++ b/homeassistant/components/danfoss_air/switch.py @@ -47,12 +47,10 @@ def setup_platform( ], ] - dev = [] - - for switch in switches: - dev.append(DanfossAir(data, switch[0], switch[1], switch[2], switch[3])) - - add_entities(dev) + add_entities( + DanfossAir(data, switch[0], switch[1], switch[2], switch[3]) + for switch in switches + ) class DanfossAir(SwitchEntity): diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py index 88f4dd3edb7..ba444be1a8f 100644 --- a/homeassistant/components/deconz/config_flow.py +++ b/homeassistant/components/deconz/config_flow.py @@ -114,10 +114,7 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN): LOGGER.debug("Discovered deCONZ gateways %s", pformat(self.bridges)) if self.bridges: - hosts = [] - - for bridge in self.bridges: - hosts.append(bridge[CONF_HOST]) + hosts = [bridge[CONF_HOST] for bridge in self.bridges] hosts.append(CONF_MANUAL_INPUT) diff --git a/homeassistant/components/decora_wifi/light.py b/homeassistant/components/decora_wifi/light.py index 56488f0712b..798243b5d4b 100644 --- a/homeassistant/components/decora_wifi/light.py +++ b/homeassistant/components/decora_wifi/light.py @@ -63,17 +63,18 @@ def setup_platform( # Gather all the available devices... perms = session.user.get_residential_permissions() - all_switches = [] + all_switches: list = [] for permission in perms: if permission.residentialAccountId is not None: acct = ResidentialAccount(session, permission.residentialAccountId) - for residence in acct.get_residences(): - for switch in residence.get_iot_switches(): - all_switches.append(switch) + all_switches.extend( + switch + for residence in acct.get_residences() + for switch in residence.get_iot_switches() + ) elif permission.residenceId is not None: residence = Residence(session, permission.residenceId) - for switch in residence.get_iot_switches(): - all_switches.append(switch) + all_switches.extend(residence.get_iot_switches()) add_entities(DecoraWifiLight(sw) for sw in all_switches) except ValueError: diff --git a/homeassistant/components/delijn/sensor.py b/homeassistant/components/delijn/sensor.py index 5239d6fbd6b..5693a00e857 100644 --- a/homeassistant/components/delijn/sensor.py +++ b/homeassistant/components/delijn/sensor.py @@ -64,9 +64,8 @@ async def async_setup_platform( session = async_get_clientsession(hass) - sensors = [] - for nextpassage in config[CONF_NEXT_DEPARTURE]: - sensors.append( + async_add_entities( + ( DeLijnPublicTransportSensor( Passages( nextpassage[CONF_STOP_ID], @@ -76,9 +75,10 @@ async def async_setup_platform( True, ) ) - ) - - async_add_entities(sensors, True) + for nextpassage in config[CONF_NEXT_DEPARTURE] + ), + True, + ) class DeLijnPublicTransportSensor(SensorEntity): diff --git a/homeassistant/components/devolo_home_control/binary_sensor.py b/homeassistant/components/devolo_home_control/binary_sensor.py index 564d3a583d2..43793a15368 100644 --- a/homeassistant/components/devolo_home_control/binary_sensor.py +++ b/homeassistant/components/devolo_home_control/binary_sensor.py @@ -34,29 +34,27 @@ async def async_setup_entry( entities: list[BinarySensorEntity] = [] for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]: - for device in gateway.binary_sensor_devices: - for binary_sensor in device.binary_sensor_property: - entities.append( - DevoloBinaryDeviceEntity( - homecontrol=gateway, - device_instance=device, - element_uid=binary_sensor, - ) - ) - for device in gateway.devices.values(): - if hasattr(device, "remote_control_property"): - for remote in device.remote_control_property: - for index in range( - 1, device.remote_control_property[remote].key_count + 1 - ): - entities.append( - DevoloRemoteControl( - homecontrol=gateway, - device_instance=device, - element_uid=remote, - key=index, - ) - ) + entities.extend( + DevoloBinaryDeviceEntity( + homecontrol=gateway, + device_instance=device, + element_uid=binary_sensor, + ) + for device in gateway.binary_sensor_devices + for binary_sensor in device.binary_sensor_property + ) + entities.extend( + DevoloRemoteControl( + homecontrol=gateway, + device_instance=device, + element_uid=remote, + key=index, + ) + for device in gateway.devices.values() + if hasattr(device, "remote_control_property") + for remote in device.remote_control_property + for index in range(1, device.remote_control_property[remote].key_count + 1) + ) async_add_entities(entities) diff --git a/homeassistant/components/devolo_home_control/climate.py b/homeassistant/components/devolo_home_control/climate.py index 702adc06e1f..f94c7dae15a 100644 --- a/homeassistant/components/devolo_home_control/climate.py +++ b/homeassistant/components/devolo_home_control/climate.py @@ -26,26 +26,24 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Get all cover devices and setup them via config entry.""" - entities = [] - for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]: - for device in gateway.multi_level_switch_devices: - for multi_level_switch in device.multi_level_switch_property: - if device.device_model_uid in ( - "devolo.model.Thermostat:Valve", - "devolo.model.Room:Thermostat", - "devolo.model.Eurotronic:Spirit:Device", - "unk.model.Danfoss:Thermostat", - ): - entities.append( - DevoloClimateDeviceEntity( - homecontrol=gateway, - device_instance=device, - element_uid=multi_level_switch, - ) - ) - - async_add_entities(entities) + async_add_entities( + DevoloClimateDeviceEntity( + homecontrol=gateway, + device_instance=device, + element_uid=multi_level_switch, + ) + for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"] + for device in gateway.multi_level_switch_devices + for multi_level_switch in device.multi_level_switch_property + if device.device_model_uid + in ( + "devolo.model.Thermostat:Valve", + "devolo.model.Room:Thermostat", + "devolo.model.Eurotronic:Spirit:Device", + "unk.model.Danfoss:Thermostat", + ) + ) class DevoloClimateDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, ClimateEntity): diff --git a/homeassistant/components/devolo_home_control/cover.py b/homeassistant/components/devolo_home_control/cover.py index 3af0de3a509..03aec622645 100644 --- a/homeassistant/components/devolo_home_control/cover.py +++ b/homeassistant/components/devolo_home_control/cover.py @@ -21,21 +21,18 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Get all cover devices and setup them via config entry.""" - entities = [] - for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]: - for device in gateway.multi_level_switch_devices: - for multi_level_switch in device.multi_level_switch_property: - if multi_level_switch.startswith("devolo.Blinds"): - entities.append( - DevoloCoverDeviceEntity( - homecontrol=gateway, - device_instance=device, - element_uid=multi_level_switch, - ) - ) - - async_add_entities(entities) + async_add_entities( + DevoloCoverDeviceEntity( + homecontrol=gateway, + device_instance=device, + element_uid=multi_level_switch, + ) + for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"] + for device in gateway.multi_level_switch_devices + for multi_level_switch in device.multi_level_switch_property + if multi_level_switch.startswith("devolo.Blinds") + ) class DevoloCoverDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, CoverEntity): diff --git a/homeassistant/components/devolo_home_control/diagnostics.py b/homeassistant/components/devolo_home_control/diagnostics.py index 2a7e82b0901..753d04db0a3 100644 --- a/homeassistant/components/devolo_home_control/diagnostics.py +++ b/homeassistant/components/devolo_home_control/diagnostics.py @@ -22,25 +22,24 @@ async def async_get_config_entry_diagnostics( """Return diagnostics for a config entry.""" gateways: list[HomeControl] = hass.data[DOMAIN][entry.entry_id]["gateways"] - device_info = [] - for gateway in gateways: - device_info.append( - { - "gateway": { - "local_connection": gateway.gateway.local_connection, - "firmware_version": gateway.gateway.firmware_version, - }, - "devices": [ - { - "device_id": device_id, - "device_model_uid": properties.device_model_uid, - "device_type": properties.device_type, - "name": properties.name, - } - for device_id, properties in gateway.devices.items() - ], - } - ) + device_info = [ + { + "gateway": { + "local_connection": gateway.gateway.local_connection, + "firmware_version": gateway.gateway.firmware_version, + }, + "devices": [ + { + "device_id": device_id, + "device_model_uid": properties.device_model_uid, + "device_type": properties.device_type, + "name": properties.name, + } + for device_id, properties in gateway.devices.items() + ], + } + for gateway in gateways + ] diag_data = { "entry": async_redact_data(entry.as_dict(), TO_REDACT), diff --git a/homeassistant/components/devolo_home_control/light.py b/homeassistant/components/devolo_home_control/light.py index 79e3531741f..36c72ca7f57 100644 --- a/homeassistant/components/devolo_home_control/light.py +++ b/homeassistant/components/devolo_home_control/light.py @@ -20,21 +20,18 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Get all light devices and setup them via config entry.""" - entities = [] - for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]: - for device in gateway.multi_level_switch_devices: - for multi_level_switch in device.multi_level_switch_property.values(): - if multi_level_switch.switch_type == "dimmer": - entities.append( - DevoloLightDeviceEntity( - homecontrol=gateway, - device_instance=device, - element_uid=multi_level_switch.element_uid, - ) - ) - - async_add_entities(entities) + async_add_entities( + DevoloLightDeviceEntity( + homecontrol=gateway, + device_instance=device, + element_uid=multi_level_switch.element_uid, + ) + for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"] + for device in gateway.multi_level_switch_devices + for multi_level_switch in device.multi_level_switch_property.values() + if multi_level_switch.switch_type == "dimmer" + ) class DevoloLightDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, LightEntity): diff --git a/homeassistant/components/devolo_home_control/sensor.py b/homeassistant/components/devolo_home_control/sensor.py index 579dc8f38d6..db630cf3532 100644 --- a/homeassistant/components/devolo_home_control/sensor.py +++ b/homeassistant/components/devolo_home_control/sensor.py @@ -45,35 +45,36 @@ async def async_setup_entry( entities: list[SensorEntity] = [] for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]: - for device in gateway.multi_level_sensor_devices: - for multi_level_sensor in device.multi_level_sensor_property: - entities.append( - DevoloGenericMultiLevelDeviceEntity( - homecontrol=gateway, - device_instance=device, - element_uid=multi_level_sensor, - ) - ) - for device in gateway.devices.values(): - if hasattr(device, "consumption_property"): - for consumption in device.consumption_property: - for consumption_type in ("current", "total"): - entities.append( - DevoloConsumptionEntity( - homecontrol=gateway, - device_instance=device, - element_uid=consumption, - consumption=consumption_type, - ) - ) - if hasattr(device, "battery_level"): - entities.append( - DevoloBatteryEntity( - homecontrol=gateway, - device_instance=device, - element_uid=f"devolo.BatterySensor:{device.uid}", - ) - ) + entities.extend( + DevoloGenericMultiLevelDeviceEntity( + homecontrol=gateway, + device_instance=device, + element_uid=multi_level_sensor, + ) + for device in gateway.multi_level_sensor_devices + for multi_level_sensor in device.multi_level_sensor_property + ) + entities.extend( + DevoloConsumptionEntity( + homecontrol=gateway, + device_instance=device, + element_uid=consumption, + consumption=consumption_type, + ) + for device in gateway.devices.values() + if hasattr(device, "consumption_property") + for consumption in device.consumption_property + for consumption_type in ("current", "total") + ) + entities.extend( + DevoloBatteryEntity( + homecontrol=gateway, + device_instance=device, + element_uid=f"devolo.BatterySensor:{device.uid}", + ) + for device in gateway.devices.values() + if hasattr(device, "battery_level") + ) async_add_entities(entities) diff --git a/homeassistant/components/devolo_home_control/siren.py b/homeassistant/components/devolo_home_control/siren.py index f0a2c228068..fd015860bbb 100644 --- a/homeassistant/components/devolo_home_control/siren.py +++ b/homeassistant/components/devolo_home_control/siren.py @@ -18,21 +18,18 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Get all binary sensor and multi level sensor devices and setup them via config entry.""" - entities = [] - for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]: - for device in gateway.multi_level_switch_devices: - for multi_level_switch in device.multi_level_switch_property: - if multi_level_switch.startswith("devolo.SirenMultiLevelSwitch"): - entities.append( - DevoloSirenDeviceEntity( - homecontrol=gateway, - device_instance=device, - element_uid=multi_level_switch, - ) - ) - - async_add_entities(entities) + async_add_entities( + DevoloSirenDeviceEntity( + homecontrol=gateway, + device_instance=device, + element_uid=multi_level_switch, + ) + for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"] + for device in gateway.multi_level_switch_devices + for multi_level_switch in device.multi_level_switch_property + if multi_level_switch.startswith("devolo.SirenMultiLevelSwitch") + ) class DevoloSirenDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, SirenEntity): diff --git a/homeassistant/components/devolo_home_control/switch.py b/homeassistant/components/devolo_home_control/switch.py index 1a6f61f64ab..f599d39d0b6 100644 --- a/homeassistant/components/devolo_home_control/switch.py +++ b/homeassistant/components/devolo_home_control/switch.py @@ -20,23 +20,20 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Get all devices and setup the switch devices via config entry.""" - entities = [] - for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]: - for device in gateway.binary_switch_devices: - for binary_switch in device.binary_switch_property: - # Exclude the binary switch which also has multi_level_switches here, - # because those are implemented as light entities now. - if not hasattr(device, "multi_level_switch_property"): - entities.append( - DevoloSwitch( - homecontrol=gateway, - device_instance=device, - element_uid=binary_switch, - ) - ) - - async_add_entities(entities) + async_add_entities( + DevoloSwitch( + homecontrol=gateway, + device_instance=device, + element_uid=binary_switch, + ) + for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"] + for device in gateway.binary_switch_devices + for binary_switch in device.binary_switch_property + # Exclude the binary switch which also has multi_level_switches here, + # because those are implemented as light entities now. + if not hasattr(device, "multi_level_switch_property") + ) class DevoloSwitch(DevoloDeviceEntity, SwitchEntity): diff --git a/homeassistant/components/directv/media_player.py b/homeassistant/components/directv/media_player.py index 24d21c195a6..736e30b9f96 100644 --- a/homeassistant/components/directv/media_player.py +++ b/homeassistant/components/directv/media_player.py @@ -60,18 +60,18 @@ async def async_setup_entry( ) -> None: """Set up the DirecTV config entry.""" dtv = hass.data[DOMAIN][entry.entry_id] - entities = [] - for location in dtv.device.locations: - entities.append( + async_add_entities( + ( DIRECTVMediaPlayer( dtv=dtv, name=str.title(location.name), address=location.address, ) - ) - - async_add_entities(entities, True) + for location in dtv.device.locations + ), + True, + ) class DIRECTVMediaPlayer(DIRECTVEntity, MediaPlayerEntity): diff --git a/homeassistant/components/directv/remote.py b/homeassistant/components/directv/remote.py index 724984545d2..5a77d90bd3c 100644 --- a/homeassistant/components/directv/remote.py +++ b/homeassistant/components/directv/remote.py @@ -29,18 +29,18 @@ async def async_setup_entry( ) -> None: """Load DirecTV remote based on a config entry.""" dtv = hass.data[DOMAIN][entry.entry_id] - entities = [] - for location in dtv.device.locations: - entities.append( + async_add_entities( + ( DIRECTVRemote( dtv=dtv, name=str.title(location.name), address=location.address, ) - ) - - async_add_entities(entities, True) + for location in dtv.device.locations + ), + True, + ) class DIRECTVRemote(DIRECTVEntity, RemoteEntity): diff --git a/homeassistant/components/dlib_face_detect/image_processing.py b/homeassistant/components/dlib_face_detect/image_processing.py index d2559c0753e..9f6b30dee61 100644 --- a/homeassistant/components/dlib_face_detect/image_processing.py +++ b/homeassistant/components/dlib_face_detect/image_processing.py @@ -24,13 +24,10 @@ def setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Dlib Face detection platform.""" - entities = [] - for camera in config[CONF_SOURCE]: - entities.append( - DlibFaceDetectEntity(camera[CONF_ENTITY_ID], camera.get(CONF_NAME)) - ) - - add_entities(entities) + add_entities( + DlibFaceDetectEntity(camera[CONF_ENTITY_ID], camera.get(CONF_NAME)) + for camera in config[CONF_SOURCE] + ) class DlibFaceDetectEntity(ImageProcessingFaceEntity): diff --git a/homeassistant/components/dlib_face_identify/image_processing.py b/homeassistant/components/dlib_face_identify/image_processing.py index 73cf53db5a2..ac9e69ec9e1 100644 --- a/homeassistant/components/dlib_face_identify/image_processing.py +++ b/homeassistant/components/dlib_face_identify/image_processing.py @@ -38,18 +38,15 @@ def setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Dlib Face detection platform.""" - entities = [] - for camera in config[CONF_SOURCE]: - entities.append( - DlibFaceIdentifyEntity( - camera[CONF_ENTITY_ID], - config[CONF_FACES], - camera.get(CONF_NAME), - config[CONF_CONFIDENCE], - ) + add_entities( + DlibFaceIdentifyEntity( + camera[CONF_ENTITY_ID], + config[CONF_FACES], + camera.get(CONF_NAME), + config[CONF_CONFIDENCE], ) - - add_entities(entities) + for camera in config[CONF_SOURCE] + ) class DlibFaceIdentifyEntity(ImageProcessingFaceEntity): diff --git a/homeassistant/components/doods/image_processing.py b/homeassistant/components/doods/image_processing.py index aa9e9535ea9..11985ef4889 100644 --- a/homeassistant/components/doods/image_processing.py +++ b/homeassistant/components/doods/image_processing.py @@ -112,19 +112,17 @@ def setup_platform( ) return - entities = [] - for camera in config[CONF_SOURCE]: - entities.append( - Doods( - hass, - camera[CONF_ENTITY_ID], - camera.get(CONF_NAME), - doods, - detector, - config, - ) + add_entities( + Doods( + hass, + camera[CONF_ENTITY_ID], + camera.get(CONF_NAME), + doods, + detector, + config, ) - add_entities(entities) + for camera in config[CONF_SOURCE] + ) class Doods(ImageProcessingEntity): diff --git a/homeassistant/components/dsmr/sensor.py b/homeassistant/components/dsmr/sensor.py index 766603f740b..7b2e916529a 100644 --- a/homeassistant/components/dsmr/sensor.py +++ b/homeassistant/components/dsmr/sensor.py @@ -531,9 +531,7 @@ async def async_setup_entry( add_entities_handler = None if dsmr_version == "5B": - mbus_entities = create_mbus_entities(hass, telegram, entry) - for mbus_entity in mbus_entities: - entities.append(mbus_entity) + entities.extend(create_mbus_entities(hass, telegram, entry)) entities.extend( [ diff --git a/homeassistant/components/dynalite/__init__.py b/homeassistant/components/dynalite/__init__.py index e1f0b277945..46fcfb267d0 100644 --- a/homeassistant/components/dynalite/__init__.py +++ b/homeassistant/components/dynalite/__init__.py @@ -65,10 +65,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async def dynalite_service(service_call: ServiceCall) -> None: data = service_call.data host = data.get(ATTR_HOST, "") - bridges = [] - for cur_bridge in hass.data[DOMAIN].values(): - if not host or cur_bridge.host == host: - bridges.append(cur_bridge) + bridges = [ + bridge + for bridge in hass.data[DOMAIN].values() + if not host or bridge.host == host + ] LOGGER.debug("Selected bridged for service call: %s", bridges) if service_call.service == SERVICE_REQUEST_AREA_PRESET: bridge_attr = "request_area_preset" diff --git a/homeassistant/components/dynalite/dynalitebase.py b/homeassistant/components/dynalite/dynalitebase.py index 869695d43f7..bfc62609101 100644 --- a/homeassistant/components/dynalite/dynalitebase.py +++ b/homeassistant/components/dynalite/dynalitebase.py @@ -31,9 +31,7 @@ def async_setup_entry_base( @callback def async_add_entities_platform(devices): # assumes it is called with a single platform - added_entities = [] - for device in devices: - added_entities.append(entity_from_device(device, bridge)) + added_entities = [entity_from_device(device, bridge) for device in devices] async_add_entities(added_entities) bridge.register_add_devices(platform, async_add_entities_platform) diff --git a/tests/components/climate/test_init.py b/tests/components/climate/test_init.py index fcf98876238..3950dea59ed 100644 --- a/tests/components/climate/test_init.py +++ b/tests/components/climate/test_init.py @@ -157,11 +157,12 @@ 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: - if enum not in [ClimateEntityFeature.TURN_ON, ClimateEntityFeature.TURN_OFF]: - result.append((enum, constant_prefix)) - return result + return [ + (enum_field, constant_prefix) + for enum_field in enum + if enum_field + not in [ClimateEntityFeature.TURN_ON, ClimateEntityFeature.TURN_OFF] + ] @pytest.mark.parametrize( diff --git a/tests/components/cover/test_init.py b/tests/components/cover/test_init.py index e44b0788c9a..5d6b40a171f 100644 --- a/tests/components/cover/test_init.py +++ b/tests/components/cover/test_init.py @@ -140,10 +140,7 @@ def is_closing(hass, ent): 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] def test_all() -> None: