diff --git a/homeassistant/components/vasttrafik/sensor.py b/homeassistant/components/vasttrafik/sensor.py index a065d6e1f6d..611f571336c 100644 --- a/homeassistant/components/vasttrafik/sensor.py +++ b/homeassistant/components/vasttrafik/sensor.py @@ -65,10 +65,8 @@ def setup_platform( ) -> None: """Set up the departure sensor.""" planner = vasttrafik.JournyPlanner(config.get(CONF_KEY), config.get(CONF_SECRET)) - sensors = [] - - for departure in config[CONF_DEPARTURES]: - sensors.append( + add_entities( + ( VasttrafikDepartureSensor( planner, departure.get(CONF_NAME), @@ -77,8 +75,10 @@ def setup_platform( departure.get(CONF_LINES), departure.get(CONF_DELAY), ) - ) - add_entities(sensors, True) + for departure in config[CONF_DEPARTURES] + ), + True, + ) class VasttrafikDepartureSensor(SensorEntity): diff --git a/homeassistant/components/velbus/light.py b/homeassistant/components/velbus/light.py index dd740e7e850..7145576be6a 100644 --- a/homeassistant/components/velbus/light.py +++ b/homeassistant/components/velbus/light.py @@ -38,11 +38,10 @@ async def async_setup_entry( """Set up Velbus switch based on config_entry.""" await hass.data[DOMAIN][entry.entry_id]["tsk"] cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"] - entities: list[Entity] = [] - for channel in cntrl.get_all("light"): - entities.append(VelbusLight(channel)) - for channel in cntrl.get_all("led"): - entities.append(VelbusButtonLight(channel)) + entities: list[Entity] = [ + VelbusLight(channel) for channel in cntrl.get_all("light") + ] + entities.extend(VelbusButtonLight(channel) for channel in cntrl.get_all("led")) async_add_entities(entities) diff --git a/homeassistant/components/velbus/switch.py b/homeassistant/components/velbus/switch.py index ebb281753bf..1e6014b8d90 100644 --- a/homeassistant/components/velbus/switch.py +++ b/homeassistant/components/velbus/switch.py @@ -21,10 +21,7 @@ async def async_setup_entry( """Set up Velbus switch based on config_entry.""" await hass.data[DOMAIN][entry.entry_id]["tsk"] cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"] - entities = [] - for channel in cntrl.get_all("switch"): - entities.append(VelbusSwitch(channel)) - async_add_entities(entities) + async_add_entities(VelbusSwitch(channel) for channel in cntrl.get_all("switch")) class VelbusSwitch(VelbusEntity, SwitchEntity): diff --git a/homeassistant/components/velux/cover.py b/homeassistant/components/velux/cover.py index 6f5f453911f..c8688e4d186 100644 --- a/homeassistant/components/velux/cover.py +++ b/homeassistant/components/velux/cover.py @@ -27,12 +27,12 @@ async def async_setup_entry( hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up cover(s) for Velux platform.""" - entities = [] module = hass.data[DOMAIN][config.entry_id] - for node in module.pyvlx.nodes: - if isinstance(node, OpeningDevice): - entities.append(VeluxCover(node)) - async_add_entities(entities) + async_add_entities( + VeluxCover(node) + for node in module.pyvlx.nodes + if isinstance(node, OpeningDevice) + ) class VeluxCover(VeluxEntity, CoverEntity): diff --git a/homeassistant/components/venstar/sensor.py b/homeassistant/components/venstar/sensor.py index c06816ad0af..24b4b2f8b16 100644 --- a/homeassistant/components/venstar/sensor.py +++ b/homeassistant/components/venstar/sensor.py @@ -96,13 +96,11 @@ async def async_setup_entry( ) runtimes = coordinator.runtimes[-1] - for sensor_name in runtimes: - if sensor_name in RUNTIME_DEVICES: - entities.append( - VenstarSensor( - coordinator, config_entry, RUNTIME_ENTITY, sensor_name - ) - ) + entities.extend( + VenstarSensor(coordinator, config_entry, RUNTIME_ENTITY, sensor_name) + for sensor_name in runtimes + if sensor_name in RUNTIME_DEVICES + ) for description in INFO_ENTITIES: try: diff --git a/homeassistant/components/vera/__init__.py b/homeassistant/components/vera/__init__.py index 3111e878820..acbb89f4367 100644 --- a/homeassistant/components/vera/__init__.py +++ b/homeassistant/components/vera/__init__.py @@ -129,14 +129,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if device_type is not None: vera_devices[device_type].append(device) - vera_scenes = [] - for scene in all_scenes: - vera_scenes.append(scene) - controller_data = ControllerData( controller=controller, devices=vera_devices, - scenes=vera_scenes, + scenes=all_scenes, config_entry=entry, ) diff --git a/homeassistant/components/vera/common.py b/homeassistant/components/vera/common.py index 4309a0d43f3..76adeeab1d2 100644 --- a/homeassistant/components/vera/common.py +++ b/homeassistant/components/vera/common.py @@ -27,9 +27,7 @@ class ControllerData(NamedTuple): def get_configured_platforms(controller_data: ControllerData) -> set[Platform]: """Get configured platforms for a controller.""" - platforms: list[Platform] = [] - for platform in controller_data.devices: - platforms.append(platform) + platforms: list[Platform] = list(controller_data.devices) if controller_data.scenes: platforms.append(Platform.SCENE) diff --git a/homeassistant/components/vesync/sensor.py b/homeassistant/components/vesync/sensor.py index d594ec5cb82..81f42f4c2ee 100644 --- a/homeassistant/components/vesync/sensor.py +++ b/homeassistant/components/vesync/sensor.py @@ -194,12 +194,15 @@ async def async_setup_entry( @callback def _setup_entities(devices, async_add_entities): """Check if device is online and add entity.""" - entities = [] - for dev in devices: - for description in SENSORS: - if description.exists_fn(dev): - entities.append(VeSyncSensorEntity(dev, description)) - async_add_entities(entities, update_before_add=True) + async_add_entities( + ( + VeSyncSensorEntity(dev, description) + for dev in devices + for description in SENSORS + if description.exists_fn(dev) + ), + update_before_add=True, + ) class VeSyncSensorEntity(VeSyncBaseEntity, SensorEntity): diff --git a/homeassistant/components/vicare/diagnostics.py b/homeassistant/components/vicare/diagnostics.py index b8cec966199..9182e96509f 100644 --- a/homeassistant/components/vicare/diagnostics.py +++ b/homeassistant/components/vicare/diagnostics.py @@ -19,12 +19,15 @@ async def async_get_config_entry_diagnostics( hass: HomeAssistant, entry: ConfigEntry ) -> dict[str, Any]: """Return diagnostics for a config entry.""" - data = [] - for device in hass.data[DOMAIN][entry.entry_id][DEVICE_LIST]: - data.append( - json.loads(await hass.async_add_executor_job(device.config.dump_secure)) - ) + + def dump_devices() -> list[dict[str, Any]]: + """Dump devices.""" + return [ + json.loads(device.config.dump_secure()) + for device in hass.data[DOMAIN][entry.entry_id][DEVICE_LIST] + ] + return { "entry": async_redact_data(entry.as_dict(), TO_REDACT), - "data": data, + "data": await hass.async_add_executor_job(dump_devices), } diff --git a/homeassistant/components/volvooncall/binary_sensor.py b/homeassistant/components/volvooncall/binary_sensor.py index 390779407fa..604dc2313bf 100644 --- a/homeassistant/components/volvooncall/binary_sensor.py +++ b/homeassistant/components/volvooncall/binary_sensor.py @@ -32,21 +32,17 @@ async def async_setup_entry( @callback def async_discover_device(instruments: list[Instrument]) -> None: """Discover and add a discovered Volvo On Call binary sensor.""" - entities: list[VolvoSensor] = [] - - for instrument in instruments: - if instrument.component == "binary_sensor": - entities.append( - VolvoSensor( - coordinator, - instrument.vehicle.vin, - instrument.component, - instrument.attr, - instrument.slug_attr, - ) - ) - - async_add_entities(entities) + async_add_entities( + VolvoSensor( + coordinator, + instrument.vehicle.vin, + instrument.component, + instrument.attr, + instrument.slug_attr, + ) + for instrument in instruments + if instrument.component == "binary_sensor" + ) async_discover_device([*volvo_data.instruments]) diff --git a/homeassistant/components/volvooncall/device_tracker.py b/homeassistant/components/volvooncall/device_tracker.py index 039679fa413..51c2f08130b 100644 --- a/homeassistant/components/volvooncall/device_tracker.py +++ b/homeassistant/components/volvooncall/device_tracker.py @@ -26,21 +26,17 @@ async def async_setup_entry( @callback def async_discover_device(instruments: list[Instrument]) -> None: """Discover and add a discovered Volvo On Call device tracker.""" - entities: list[VolvoTrackerEntity] = [] - - for instrument in instruments: - if instrument.component == "device_tracker": - entities.append( - VolvoTrackerEntity( - instrument.vehicle.vin, - instrument.component, - instrument.attr, - instrument.slug_attr, - coordinator, - ) - ) - - async_add_entities(entities) + async_add_entities( + VolvoTrackerEntity( + instrument.vehicle.vin, + instrument.component, + instrument.attr, + instrument.slug_attr, + coordinator, + ) + for instrument in instruments + if instrument.component == "device_tracker" + ) async_discover_device([*volvo_data.instruments]) diff --git a/homeassistant/components/volvooncall/lock.py b/homeassistant/components/volvooncall/lock.py index a48b5dc6b65..cccd64bce05 100644 --- a/homeassistant/components/volvooncall/lock.py +++ b/homeassistant/components/volvooncall/lock.py @@ -28,21 +28,17 @@ async def async_setup_entry( @callback def async_discover_device(instruments: list[Instrument]) -> None: """Discover and add a discovered Volvo On Call lock.""" - entities: list[VolvoLock] = [] - - for instrument in instruments: - if instrument.component == "lock": - entities.append( - VolvoLock( - coordinator, - instrument.vehicle.vin, - instrument.component, - instrument.attr, - instrument.slug_attr, - ) - ) - - async_add_entities(entities) + async_add_entities( + VolvoLock( + coordinator, + instrument.vehicle.vin, + instrument.component, + instrument.attr, + instrument.slug_attr, + ) + for instrument in instruments + if instrument.component == "lock" + ) async_discover_device([*volvo_data.instruments]) diff --git a/homeassistant/components/volvooncall/sensor.py b/homeassistant/components/volvooncall/sensor.py index d8acaf34d67..a46c8671929 100644 --- a/homeassistant/components/volvooncall/sensor.py +++ b/homeassistant/components/volvooncall/sensor.py @@ -26,21 +26,17 @@ async def async_setup_entry( @callback def async_discover_device(instruments: list[Instrument]) -> None: """Discover and add a discovered Volvo On Call sensor.""" - entities: list[VolvoSensor] = [] - - for instrument in instruments: - if instrument.component == "sensor": - entities.append( - VolvoSensor( - coordinator, - instrument.vehicle.vin, - instrument.component, - instrument.attr, - instrument.slug_attr, - ) - ) - - async_add_entities(entities) + async_add_entities( + VolvoSensor( + coordinator, + instrument.vehicle.vin, + instrument.component, + instrument.attr, + instrument.slug_attr, + ) + for instrument in instruments + if instrument.component == "sensor" + ) async_discover_device([*volvo_data.instruments]) diff --git a/homeassistant/components/volvooncall/switch.py b/homeassistant/components/volvooncall/switch.py index 571aa88757a..23bc452ef66 100644 --- a/homeassistant/components/volvooncall/switch.py +++ b/homeassistant/components/volvooncall/switch.py @@ -28,21 +28,17 @@ async def async_setup_entry( @callback def async_discover_device(instruments: list[Instrument]) -> None: """Discover and add a discovered Volvo On Call switch.""" - entities: list[VolvoSwitch] = [] - - for instrument in instruments: - if instrument.component == "switch": - entities.append( - VolvoSwitch( - coordinator, - instrument.vehicle.vin, - instrument.component, - instrument.attr, - instrument.slug_attr, - ) - ) - - async_add_entities(entities) + async_add_entities( + VolvoSwitch( + coordinator, + instrument.vehicle.vin, + instrument.component, + instrument.attr, + instrument.slug_attr, + ) + for instrument in instruments + if instrument.component == "switch" + ) async_discover_device([*volvo_data.instruments]) diff --git a/homeassistant/components/vulcan/config_flow.py b/homeassistant/components/vulcan/config_flow.py index b761527e660..15749a7bf3d 100644 --- a/homeassistant/components/vulcan/config_flow.py +++ b/homeassistant/components/vulcan/config_flow.py @@ -190,9 +190,7 @@ class VulcanFlowHandler(ConfigFlow, domain=DOMAIN): async def async_step_add_next_config_entry(self, user_input=None): """Flow initialized when user is adding next entry of that integration.""" - existing_entries = [] - for entry in self.hass.config_entries.async_entries(DOMAIN): - existing_entries.append(entry) + existing_entries = self.hass.config_entries.async_entries(DOMAIN) errors = {} @@ -205,13 +203,14 @@ class VulcanFlowHandler(ConfigFlow, domain=DOMAIN): account = Account.load(existing_entries[0].data["account"]) client = Vulcan(keystore, account, async_get_clientsession(self.hass)) students = await client.get_students() - new_students = [] - existing_entry_ids = [] - for entry in self.hass.config_entries.async_entries(DOMAIN): - existing_entry_ids.append(entry.data["student_id"]) - for student in students: - if str(student.pupil.id) not in existing_entry_ids: - new_students.append(student) + existing_entry_ids = [ + entry.data["student_id"] for entry in existing_entries + ] + new_students = [ + student + for student in students + if str(student.pupil.id) not in existing_entry_ids + ] if not new_students: return self.async_abort(reason="all_student_already_configured") if len(new_students) == 1: @@ -277,9 +276,7 @@ class VulcanFlowHandler(ConfigFlow, domain=DOMAIN): keystore = credentials["keystore"] client = Vulcan(keystore, account, async_get_clientsession(self.hass)) students = await client.get_students() - existing_entries = [] - for entry in self.hass.config_entries.async_entries(DOMAIN): - existing_entries.append(entry) + existing_entries = self.hass.config_entries.async_entries(DOMAIN) matching_entries = False for student in students: for entry in existing_entries: diff --git a/homeassistant/components/waterfurnace/sensor.py b/homeassistant/components/waterfurnace/sensor.py index 46f76a58eb5..1e03ad88cc8 100644 --- a/homeassistant/components/waterfurnace/sensor.py +++ b/homeassistant/components/waterfurnace/sensor.py @@ -104,12 +104,9 @@ def setup_platform( if discovery_info is None: return - sensors = [] client = hass.data[WF_DOMAIN] - for description in SENSORS: - sensors.append(WaterFurnaceSensor(client, description)) - add_entities(sensors) + add_entities(WaterFurnaceSensor(client, description) for description in SENSORS) class WaterFurnaceSensor(SensorEntity): diff --git a/homeassistant/components/wled/number.py b/homeassistant/components/wled/number.py index 4dcdc493e53..e6142c1cea6 100644 --- a/homeassistant/components/wled/number.py +++ b/homeassistant/components/wled/number.py @@ -140,7 +140,8 @@ def async_update_segments( # Process new segments, add them to Home Assistant for segment_id in segment_ids - current_ids: current_ids.add(segment_id) - for desc in NUMBERS: - new_entities.append(WLEDNumber(coordinator, segment_id, desc)) + new_entities.extend( + WLEDNumber(coordinator, segment_id, desc) for desc in NUMBERS + ) async_add_entities(new_entities) diff --git a/homeassistant/components/workday/config_flow.py b/homeassistant/components/workday/config_flow.py index a1a5ed37a14..a66a9c51588 100644 --- a/homeassistant/components/workday/config_flow.py +++ b/homeassistant/components/workday/config_flow.py @@ -66,9 +66,7 @@ def add_province_and_language_to_schema( _country = country_holidays(country=country) if country_default_language := (_country.default_language): selectable_languages = _country.supported_languages - new_selectable_languages = [] - for lang in selectable_languages: - new_selectable_languages.append(lang[:2]) + new_selectable_languages = [lang[:2] for lang in selectable_languages] language_schema = { vol.Optional( CONF_LANGUAGE, default=country_default_language diff --git a/tests/components/venstar/util.py b/tests/components/venstar/util.py index 23e480272d0..369d3332135 100644 --- a/tests/components/venstar/util.py +++ b/tests/components/venstar/util.py @@ -47,14 +47,13 @@ async def async_init_integration( skip_setup: bool = False, ): """Set up the venstar integration in Home Assistant.""" - platform_config = [] - for model in TEST_MODELS: - platform_config.append( - { - CONF_PLATFORM: "venstar", - CONF_HOST: f"venstar-{model}.localdomain", - } - ) + platform_config = [ + { + CONF_PLATFORM: "venstar", + CONF_HOST: f"venstar-{model}.localdomain", + } + for model in TEST_MODELS + ] config = {DOMAIN: platform_config} await async_setup_component(hass, DOMAIN, config) diff --git a/tests/components/vesync/common.py b/tests/components/vesync/common.py index 2e5a973c143..23c57177ddd 100644 --- a/tests/components/vesync/common.py +++ b/tests/components/vesync/common.py @@ -49,10 +49,11 @@ def mock_devices_response( requests_mock: requests_mock.Mocker, device_name: str ) -> None: """Build a response for the Helpers.call_api method.""" - device_list = [] - for device in ALL_DEVICES["result"]["list"]: - if device["deviceName"] == device_name: - device_list.append(device) + device_list = [ + device + for device in ALL_DEVICES["result"]["list"] + if device["deviceName"] == device_name + ] requests_mock.post( "https://smartapi.vesync.com/cloud/v1/deviceManaged/devices", diff --git a/tests/components/vultr/test_switch.py b/tests/components/vultr/test_switch.py index a8968682aef..9f98447af41 100644 --- a/tests/components/vultr/test_switch.py +++ b/tests/components/vultr/test_switch.py @@ -141,8 +141,7 @@ def test_invalid_switches(hass: HomeAssistant) -> None: def add_entities(devices, action): """Mock add devices.""" - for device in devices: - hass_devices.append(device) + hass_devices.extend(devices) bad_conf = {} # No subscription diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index 5e4eff5da53..7eee2261a26 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -684,9 +684,7 @@ async def test_get_states( assert msg["type"] == const.TYPE_RESULT assert msg["success"] - states = [] - for state in hass.states.async_all(): - states.append(state.as_dict()) + states = [state.as_dict() for state in hass.states.async_all()] assert msg["result"] == states diff --git a/tests/components/wsdot/test_sensor.py b/tests/components/wsdot/test_sensor.py index 4a912340078..9f5ec92a5b6 100644 --- a/tests/components/wsdot/test_sensor.py +++ b/tests/components/wsdot/test_sensor.py @@ -46,8 +46,7 @@ async def test_setup(hass: HomeAssistant, requests_mock: requests_mock.Mocker) - for entity in new_entities: entity.update() - for entity in new_entities: - entities.append(entity) + entities.extend(new_entities) uri = re.compile(RESOURCE + "*") requests_mock.get(uri, text=load_fixture("wsdot/wsdot.json"))