From 96cebdf096230576aecbcc62100b73781b874c66 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 13 Mar 2024 17:54:46 +0100 Subject: [PATCH] Improve lists in integrations [T-U] (#113243) --- homeassistant/components/tami4/sensor.py | 17 +++++----- homeassistant/components/ted5000/sensor.py | 11 +++---- .../components/tellduslive/__init__.py | 5 +-- .../components/tensorflow/image_processing.py | 22 ++++++------- .../components/thermoworks_smoke/sensor.py | 19 ++++++------ .../components/thread/websocket_api.py | 31 +++++++++---------- .../components/tibber/diagnostics.py | 14 +++------ homeassistant/components/tibber/sensor.py | 6 ++-- .../totalconnect/alarm_control_panel.py | 18 +++++------ homeassistant/components/touchline/climate.py | 11 ++++--- homeassistant/components/tplink/switch.py | 6 ++-- homeassistant/components/trace/__init__.py | 8 ++--- .../components/tradfri/diagnostics.py | 7 +++-- .../components/tuya/alarm_control_panel.py | 10 +++--- homeassistant/components/tuya/button.py | 10 +++--- homeassistant/components/tuya/cover.py | 10 +++--- homeassistant/components/tuya/light.py | 10 +++--- homeassistant/components/tuya/number.py | 10 +++--- homeassistant/components/tuya/select.py | 10 +++--- homeassistant/components/tuya/sensor.py | 10 +++--- homeassistant/components/tuya/switch.py | 10 +++--- homeassistant/components/twinkly/light.py | 5 +-- .../components/ukraine_alarm/config_flow.py | 16 ++-------- .../components/unifi/hub/entity_loader.py | 14 ++++----- .../components/unifiprotect/light.py | 11 +++---- .../components/unifiprotect/select.py | 6 ++-- tests/components/unifiprotect/test_migrate.py | 18 ++++++----- .../components/universal/test_media_player.py | 3 +- 28 files changed, 153 insertions(+), 175 deletions(-) diff --git a/homeassistant/components/tami4/sensor.py b/homeassistant/components/tami4/sensor.py index b93342d9144..3772ef0bccb 100644 --- a/homeassistant/components/tami4/sensor.py +++ b/homeassistant/components/tami4/sensor.py @@ -69,17 +69,14 @@ async def async_setup_entry( api: Tami4EdgeAPI = data[API] coordinator: Tami4EdgeWaterQualityCoordinator = data[COORDINATOR] - entities = [] - for entity_description in ENTITY_DESCRIPTIONS: - entities.append( - Tami4EdgeSensorEntity( - coordinator=coordinator, - api=api, - entity_description=entity_description, - ) + async_add_entities( + Tami4EdgeSensorEntity( + coordinator=coordinator, + api=api, + entity_description=entity_description, ) - - async_add_entities(entities) + for entity_description in ENTITY_DESCRIPTIONS + ) class Tami4EdgeSensorEntity( diff --git a/homeassistant/components/ted5000/sensor.py b/homeassistant/components/ted5000/sensor.py index 9dafe945188..99d8991a02e 100644 --- a/homeassistant/components/ted5000/sensor.py +++ b/homeassistant/components/ted5000/sensor.py @@ -78,12 +78,11 @@ def setup_platform( # Get MUT information to create the sensors. gateway.update() - entities = [] - for mtu in gateway.data: - for description in SENSORS: - entities.append(Ted5000Sensor(gateway, name, mtu, description)) - - add_entities(entities) + add_entities( + Ted5000Sensor(gateway, name, mtu, description) + for mtu in gateway.data + for description in SENSORS + ) class Ted5000Sensor(SensorEntity): diff --git a/homeassistant/components/tellduslive/__init__.py b/homeassistant/components/tellduslive/__init__.py index fcabea070b1..92e61edec56 100644 --- a/homeassistant/components/tellduslive/__init__.py +++ b/homeassistant/components/tellduslive/__init__.py @@ -186,8 +186,9 @@ class TelldusLiveClient: self._hass.data[CONFIG_ENTRY_IS_SETUP].add(component) device_ids = [] if device.is_sensor: - for item in device.items: - device_ids.append((device.device_id, item.name, item.scale)) + device_ids.extend( + (device.device_id, item.name, item.scale) for item in device.items + ) else: device_ids.append(device_id) for _id in device_ids: diff --git a/homeassistant/components/tensorflow/image_processing.py b/homeassistant/components/tensorflow/image_processing.py index 3025ffa27c7..632db28ca3a 100644 --- a/homeassistant/components/tensorflow/image_processing.py +++ b/homeassistant/components/tensorflow/image_processing.py @@ -196,20 +196,16 @@ def setup_platform( labels, use_display_name=True ) - entities = [] - - for camera in config[CONF_SOURCE]: - entities.append( - TensorFlowImageProcessor( - hass, - camera[CONF_ENTITY_ID], - camera.get(CONF_NAME), - category_index, - config, - ) + add_entities( + TensorFlowImageProcessor( + hass, + camera[CONF_ENTITY_ID], + camera.get(CONF_NAME), + category_index, + config, ) - - add_entities(entities) + for camera in config[CONF_SOURCE] + ) class TensorFlowImageProcessor(ImageProcessingEntity): diff --git a/homeassistant/components/thermoworks_smoke/sensor.py b/homeassistant/components/thermoworks_smoke/sensor.py index 33681d5e574..b2d6613f2e5 100644 --- a/homeassistant/components/thermoworks_smoke/sensor.py +++ b/homeassistant/components/thermoworks_smoke/sensor.py @@ -86,22 +86,21 @@ def setup_platform( try: mgr = thermoworks_smoke.initialize_app(email, password, True, excluded) - - # list of sensor devices - dev = [] - - # get list of registered devices - for serial in mgr.serials(): - for variable in monitored_variables: - dev.append(ThermoworksSmokeSensor(variable, serial, mgr)) - - add_entities(dev, True) except HTTPError as error: msg = f"{error.strerror}" if "EMAIL_NOT_FOUND" in msg or "INVALID_PASSWORD" in msg: _LOGGER.error("Invalid email and password combination") else: _LOGGER.error(msg) + else: + add_entities( + ( + ThermoworksSmokeSensor(variable, serial, mgr) + for serial in mgr.serials() + for variable in monitored_variables + ), + True, + ) class ThermoworksSmokeSensor(SensorEntity): diff --git a/homeassistant/components/thread/websocket_api.py b/homeassistant/components/thread/websocket_api.py index 2ac817c2b75..687c4067caf 100644 --- a/homeassistant/components/thread/websocket_api.py +++ b/homeassistant/components/thread/websocket_api.py @@ -166,23 +166,22 @@ async def ws_list_datasets( """Get a list of thread datasets.""" store = await dataset_store.async_get_store(hass) - result = [] preferred_dataset = store.preferred_dataset - for dataset in store.datasets.values(): - result.append( - { - "channel": dataset.channel, - "created": dataset.created, - "dataset_id": dataset.id, - "extended_pan_id": dataset.extended_pan_id, - "network_name": dataset.network_name, - "pan_id": dataset.pan_id, - "preferred": dataset.id == preferred_dataset, - "preferred_border_agent_id": dataset.preferred_border_agent_id, - "preferred_extended_address": dataset.preferred_extended_address, - "source": dataset.source, - } - ) + result = [ + { + "channel": dataset.channel, + "created": dataset.created, + "dataset_id": dataset.id, + "extended_pan_id": dataset.extended_pan_id, + "network_name": dataset.network_name, + "pan_id": dataset.pan_id, + "preferred": dataset.id == preferred_dataset, + "preferred_border_agent_id": dataset.preferred_border_agent_id, + "preferred_extended_address": dataset.preferred_extended_address, + "source": dataset.source, + } + for dataset in store.datasets.values() + ] connection.send_result(msg["id"], {"datasets": result}) diff --git a/homeassistant/components/tibber/diagnostics.py b/homeassistant/components/tibber/diagnostics.py index f0fc6fec58b..2306aac23e1 100644 --- a/homeassistant/components/tibber/diagnostics.py +++ b/homeassistant/components/tibber/diagnostics.py @@ -18,11 +18,8 @@ async def async_get_config_entry_diagnostics( """Return diagnostics for a config entry.""" tibber_connection: tibber.Tibber = hass.data[DOMAIN] - diagnostics_data = {} - - homes = [] - for home in tibber_connection.get_homes(only_active=False): - homes.append( + return { + "homes": [ { "last_data_timestamp": home.last_data_timestamp, "has_active_subscription": home.has_active_subscription, @@ -30,7 +27,6 @@ async def async_get_config_entry_diagnostics( "last_cons_data_timestamp": home.last_cons_data_timestamp, "country": home.country, } - ) - diagnostics_data["homes"] = homes - - return diagnostics_data + for home in tibber_connection.get_homes(only_active=False) + ] + } diff --git a/homeassistant/components/tibber/sensor.py b/homeassistant/components/tibber/sensor.py index 075b2518bd2..a57c5d3e8dd 100644 --- a/homeassistant/components/tibber/sensor.py +++ b/homeassistant/components/tibber/sensor.py @@ -295,8 +295,10 @@ async def async_setup_entry( entities.append(TibberSensorElPrice(home)) if coordinator is None: coordinator = TibberDataCoordinator(hass, tibber_connection) - for entity_description in SENSORS: - entities.append(TibberDataSensor(home, coordinator, entity_description)) + entities.extend( + TibberDataSensor(home, coordinator, entity_description) + for entity_description in SENSORS + ) if home.has_real_time_consumption: await home.rt_subscribe( diff --git a/homeassistant/components/totalconnect/alarm_control_panel.py b/homeassistant/components/totalconnect/alarm_control_panel.py index 50d889eeba1..3f2c51989f9 100644 --- a/homeassistant/components/totalconnect/alarm_control_panel.py +++ b/homeassistant/components/totalconnect/alarm_control_panel.py @@ -36,21 +36,21 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up TotalConnect alarm panels based on a config entry.""" - alarms = [] + alarms: list[TotalConnectAlarm] = [] coordinator: TotalConnectDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] for location_id, location in coordinator.client.locations.items(): location_name = location.location_name - for partition_id in location.partitions: - alarms.append( - TotalConnectAlarm( - coordinator=coordinator, - name=location_name, - location_id=location_id, - partition_id=partition_id, - ) + alarms.extend( + TotalConnectAlarm( + coordinator=coordinator, + name=location_name, + location_id=location_id, + partition_id=partition_id, ) + for partition_id in location.partitions + ) async_add_entities(alarms) diff --git a/homeassistant/components/touchline/climate.py b/homeassistant/components/touchline/climate.py index 04251648cc1..83c7839772a 100644 --- a/homeassistant/components/touchline/climate.py +++ b/homeassistant/components/touchline/climate.py @@ -55,10 +55,13 @@ def setup_platform( host = config[CONF_HOST] py_touchline = PyTouchline() number_of_devices = int(py_touchline.get_number_of_devices(host)) - devices = [] - for device_id in range(0, number_of_devices): - devices.append(Touchline(PyTouchline(device_id))) - add_entities(devices, True) + add_entities( + ( + Touchline(PyTouchline(device_id)) + for device_id in range(0, number_of_devices) + ), + True, + ) class Touchline(ClimateEntity): diff --git a/homeassistant/components/tplink/switch.py b/homeassistant/components/tplink/switch.py index 0d5aa9d2224..da3dda9c041 100644 --- a/homeassistant/components/tplink/switch.py +++ b/homeassistant/components/tplink/switch.py @@ -37,8 +37,10 @@ async def async_setup_entry( if device.is_strip: # Historically we only add the children if the device is a strip _LOGGER.debug("Initializing strip with %s sockets", len(device.children)) - for child in device.children: - entities.append(SmartPlugSwitchChild(device, parent_coordinator, child)) + entities.extend( + SmartPlugSwitchChild(device, parent_coordinator, child) + for child in device.children + ) elif device.is_plug: entities.append(SmartPlugSwitch(device, parent_coordinator)) diff --git a/homeassistant/components/trace/__init__.py b/homeassistant/components/trace/__init__.py index 9551c5c7276..d0ec4555376 100644 --- a/homeassistant/components/trace/__init__.py +++ b/homeassistant/components/trace/__init__.py @@ -111,13 +111,9 @@ async def async_list_contexts( def _get_debug_traces(hass: HomeAssistant, key: str) -> list[dict[str, Any]]: """Return a serializable list of debug traces for a script or automation.""" - traces: list[dict[str, Any]] = [] - if traces_for_key := _get_data(hass).get(key): - for trace in traces_for_key.values(): - traces.append(trace.as_short_dict()) - - return traces + return [trace.as_short_dict() for trace in traces_for_key.values()] + return [] async def async_list_traces( diff --git a/homeassistant/components/tradfri/diagnostics.py b/homeassistant/components/tradfri/diagnostics.py index 0237382ec39..4d89fd0081f 100644 --- a/homeassistant/components/tradfri/diagnostics.py +++ b/homeassistant/components/tradfri/diagnostics.py @@ -26,9 +26,10 @@ async def async_get_config_entry_diagnostics( ), ) - device_data: list = [] - for coordinator in coordinator_data[COORDINATOR_LIST]: - device_data.append(coordinator.device.device_info.model_number) + device_data: list = [ + coordinator.device.device_info.model_number + for coordinator in coordinator_data[COORDINATOR_LIST] + ] return { "gateway_version": device.sw_version, diff --git a/homeassistant/components/tuya/alarm_control_panel.py b/homeassistant/components/tuya/alarm_control_panel.py index 74392b20148..59075cf00cd 100644 --- a/homeassistant/components/tuya/alarm_control_panel.py +++ b/homeassistant/components/tuya/alarm_control_panel.py @@ -71,11 +71,11 @@ async def async_setup_entry( for device_id in device_ids: device = hass_data.manager.device_map[device_id] if descriptions := ALARM.get(device.category): - for description in descriptions: - if description.key in device.status: - entities.append( - TuyaAlarmEntity(device, hass_data.manager, description) - ) + entities.extend( + TuyaAlarmEntity(device, hass_data.manager, description) + for description in descriptions + if description.key in device.status + ) async_add_entities(entities) async_discover_device([*hass_data.manager.device_map]) diff --git a/homeassistant/components/tuya/button.py b/homeassistant/components/tuya/button.py index c0363eebe72..a170ddb09e9 100644 --- a/homeassistant/components/tuya/button.py +++ b/homeassistant/components/tuya/button.py @@ -71,11 +71,11 @@ async def async_setup_entry( for device_id in device_ids: device = hass_data.manager.device_map[device_id] if descriptions := BUTTONS.get(device.category): - for description in descriptions: - if description.key in device.status: - entities.append( - TuyaButtonEntity(device, hass_data.manager, description) - ) + entities.extend( + TuyaButtonEntity(device, hass_data.manager, description) + for description in descriptions + if description.key in device.status + ) async_add_entities(entities) diff --git a/homeassistant/components/tuya/cover.py b/homeassistant/components/tuya/cover.py index 21191ece553..7dc54888ac4 100644 --- a/homeassistant/components/tuya/cover.py +++ b/homeassistant/components/tuya/cover.py @@ -155,14 +155,14 @@ async def async_setup_entry( for device_id in device_ids: device = hass_data.manager.device_map[device_id] if descriptions := COVERS.get(device.category): - for description in descriptions: + entities.extend( + TuyaCoverEntity(device, hass_data.manager, description) + for description in descriptions if ( description.key in device.function or description.key in device.status_range - ): - entities.append( - TuyaCoverEntity(device, hass_data.manager, description) - ) + ) + ) async_add_entities(entities) diff --git a/homeassistant/components/tuya/light.py b/homeassistant/components/tuya/light.py index 0f769191710..144e3746285 100644 --- a/homeassistant/components/tuya/light.py +++ b/homeassistant/components/tuya/light.py @@ -417,11 +417,11 @@ async def async_setup_entry( for device_id in device_ids: device = hass_data.manager.device_map[device_id] if descriptions := LIGHTS.get(device.category): - for description in descriptions: - if description.key in device.status: - entities.append( - TuyaLightEntity(device, hass_data.manager, description) - ) + entities.extend( + TuyaLightEntity(device, hass_data.manager, description) + for description in descriptions + if description.key in device.status + ) async_add_entities(entities) diff --git a/homeassistant/components/tuya/number.py b/homeassistant/components/tuya/number.py index f8d05d0841e..2be7deef89f 100644 --- a/homeassistant/components/tuya/number.py +++ b/homeassistant/components/tuya/number.py @@ -294,11 +294,11 @@ async def async_setup_entry( for device_id in device_ids: device = hass_data.manager.device_map[device_id] if descriptions := NUMBERS.get(device.category): - for description in descriptions: - if description.key in device.status: - entities.append( - TuyaNumberEntity(device, hass_data.manager, description) - ) + entities.extend( + TuyaNumberEntity(device, hass_data.manager, description) + for description in descriptions + if description.key in device.status + ) async_add_entities(entities) diff --git a/homeassistant/components/tuya/select.py b/homeassistant/components/tuya/select.py index 472f11e12b0..6e128bfdcc4 100644 --- a/homeassistant/components/tuya/select.py +++ b/homeassistant/components/tuya/select.py @@ -332,11 +332,11 @@ async def async_setup_entry( for device_id in device_ids: device = hass_data.manager.device_map[device_id] if descriptions := SELECTS.get(device.category): - for description in descriptions: - if description.key in device.status: - entities.append( - TuyaSelectEntity(device, hass_data.manager, description) - ) + entities.extend( + TuyaSelectEntity(device, hass_data.manager, description) + for description in descriptions + if description.key in device.status + ) async_add_entities(entities) diff --git a/homeassistant/components/tuya/sensor.py b/homeassistant/components/tuya/sensor.py index 7669cfa0f32..df11840931d 100644 --- a/homeassistant/components/tuya/sensor.py +++ b/homeassistant/components/tuya/sensor.py @@ -1087,11 +1087,11 @@ async def async_setup_entry( for device_id in device_ids: device = hass_data.manager.device_map[device_id] if descriptions := SENSORS.get(device.category): - for description in descriptions: - if description.key in device.status: - entities.append( - TuyaSensorEntity(device, hass_data.manager, description) - ) + entities.extend( + TuyaSensorEntity(device, hass_data.manager, description) + for description in descriptions + if description.key in device.status + ) async_add_entities(entities) diff --git a/homeassistant/components/tuya/switch.py b/homeassistant/components/tuya/switch.py index 9b90d391d98..36debaeadde 100644 --- a/homeassistant/components/tuya/switch.py +++ b/homeassistant/components/tuya/switch.py @@ -672,11 +672,11 @@ async def async_setup_entry( for device_id in device_ids: device = hass_data.manager.device_map[device_id] if descriptions := SWITCHES.get(device.category): - for description in descriptions: - if description.key in device.status: - entities.append( - TuyaSwitchEntity(device, hass_data.manager, description) - ) + entities.extend( + TuyaSwitchEntity(device, hass_data.manager, description) + for description in descriptions + if description.key in device.status + ) async_add_entities(entities) diff --git a/homeassistant/components/twinkly/light.py b/homeassistant/components/twinkly/light.py index 6bfc205b553..2749c9a7764 100644 --- a/homeassistant/components/twinkly/light.py +++ b/homeassistant/components/twinkly/light.py @@ -130,10 +130,7 @@ class TwinklyLight(LightEntity): @property def effect_list(self) -> list[str]: """Return the list of saved effects.""" - effect_list = [] - for movie in self._movies: - effect_list.append(f"{movie['id']} {movie['name']}") - return effect_list + return [f"{movie['id']} {movie['name']}" for movie in self._movies] async def async_added_to_hass(self) -> None: """Device is added to hass.""" diff --git a/homeassistant/components/ukraine_alarm/config_flow.py b/homeassistant/components/ukraine_alarm/config_flow.py index 9b593b77639..bafe6d1fe11 100644 --- a/homeassistant/components/ukraine_alarm/config_flow.py +++ b/homeassistant/components/ukraine_alarm/config_flow.py @@ -133,17 +133,5 @@ def _find(regions, region_id): def _make_regions_object(regions): - regions_list = [] - for region in regions: - regions_list.append( - { - "id": region["regionId"], - "name": region["regionName"], - } - ) - regions_list = sorted(regions_list, key=lambda region: region["name"].lower()) - regions_object = {} - for region in regions_list: - regions_object[region["id"]] = region["name"] - - return regions_object + regions = sorted(regions, key=lambda region: region["regionName"].lower()) + return {region["regionId"]: region["regionName"] for region in regions} diff --git a/homeassistant/components/unifi/hub/entity_loader.py b/homeassistant/components/unifi/hub/entity_loader.py index af63419d82a..a7a1cb970ec 100644 --- a/homeassistant/components/unifi/hub/entity_loader.py +++ b/homeassistant/components/unifi/hub/entity_loader.py @@ -83,14 +83,14 @@ class UnifiEntityLoader: Provide inactive clients to device tracker and switch platform. """ config = self.hub.config - macs: list[str] = [] entity_registry = er.async_get(self.hub.hass) - for entry in async_entries_for_config_entry( - entity_registry, config.entry.entry_id - ): - if entry.domain == Platform.DEVICE_TRACKER and "-" in entry.unique_id: - macs.append(entry.unique_id.split("-", 1)[1]) - + macs: list[str] = [ + entry.unique_id.split("-", 1)[1] + for entry in async_entries_for_config_entry( + entity_registry, config.entry.entry_id + ) + if entry.domain == Platform.DEVICE_TRACKER and "-" in entry.unique_id + ] api = self.hub.api for mac in config.option_supported_clients + config.option_block_clients + macs: if mac not in api.clients and mac in api.clients_all: diff --git a/homeassistant/components/unifiprotect/light.py b/homeassistant/components/unifiprotect/light.py index 5a1e5dfd0c4..3ce236b3e23 100644 --- a/homeassistant/components/unifiprotect/light.py +++ b/homeassistant/components/unifiprotect/light.py @@ -45,12 +45,11 @@ async def async_setup_entry( async_dispatcher_connect(hass, _ufpd(entry, DISPATCH_ADOPT), _add_new_device) ) - entities = [] - for device in data.get_by_types({ModelType.LIGHT}): - if device.can_write(data.api.bootstrap.auth_user): - entities.append(ProtectLight(data, device)) - - async_add_entities(entities) + async_add_entities( + ProtectLight(data, device) + for device in data.get_by_types({ModelType.LIGHT}) + if device.can_write(data.api.bootstrap.auth_user) + ) def unifi_brightness_to_hass(value: int) -> int: diff --git a/homeassistant/components/unifiprotect/select.py b/homeassistant/components/unifiprotect/select.py index 7d1ca436c78..13bf18eb2a7 100644 --- a/homeassistant/components/unifiprotect/select.py +++ b/homeassistant/components/unifiprotect/select.py @@ -130,8 +130,10 @@ def _get_doorbell_options(api: ProtectApiClient) -> list[dict[str, Any]]: def _get_paired_camera_options(api: ProtectApiClient) -> list[dict[str, Any]]: options = [{"id": TYPE_EMPTY_VALUE, "name": "Not Paired"}] - for camera in api.bootstrap.cameras.values(): - options.append({"id": camera.id, "name": camera.display_name or camera.type}) + options.extend( + {"id": camera.id, "name": camera.display_name or camera.type} + for camera in api.bootstrap.cameras.values() + ) return options diff --git a/tests/components/unifiprotect/test_migrate.py b/tests/components/unifiprotect/test_migrate.py index 475f6170550..88d66c819bc 100644 --- a/tests/components/unifiprotect/test_migrate.py +++ b/tests/components/unifiprotect/test_migrate.py @@ -52,10 +52,11 @@ async def test_migrate_reboot_button( assert ufp.api.update.called assert ufp.entry.unique_id == ufp.api.bootstrap.nvr.mac - buttons = [] - for entity in er.async_entries_for_config_entry(registry, ufp.entry.entry_id): - if entity.domain == Platform.BUTTON.value: - buttons.append(entity) + buttons = [ + entity + for entity in er.async_entries_for_config_entry(registry, ufp.entry.entry_id) + if entity.domain == Platform.BUTTON.value + ] assert len(buttons) == 4 assert registry.async_get(f"{Platform.BUTTON}.test_light_1_reboot_device") is None @@ -133,10 +134,11 @@ async def test_migrate_reboot_button_no_device( assert ufp.api.update.called assert ufp.entry.unique_id == ufp.api.bootstrap.nvr.mac - buttons = [] - for entity in er.async_entries_for_config_entry(registry, ufp.entry.entry_id): - if entity.domain == Platform.BUTTON.value: - buttons.append(entity) + buttons = [ + entity + for entity in er.async_entries_for_config_entry(registry, ufp.entry.entry_id) + if entity.domain == Platform.BUTTON.value + ] assert len(buttons) == 3 entity = registry.async_get(f"{Platform.BUTTON}.unifiprotect_{light2_id.lower()}") diff --git a/tests/components/universal/test_media_player.py b/tests/components/universal/test_media_player.py index c48316e6f22..9fa55ae6725 100644 --- a/tests/components/universal/test_media_player.py +++ b/tests/components/universal/test_media_player.py @@ -365,8 +365,7 @@ async def test_platform_setup(hass: HomeAssistant) -> None: def add_entities(new_entities): """Add devices to list.""" - for dev in new_entities: - entities.append(dev) + entities.extend(new_entities) setup_ok = True try: