diff --git a/homeassistant/components/assist_pipeline/websocket_api.py b/homeassistant/components/assist_pipeline/websocket_api.py index 7550f860a9b..3e8cdf6fa42 100644 --- a/homeassistant/components/assist_pipeline/websocket_api.py +++ b/homeassistant/components/assist_pipeline/websocket_api.py @@ -291,8 +291,11 @@ def websocket_list_runs( msg["id"], { "pipeline_runs": [ - {"pipeline_run_id": id, "timestamp": pipeline_run.timestamp} - for id, pipeline_run in pipeline_debug.items() + { + "pipeline_run_id": pipeline_run_id, + "timestamp": pipeline_run.timestamp, + } + for pipeline_run_id, pipeline_run in pipeline_debug.items() ] }, ) diff --git a/homeassistant/components/jellyfin/__init__.py b/homeassistant/components/jellyfin/__init__.py index c24f06d7b19..de9fa805f02 100644 --- a/homeassistant/components/jellyfin/__init__.py +++ b/homeassistant/components/jellyfin/__init__.py @@ -73,6 +73,6 @@ async def async_remove_config_entry_device( return not device_entry.identifiers.intersection( ( (DOMAIN, coordinator.server_id), - *((DOMAIN, id) for id in coordinator.device_ids), + *((DOMAIN, device_id) for device_id in coordinator.device_ids), ) ) diff --git a/homeassistant/components/media_extractor/__init__.py b/homeassistant/components/media_extractor/__init__.py index 228a012a04f..139acf06cf6 100644 --- a/homeassistant/components/media_extractor/__init__.py +++ b/homeassistant/components/media_extractor/__init__.py @@ -278,9 +278,9 @@ def get_best_stream_youtube(formats: list[dict[str, Any]]) -> str: return get_best_stream( [ - format - for format in formats - if format.get("acodec", "none") != "none" - and format.get("vcodec", "none") != "none" + stream_format + for stream_format in formats + if stream_format.get("acodec", "none") != "none" + and stream_format.get("vcodec", "none") != "none" ] ) diff --git a/homeassistant/components/nest/device_info.py b/homeassistant/components/nest/device_info.py index f269e3e89d6..33793fe836b 100644 --- a/homeassistant/components/nest/device_info.py +++ b/homeassistant/components/nest/device_info.py @@ -73,7 +73,7 @@ class NestDeviceInfo: """Return device suggested area based on the Google Home room.""" if parent_relations := self._device.parent_relations: items = sorted(parent_relations.items()) - names = [name for id, name in items] + names = [name for _, name in items] return " ".join(names) return None diff --git a/homeassistant/components/onewire/binary_sensor.py b/homeassistant/components/onewire/binary_sensor.py index fea78fd3760..d2e66609103 100644 --- a/homeassistant/components/onewire/binary_sensor.py +++ b/homeassistant/components/onewire/binary_sensor.py @@ -36,33 +36,33 @@ class OneWireBinarySensorEntityDescription( DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = { "12": tuple( OneWireBinarySensorEntityDescription( - key=f"sensed.{id}", + key=f"sensed.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, translation_key="sensed_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_A_B + for device_key in DEVICE_KEYS_A_B ), "29": tuple( OneWireBinarySensorEntityDescription( - key=f"sensed.{id}", + key=f"sensed.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, translation_key="sensed_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_0_7 + for device_key in DEVICE_KEYS_0_7 ), "3A": tuple( OneWireBinarySensorEntityDescription( - key=f"sensed.{id}", + key=f"sensed.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, translation_key="sensed_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_A_B + for device_key in DEVICE_KEYS_A_B ), "EF": (), # "HobbyBoard": special } @@ -71,15 +71,15 @@ DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ... HOBBYBOARD_EF: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = { "HB_HUB": tuple( OneWireBinarySensorEntityDescription( - key=f"hub/short.{id}", + key=f"hub/short.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, translation_key="hub_short_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_0_3 + for device_key in DEVICE_KEYS_0_3 ), } diff --git a/homeassistant/components/onewire/sensor.py b/homeassistant/components/onewire/sensor.py index d32afce7fa9..46f18842d51 100644 --- a/homeassistant/components/onewire/sensor.py +++ b/homeassistant/components/onewire/sensor.py @@ -233,14 +233,14 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = { "42": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,), "1D": tuple( OneWireSensorEntityDescription( - key=f"counter.{id}", + key=f"counter.{device_key}", native_unit_of_measurement="count", read_mode=READ_MODE_INT, state_class=SensorStateClass.TOTAL_INCREASING, translation_key="counter_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_A_B + for device_key in DEVICE_KEYS_A_B ), } @@ -273,15 +273,15 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = { ), "HB_MOISTURE_METER": tuple( OneWireSensorEntityDescription( - key=f"moisture/sensor.{id}", + key=f"moisture/sensor.{device_key}", device_class=SensorDeviceClass.PRESSURE, native_unit_of_measurement=UnitOfPressure.CBAR, read_mode=READ_MODE_FLOAT, state_class=SensorStateClass.MEASUREMENT, translation_key="moisture_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_0_3 + for device_key in DEVICE_KEYS_0_3 ), } diff --git a/homeassistant/components/onewire/switch.py b/homeassistant/components/onewire/switch.py index cdf1315394e..41276218540 100644 --- a/homeassistant/components/onewire/switch.py +++ b/homeassistant/components/onewire/switch.py @@ -40,23 +40,23 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = { "12": tuple( [ OneWireSwitchEntityDescription( - key=f"PIO.{id}", + key=f"PIO.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, translation_key="pio_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_A_B + for device_key in DEVICE_KEYS_A_B ] + [ OneWireSwitchEntityDescription( - key=f"latch.{id}", + key=f"latch.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, translation_key="latch_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_A_B + for device_key in DEVICE_KEYS_A_B ] ), "26": ( @@ -71,34 +71,34 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = { "29": tuple( [ OneWireSwitchEntityDescription( - key=f"PIO.{id}", + key=f"PIO.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, translation_key="pio_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_0_7 + for device_key in DEVICE_KEYS_0_7 ] + [ OneWireSwitchEntityDescription( - key=f"latch.{id}", + key=f"latch.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, translation_key="latch_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_0_7 + for device_key in DEVICE_KEYS_0_7 ] ), "3A": tuple( OneWireSwitchEntityDescription( - key=f"PIO.{id}", + key=f"PIO.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, translation_key="pio_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_A_B + for device_key in DEVICE_KEYS_A_B ), "EF": (), # "HobbyBoard": special } @@ -108,37 +108,37 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = { HOBBYBOARD_EF: dict[str, tuple[OneWireEntityDescription, ...]] = { "HB_HUB": tuple( OneWireSwitchEntityDescription( - key=f"hub/branch.{id}", + key=f"hub/branch.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, entity_category=EntityCategory.CONFIG, translation_key="hub_branch_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_0_3 + for device_key in DEVICE_KEYS_0_3 ), "HB_MOISTURE_METER": tuple( [ OneWireSwitchEntityDescription( - key=f"moisture/is_leaf.{id}", + key=f"moisture/is_leaf.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, entity_category=EntityCategory.CONFIG, translation_key="leaf_sensor_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_0_3 + for device_key in DEVICE_KEYS_0_3 ] + [ OneWireSwitchEntityDescription( - key=f"moisture/is_moisture.{id}", + key=f"moisture/is_moisture.{device_key}", entity_registry_enabled_default=False, read_mode=READ_MODE_BOOL, entity_category=EntityCategory.CONFIG, translation_key="moisture_sensor_id", - translation_placeholders={"id": str(id)}, + translation_placeholders={"id": str(device_key)}, ) - for id in DEVICE_KEYS_0_3 + for device_key in DEVICE_KEYS_0_3 ] ), } diff --git a/homeassistant/components/risco/sensor.py b/homeassistant/components/risco/sensor.py index f4d6ddaf451..8f97c76c879 100644 --- a/homeassistant/components/risco/sensor.py +++ b/homeassistant/components/risco/sensor.py @@ -56,8 +56,8 @@ async def async_setup_entry( config_entry.entry_id ][EVENTS_COORDINATOR] sensors = [ - RiscoSensor(coordinator, id, [], name, config_entry.entry_id) - for id, name in CATEGORIES.items() + RiscoSensor(coordinator, category_id, [], name, config_entry.entry_id) + for category_id, name in CATEGORIES.items() ] sensors.append( RiscoSensor( diff --git a/homeassistant/components/roborock/vacuum.py b/homeassistant/components/roborock/vacuum.py index d8108abf78c..16cf518aa02 100644 --- a/homeassistant/components/roborock/vacuum.py +++ b/homeassistant/components/roborock/vacuum.py @@ -178,4 +178,8 @@ class RoborockVacuum(RoborockCoordinatedEntity, StateVacuumEntity): async def get_maps(self) -> ServiceResponse: """Get map information such as map id and room ids.""" - return {"maps": [asdict(map) for map in self.coordinator.maps.values()]} + return { + "maps": [ + asdict(vacuum_map) for vacuum_map in self.coordinator.maps.values() + ] + } diff --git a/homeassistant/components/synology_dsm/__init__.py b/homeassistant/components/synology_dsm/__init__.py index ec13ec929a5..2748b27c93d 100644 --- a/homeassistant/components/synology_dsm/__init__.py +++ b/homeassistant/components/synology_dsm/__init__.py @@ -161,6 +161,8 @@ async def async_remove_config_entry_device( return not device_entry.identifiers.intersection( ( (DOMAIN, serial), # Base device - *((DOMAIN, f"{serial}_{id}") for id in device_ids), # Storage and cameras + *( + (DOMAIN, f"{serial}_{device_id}") for device_id in device_ids + ), # Storage and cameras ) ) diff --git a/homeassistant/components/zwave_js/siren.py b/homeassistant/components/zwave_js/siren.py index b3f54ae9904..413186da9bf 100644 --- a/homeassistant/components/zwave_js/siren.py +++ b/homeassistant/components/zwave_js/siren.py @@ -63,7 +63,8 @@ class ZwaveSirenEntity(ZWaveBaseEntity, SirenEntity): super().__init__(config_entry, driver, info) # Entity class attributes self._attr_available_tones = { - int(id): val for id, val in self.info.primary_value.metadata.states.items() + int(state_id): val + for state_id, val in self.info.primary_value.metadata.states.items() } self._attr_supported_features = ( SirenEntityFeature.TURN_ON diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 1f0742e896d..16379c1d05c 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -1347,8 +1347,8 @@ def device_id(hass: HomeAssistant, entity_id_or_device_name: str) -> str | None: dev_reg = device_registry.async_get(hass) return next( ( - id - for id, device in dev_reg.devices.items() + device_id + for device_id, device in dev_reg.devices.items() if (name := device.name_by_user or device.name) and (str(entity_id_or_device_name) == name) ), diff --git a/pyproject.toml b/pyproject.toml index 91f75c96fd6..d3487d50a17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -251,7 +251,7 @@ disable = [ "nested-min-max", # PLW3301 "pointless-statement", # B018 "raise-missing-from", # B904 - # "redefined-builtin", # A001, ruff is way more stricter, needs work + "redefined-builtin", # A001 "try-except-raise", # TRY302 "unused-argument", # ARG001, we don't use it "unused-format-string-argument", #F507 @@ -663,6 +663,7 @@ required-version = ">=0.4.1" [tool.ruff.lint] select = [ + "A001", # Variable {name} is shadowing a Python builtin "B002", # Python does not support the unary prefix increment "B005", # Using .strip() with multi-character strings is misleading "B007", # Loop control variable {name} not used within loop body diff --git a/tests/components/alexa/test_common.py b/tests/components/alexa/test_common.py index 0cc4d995efa..9fdcc1c89c1 100644 --- a/tests/components/alexa/test_common.py +++ b/tests/components/alexa/test_common.py @@ -158,14 +158,14 @@ async def assert_power_controller_works( _, response = await assert_request_calls_service( "Alexa.PowerController", "TurnOn", endpoint, on_service, hass ) - for property in response["context"]["properties"]: - assert property["timeOfSample"] == timestamp + for context_property in response["context"]["properties"]: + assert context_property["timeOfSample"] == timestamp _, response = await assert_request_calls_service( "Alexa.PowerController", "TurnOff", endpoint, off_service, hass ) - for property in response["context"]["properties"]: - assert property["timeOfSample"] == timestamp + for context_property in response["context"]["properties"]: + assert context_property["timeOfSample"] == timestamp async def assert_scene_controller_works( diff --git a/tests/components/device_automation/test_init.py b/tests/components/device_automation/test_init.py index 4526a9d9b67..3c3101d7a1f 100644 --- a/tests/components/device_automation/test_init.py +++ b/tests/components/device_automation/test_init.py @@ -328,23 +328,23 @@ async def test_websocket_get_action_capabilities( assert msg["success"] actions = msg["result"] - id = 2 + msg_id = 2 assert len(actions) == 3 for action in actions: await client.send_json( { - "id": id, + "id": msg_id, "type": "device_automation/action/capabilities", "action": action, } ) msg = await client.receive_json() - assert msg["id"] == id + assert msg["id"] == msg_id assert msg["type"] == TYPE_RESULT assert msg["success"] capabilities = msg["result"] assert capabilities == expected_capabilities[action["type"]] - id = id + 1 + msg_id = msg_id + 1 async def test_websocket_get_action_capabilities_unknown_domain( @@ -487,23 +487,23 @@ async def test_websocket_get_condition_capabilities( assert msg["success"] conditions = msg["result"] - id = 2 + msg_id = 2 assert len(conditions) == 2 for condition in conditions: await client.send_json( { - "id": id, + "id": msg_id, "type": "device_automation/condition/capabilities", "condition": condition, } ) msg = await client.receive_json() - assert msg["id"] == id + assert msg["id"] == msg_id assert msg["type"] == TYPE_RESULT assert msg["success"] capabilities = msg["result"] assert capabilities == expected_capabilities - id = id + 1 + msg_id = msg_id + 1 async def test_websocket_get_condition_capabilities_unknown_domain( @@ -775,23 +775,23 @@ async def test_websocket_get_trigger_capabilities( assert msg["success"] triggers = msg["result"] - id = 2 + msg_id = 2 assert len(triggers) == 3 # toggled, turned_on, turned_off for trigger in triggers: await client.send_json( { - "id": id, + "id": msg_id, "type": "device_automation/trigger/capabilities", "trigger": trigger, } ) msg = await client.receive_json() - assert msg["id"] == id + assert msg["id"] == msg_id assert msg["type"] == TYPE_RESULT assert msg["success"] capabilities = msg["result"] assert capabilities == expected_capabilities - id = id + 1 + msg_id = msg_id + 1 async def test_websocket_get_trigger_capabilities_unknown_domain( diff --git a/tests/components/devolo_home_control/test_siren.py b/tests/components/devolo_home_control/test_siren.py index 037d7b5021f..be662418967 100644 --- a/tests/components/devolo_home_control/test_siren.py +++ b/tests/components/devolo_home_control/test_siren.py @@ -66,7 +66,7 @@ async def test_siren_switching( with patch( "devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set" - ) as set: + ) as property_set: await hass.services.async_call( "siren", "turn_on", @@ -78,11 +78,11 @@ async def test_siren_switching( "Test", ("devolo.SirenMultiLevelSwitch:Test", 1) ) await hass.async_block_till_done() - set.assert_called_once_with(1) + property_set.assert_called_once_with(1) with patch( "devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set" - ) as set: + ) as property_set: await hass.services.async_call( "siren", "turn_off", @@ -95,7 +95,7 @@ async def test_siren_switching( ) await hass.async_block_till_done() assert hass.states.get(f"{DOMAIN}.test").state == STATE_OFF - set.assert_called_once_with(0) + property_set.assert_called_once_with(0) @pytest.mark.usefixtures("mock_zeroconf") @@ -119,7 +119,7 @@ async def test_siren_change_default_tone( with patch( "devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set" - ) as set: + ) as property_set: test_gateway.publisher.dispatch("Test", ("mss:Test", 2)) await hass.services.async_call( "siren", @@ -127,7 +127,7 @@ async def test_siren_change_default_tone( {"entity_id": f"{DOMAIN}.test"}, blocking=True, ) - set.assert_called_once_with(2) + property_set.assert_called_once_with(2) @pytest.mark.usefixtures("mock_zeroconf") diff --git a/tests/components/hue/test_config_flow.py b/tests/components/hue/test_config_flow.py index 325c32227e3..692bd1405cf 100644 --- a/tests/components/hue/test_config_flow.py +++ b/tests/components/hue/test_config_flow.py @@ -36,7 +36,10 @@ def create_mock_api_discovery(aioclient_mock, bridges): """Patch aiohttp responses with fake data for bridge discovery.""" aioclient_mock.get( URL_NUPNP, - json=[{"internalipaddress": host, "id": id} for (host, id) in bridges], + json=[ + {"internalipaddress": host, "id": bridge_id} + for (host, bridge_id) in bridges + ], ) for host, bridge_id in bridges: aioclient_mock.get( diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 37f7e0cf587..7bb43568b30 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -3033,14 +3033,16 @@ async def test_debug_info_multiple_devices( for dev in devices: data = json.dumps(dev["config"]) domain = dev["domain"] - id = dev["config"]["device"]["identifiers"][0] - async_fire_mqtt_message(hass, f"homeassistant/{domain}/{id}/config", data) + device_id = dev["config"]["device"]["identifiers"][0] + async_fire_mqtt_message( + hass, f"homeassistant/{domain}/{device_id}/config", data + ) await hass.async_block_till_done() for dev in devices: domain = dev["domain"] - id = dev["config"]["device"]["identifiers"][0] - device = device_registry.async_get_device(identifiers={("mqtt", id)}) + device_id = dev["config"]["device"]["identifiers"][0] + device = device_registry.async_get_device(identifiers={("mqtt", device_id)}) assert device is not None debug_info_data = debug_info.info_for_device(hass, device.id) @@ -3058,7 +3060,7 @@ async def test_debug_info_multiple_devices( assert len(debug_info_data["triggers"]) == 1 discovery_data = debug_info_data["triggers"][0]["discovery_data"] - assert discovery_data["topic"] == f"homeassistant/{domain}/{id}/config" + assert discovery_data["topic"] == f"homeassistant/{domain}/{device_id}/config" assert discovery_data["payload"] == dev["config"] @@ -3116,8 +3118,10 @@ async def test_debug_info_multiple_entities_triggers( data = json.dumps(c["config"]) domain = c["domain"] # Use topic as discovery_id - id = c["config"].get("topic", c["config"].get("state_topic")) - async_fire_mqtt_message(hass, f"homeassistant/{domain}/{id}/config", data) + discovery_id = c["config"].get("topic", c["config"].get("state_topic")) + async_fire_mqtt_message( + hass, f"homeassistant/{domain}/{discovery_id}/config", data + ) await hass.async_block_till_done() device_id = config[0]["config"]["device"]["identifiers"][0] @@ -3131,7 +3135,7 @@ async def test_debug_info_multiple_entities_triggers( # Test we get debug info for each entity and trigger domain = c["domain"] # Use topic as discovery_id - id = c["config"].get("topic", c["config"].get("state_topic")) + discovery_id = c["config"].get("topic", c["config"].get("state_topic")) if c["domain"] != "device_automation": discovery_data = [e["discovery_data"] for e in debug_info_data["entities"]] @@ -3143,7 +3147,7 @@ async def test_debug_info_multiple_entities_triggers( discovery_data = [e["discovery_data"] for e in debug_info_data["triggers"]] assert { - "topic": f"homeassistant/{domain}/{id}/config", + "topic": f"homeassistant/{domain}/{discovery_id}/config", "payload": c["config"], } in discovery_data diff --git a/tests/components/recorder/common.py b/tests/components/recorder/common.py index 7a57b226d77..e0f43323f25 100644 --- a/tests/components/recorder/common.py +++ b/tests/components/recorder/common.py @@ -109,7 +109,9 @@ async def async_wait_recording_done(hass: HomeAssistant) -> None: await hass.async_block_till_done() -async def async_wait_purge_done(hass: HomeAssistant, max: int | None = None) -> None: +async def async_wait_purge_done( + hass: HomeAssistant, max_number: int | None = None +) -> None: """Wait for max number of purge events. Because a purge may insert another PurgeTask into @@ -117,9 +119,9 @@ async def async_wait_purge_done(hass: HomeAssistant, max: int | None = None) -> a maximum number of WaitTasks that we will put into the queue. """ - if not max: - max = DEFAULT_PURGE_TASKS - for _ in range(max + 1): + if not max_number: + max_number = DEFAULT_PURGE_TASKS + for _ in range(max_number + 1): await async_wait_recording_done(hass) @@ -325,10 +327,10 @@ def convert_pending_states_to_meta(instance: Recorder, session: Session) -> None entity_ids: set[str] = set() states: set[States] = set() states_meta_objects: dict[str, StatesMeta] = {} - for object in session: - if isinstance(object, States): - entity_ids.add(object.entity_id) - states.add(object) + for session_object in session: + if isinstance(session_object, States): + entity_ids.add(session_object.entity_id) + states.add(session_object) entity_id_to_metadata_ids = instance.states_meta_manager.get_many( entity_ids, session, True @@ -352,10 +354,10 @@ def convert_pending_events_to_event_types(instance: Recorder, session: Session) event_types: set[str] = set() events: set[Events] = set() event_types_objects: dict[str, EventTypes] = {} - for object in session: - if isinstance(object, Events): - event_types.add(object.event_type) - events.add(object) + for session_object in session: + if isinstance(session_object, Events): + event_types.add(session_object.event_type) + events.add(session_object) event_type_to_event_type_ids = instance.event_type_manager.get_many( event_types, session, True diff --git a/tests/components/recorder/test_util.py b/tests/components/recorder/test_util.py index 549280efba2..9e32fa2c500 100644 --- a/tests/components/recorder/test_util.py +++ b/tests/components/recorder/test_util.py @@ -1040,14 +1040,14 @@ async def test_resolve_period(hass: HomeAssistant) -> None: def test_chunked_or_all(): """Test chunked_or_all can iterate chunk sizes larger than the passed in collection.""" - all = [] + all_items = [] incoming = (1, 2, 3, 4) for chunk in chunked_or_all(incoming, 2): assert len(chunk) == 2 - all.extend(chunk) - assert all == [1, 2, 3, 4] + all_items.extend(chunk) + assert all_items == [1, 2, 3, 4] - all = [] + all_items = [] incoming = (1, 2, 3, 4) for chunk in chunked_or_all(incoming, 5): assert len(chunk) == 4 @@ -1055,5 +1055,5 @@ def test_chunked_or_all(): # collection since we want to avoid copying the collection # if we don't need to assert chunk is incoming - all.extend(chunk) - assert all == [1, 2, 3, 4] + all_items.extend(chunk) + assert all_items == [1, 2, 3, 4] diff --git a/tests/components/recorder/test_websocket_api.py b/tests/components/recorder/test_websocket_api.py index d594218e9d4..4a1410d45a4 100644 --- a/tests/components/recorder/test_websocket_api.py +++ b/tests/components/recorder/test_websocket_api.py @@ -641,12 +641,12 @@ async def test_statistic_during_period_hole( recorder_mock: Recorder, hass: HomeAssistant, hass_ws_client: WebSocketGenerator ) -> None: """Test statistic_during_period when there are holes in the data.""" - id = 1 + stat_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal stat_id + stat_id += 1 + return stat_id now = dt_util.utcnow() diff --git a/tests/components/risco/test_binary_sensor.py b/tests/components/risco/test_binary_sensor.py index ea18c59e236..b6ea723064e 100644 --- a/tests/components/risco/test_binary_sensor.py +++ b/tests/components/risco/test_binary_sensor.py @@ -122,11 +122,11 @@ async def test_local_setup( async def _check_local_state( - hass, zones, property, value, entity_id, zone_id, callback + hass, zones, entity_property, value, entity_id, zone_id, callback ): with patch.object( zones[zone_id], - property, + entity_property, new_callable=PropertyMock(return_value=value), ): await callback(zone_id, zones[zone_id]) @@ -210,19 +210,19 @@ async def test_armed_local_states( ) -async def _check_system_state(hass, system, property, value, callback): +async def _check_system_state(hass, system, entity_property, value, callback): with patch.object( system, - property, + entity_property, new_callable=PropertyMock(return_value=value), ): await callback(system) await hass.async_block_till_done() expected_value = STATE_ON if value else STATE_OFF - if property == "ac_trouble": - property = "a_c_trouble" - entity_id = f"binary_sensor.test_site_name_{property}" + if entity_property == "ac_trouble": + entity_property = "a_c_trouble" + entity_id = f"binary_sensor.test_site_name_{entity_property}" assert hass.states.get(entity_id).state == expected_value @@ -275,6 +275,10 @@ async def test_system_states( "clock_trouble", "box_tamper", ] - for property in properties: - await _check_system_state(hass, system_only_local, property, True, callback) - await _check_system_state(hass, system_only_local, property, False, callback) + for entity_property in properties: + await _check_system_state( + hass, system_only_local, entity_property, True, callback + ) + await _check_system_state( + hass, system_only_local, entity_property, False, callback + ) diff --git a/tests/components/risco/test_sensor.py b/tests/components/risco/test_sensor.py index 157eb3e62b5..a8236ad3d87 100644 --- a/tests/components/risco/test_sensor.py +++ b/tests/components/risco/test_sensor.py @@ -133,8 +133,8 @@ async def test_error_on_login( await hass.async_block_till_done() registry = er.async_get(hass) - for id in ENTITY_IDS.values(): - assert not registry.async_is_registered(id) + for entity_id in ENTITY_IDS.values(): + assert not registry.async_is_registered(entity_id) def _check_state(hass, category, entity_id): @@ -184,8 +184,8 @@ async def test_cloud_setup( ) -> None: """Test entity setup.""" registry = er.async_get(hass) - for id in ENTITY_IDS.values(): - assert registry.async_is_registered(id) + for entity_id in ENTITY_IDS.values(): + assert registry.async_is_registered(entity_id) save_mock.assert_awaited_once_with({LAST_EVENT_TIMESTAMP_KEY: TEST_EVENTS[0].time}) for category, entity_id in ENTITY_IDS.items(): @@ -213,5 +213,5 @@ async def test_local_setup( ) -> None: """Test entity setup.""" registry = er.async_get(hass) - for id in ENTITY_IDS.values(): - assert not registry.async_is_registered(id) + for entity_id in ENTITY_IDS.values(): + assert not registry.async_is_registered(entity_id) diff --git a/tests/components/sensor/test_recorder.py b/tests/components/sensor/test_recorder.py index 8084fe69e89..a7aaf938410 100644 --- a/tests/components/sensor/test_recorder.py +++ b/tests/components/sensor/test_recorder.py @@ -560,7 +560,7 @@ def test_compile_hourly_statistics_purged_state_changes( ) assert_dict_of_states_equal_without_context_and_last_changed(states, hist) - mean = min = max = float(hist["sensor.test1"][-1].state) + mean = min_value = max_value = float(hist["sensor.test1"][-1].state) # Purge all states from the database with freeze_time(four): @@ -594,8 +594,8 @@ def test_compile_hourly_statistics_purged_state_changes( "start": process_timestamp(zero).timestamp(), "end": process_timestamp(zero + timedelta(minutes=5)).timestamp(), "mean": pytest.approx(mean), - "min": pytest.approx(min), - "max": pytest.approx(max), + "min": pytest.approx(min_value), + "max": pytest.approx(max_value), "last_reset": None, "state": None, "sum": None, @@ -4113,12 +4113,12 @@ async def test_validate_unit_change_convertible( The test also asserts that the sensor's device class is ignored. """ - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -4228,12 +4228,12 @@ async def test_validate_statistics_unit_ignore_device_class( The test asserts that the sensor's device class is ignored. """ - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -4321,14 +4321,14 @@ async def test_validate_statistics_unit_change_no_device_class( conversion, and the unit is then changed to a unit which can and cannot be converted to the original unit. """ - id = 1 + msg_id = 1 attributes = dict(attributes) attributes.pop("device_class") def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -4436,12 +4436,12 @@ async def test_validate_statistics_unsupported_state_class( unit, ) -> None: """Test validate_statistics.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -4505,12 +4505,12 @@ async def test_validate_statistics_sensor_no_longer_recorded( unit, ) -> None: """Test validate_statistics.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -4573,12 +4573,12 @@ async def test_validate_statistics_sensor_not_recorded( unit, ) -> None: """Test validate_statistics.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -4638,12 +4638,12 @@ async def test_validate_statistics_sensor_removed( unit, ) -> None: """Test validate_statistics.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -4702,12 +4702,12 @@ async def test_validate_statistics_unit_change_no_conversion( unit2, ) -> None: """Test validate_statistics.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -4837,12 +4837,12 @@ async def test_validate_statistics_unit_change_equivalent_units( This tests no validation issue is created when a sensor's unit changes to an equivalent unit. """ - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -4923,12 +4923,12 @@ async def test_validate_statistics_unit_change_equivalent_units_2( equivalent unit which is not known to the unit converters. """ - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( @@ -5005,12 +5005,12 @@ async def test_validate_statistics_other_domain( recorder_mock: Recorder, hass: HomeAssistant, hass_ws_client: WebSocketGenerator ) -> None: """Test sensor does not raise issues for statistics for other domains.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_validation_result(client, expected_result): await client.send_json( diff --git a/tests/components/shelly/test_device_trigger.py b/tests/components/shelly/test_device_trigger.py index c4db8acaf6d..39238f1674a 100644 --- a/tests/components/shelly/test_device_trigger.py +++ b/tests/components/shelly/test_device_trigger.py @@ -96,11 +96,11 @@ async def test_get_triggers_rpc_device( CONF_PLATFORM: "device", CONF_DEVICE_ID: device.id, CONF_DOMAIN: DOMAIN, - CONF_TYPE: type, + CONF_TYPE: trigger_type, CONF_SUBTYPE: "button1", "metadata": {}, } - for type in [ + for trigger_type in [ "btn_down", "btn_up", "single_push", @@ -130,11 +130,11 @@ async def test_get_triggers_button( CONF_PLATFORM: "device", CONF_DEVICE_ID: device.id, CONF_DOMAIN: DOMAIN, - CONF_TYPE: type, + CONF_TYPE: trigger_type, CONF_SUBTYPE: "button", "metadata": {}, } - for type in ["single", "double", "triple", "long"] + for trigger_type in ["single", "double", "triple", "long"] ] triggers = await async_get_device_automations( diff --git a/tests/components/smartthings/conftest.py b/tests/components/smartthings/conftest.py index b6d34b9d98a..d25cc8849e5 100644 --- a/tests/components/smartthings/conftest.py +++ b/tests/components/smartthings/conftest.py @@ -342,7 +342,7 @@ def event_request_factory_fixture(event_factory): if events is None: events = [] if device_ids: - events.extend([event_factory(id) for id in device_ids]) + events.extend([event_factory(device_id) for device_id in device_ids]) events.append(event_factory(uuid4())) events.append(event_factory(device_ids[0], event_type="OTHER")) request.events = events diff --git a/tests/components/tautulli/test_config_flow.py b/tests/components/tautulli/test_config_flow.py index b731067cd72..ca563cfad77 100644 --- a/tests/components/tautulli/test_config_flow.py +++ b/tests/components/tautulli/test_config_flow.py @@ -133,7 +133,7 @@ async def test_flow_user_multiple_entries_allowed(hass: HomeAssistant) -> None: assert result["step_id"] == "user" assert result["errors"] == {} - input = { + user_input = { CONF_URL: "http://1.2.3.5:8181/test", CONF_API_KEY: "efgh", CONF_VERIFY_SSL: True, @@ -141,13 +141,13 @@ async def test_flow_user_multiple_entries_allowed(hass: HomeAssistant) -> None: with patch_config_flow_tautulli(AsyncMock()): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], - user_input=input, + user_input=user_input, ) await hass.async_block_till_done() assert result2["type"] is FlowResultType.CREATE_ENTRY assert result2["title"] == NAME - assert result2["data"] == input + assert result2["data"] == user_input async def test_flow_reauth( diff --git a/tests/components/trace/test_websocket_api.py b/tests/components/trace/test_websocket_api.py index 5c5d882b721..f2cfb6a109f 100644 --- a/tests/components/trace/test_websocket_api.py +++ b/tests/components/trace/test_websocket_api.py @@ -133,12 +133,12 @@ async def test_get_trace( ) -> None: """Test tracing a script or automation.""" await async_setup_component(hass, "homeassistant", {}) - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id sun_config = { "id": "sun", @@ -429,12 +429,12 @@ async def test_restore_traces( ) -> None: """Test restored traces.""" hass.set_state(CoreState.not_running) - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id saved_traces = json.loads(load_fixture(f"trace/{domain}_saved_traces.json")) hass_storage["trace.saved_traces"] = saved_traces @@ -522,7 +522,7 @@ async def test_trace_overflow( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, stored_traces ) -> None: """Test the number of stored traces per script or automation is limited.""" - id = 1 + msg_id = 1 trace_uuids = [] @@ -532,9 +532,9 @@ async def test_trace_overflow( return trace_uuids[-1] def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id sun_config = { "id": "sun", @@ -601,7 +601,7 @@ async def test_restore_traces_overflow( ) -> None: """Test restored traces are evicted first.""" hass.set_state(CoreState.not_running) - id = 1 + msg_id = 1 trace_uuids = [] @@ -611,9 +611,9 @@ async def test_restore_traces_overflow( return trace_uuids[-1] def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id saved_traces = json.loads(load_fixture(f"trace/{domain}_saved_traces.json")) hass_storage["trace.saved_traces"] = saved_traces @@ -682,7 +682,7 @@ async def test_restore_traces_late_overflow( ) -> None: """Test restored traces are evicted first.""" hass.set_state(CoreState.not_running) - id = 1 + msg_id = 1 trace_uuids = [] @@ -692,9 +692,9 @@ async def test_restore_traces_late_overflow( return trace_uuids[-1] def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id saved_traces = json.loads(load_fixture(f"trace/{domain}_saved_traces.json")) hass_storage["trace.saved_traces"] = saved_traces @@ -743,12 +743,12 @@ async def test_trace_no_traces( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain ) -> None: """Test the storing traces for a script or automation can be disabled.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id sun_config = { "id": "sun", @@ -810,12 +810,12 @@ async def test_list_traces( ) -> None: """Test listing script and automation traces.""" await async_setup_component(hass, "homeassistant", {}) - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id sun_config = { "id": "sun", @@ -943,12 +943,12 @@ async def test_nested_traces( extra_trace_keys, ) -> None: """Test nested automation and script traces.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id sun_config = { "id": "sun", @@ -1003,12 +1003,12 @@ async def test_breakpoints( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, prefix ) -> None: """Test script and automation breakpoints.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_last_step(item_id, expected_action, expected_state): await client.send_json( @@ -1173,12 +1173,12 @@ async def test_breakpoints_2( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, prefix ) -> None: """Test execution resumes and breakpoints are removed after subscription removed.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_last_step(item_id, expected_action, expected_state): await client.send_json( @@ -1278,12 +1278,12 @@ async def test_breakpoints_3( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, prefix ) -> None: """Test breakpoints can be cleared.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id async def assert_last_step(item_id, expected_action, expected_state): await client.send_json( @@ -1434,12 +1434,12 @@ async def test_script_mode( script_execution, ) -> None: """Test overlapping runs with max_runs > 1.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id flag = asyncio.Event() @@ -1502,12 +1502,12 @@ async def test_script_mode_2( script_execution, ) -> None: """Test overlapping runs with max_runs > 1.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id flag = asyncio.Event() @@ -1577,12 +1577,12 @@ async def test_trace_blueprint_automation( ) -> None: """Test trace of blueprint automation.""" await async_setup_component(hass, "homeassistant", {}) - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id domain = "automation" sun_config = { diff --git a/tests/components/twinkly/test_init.py b/tests/components/twinkly/test_init.py index 794d4d5e773..6642807ac3f 100644 --- a/tests/components/twinkly/test_init.py +++ b/tests/components/twinkly/test_init.py @@ -17,16 +17,16 @@ async def test_load_unload_entry(hass: HomeAssistant) -> None: """Validate that setup entry also configure the client.""" client = ClientMock() - id = str(uuid4()) + device_id = str(uuid4()) config_entry = MockConfigEntry( domain=TWINKLY_DOMAIN, data={ CONF_HOST: TEST_HOST, - CONF_ID: id, + CONF_ID: device_id, CONF_NAME: TEST_NAME_ORIGINAL, CONF_MODEL: TEST_MODEL, }, - entry_id=id, + entry_id=device_id, ) config_entry.add_to_hass(hass) diff --git a/tests/components/vizio/conftest.py b/tests/components/vizio/conftest.py index 6ce36b38c8f..783ed8b4585 100644 --- a/tests/components/vizio/conftest.py +++ b/tests/components/vizio/conftest.py @@ -37,7 +37,7 @@ class MockInput: def get_mock_inputs(input_list): """Return list of MockInput.""" - return [MockInput(input) for input in input_list] + return [MockInput(device_input) for device_input in input_list] @pytest.fixture(name="vizio_get_unique_id", autouse=True) diff --git a/tests/components/zwave_js/test_diagnostics.py b/tests/components/zwave_js/test_diagnostics.py index 054906cd0f6..ea354ab80d3 100644 --- a/tests/components/zwave_js/test_diagnostics.py +++ b/tests/components/zwave_js/test_diagnostics.py @@ -128,7 +128,9 @@ async def test_device_diagnostics( ) assert diagnostics_data["state"] == { **multisensor_6.data, - "values": {id: val.data for id, val in multisensor_6.values.items()}, + "values": { + value_id: val.data for value_id, val in multisensor_6.values.items() + }, "endpoints": { str(idx): endpoint.data for idx, endpoint in multisensor_6.endpoints.items() }, diff --git a/tests/helpers/test_condition.py b/tests/helpers/test_condition.py index 701bc342760..20dea85c3e4 100644 --- a/tests/helpers/test_condition.py +++ b/tests/helpers/test_condition.py @@ -2178,12 +2178,12 @@ def _find_run_id(traces, trace_type, item_id): async def assert_automation_condition_trace(hass_ws_client, automation_id, expected): """Test the result of automation condition.""" - id = 1 + msg_id = 1 def next_id(): - nonlocal id - id += 1 - return id + nonlocal msg_id + msg_id += 1 + return msg_id client = await hass_ws_client() diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index fb2793a75c7..690592a850b 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -2330,30 +2330,30 @@ async def test_cached_entity_properties( async def test_cached_entity_property_delete_attr(hass: HomeAssistant) -> None: """Test deleting an _attr corresponding to a cached property.""" - property = "has_entity_name" + property_name = "has_entity_name" ent = entity.Entity() - assert not hasattr(ent, f"_attr_{property}") + assert not hasattr(ent, f"_attr_{property_name}") with pytest.raises(AttributeError): - delattr(ent, f"_attr_{property}") - assert getattr(ent, property) is False + delattr(ent, f"_attr_{property_name}") + assert getattr(ent, property_name) is False with pytest.raises(AttributeError): - delattr(ent, f"_attr_{property}") - assert not hasattr(ent, f"_attr_{property}") - assert getattr(ent, property) is False + delattr(ent, f"_attr_{property_name}") + assert not hasattr(ent, f"_attr_{property_name}") + assert getattr(ent, property_name) is False - setattr(ent, f"_attr_{property}", True) - assert getattr(ent, property) is True + setattr(ent, f"_attr_{property_name}", True) + assert getattr(ent, property_name) is True - delattr(ent, f"_attr_{property}") - assert not hasattr(ent, f"_attr_{property}") - assert getattr(ent, property) is False + delattr(ent, f"_attr_{property_name}") + assert not hasattr(ent, f"_attr_{property_name}") + assert getattr(ent, property_name) is False async def test_cached_entity_property_class_attribute(hass: HomeAssistant) -> None: """Test entity properties on class level work in derived classes.""" - property = "attribution" + property_name = "attribution" values = ["abcd", "efgh"] class EntityWithClassAttribute1(entity.Entity): @@ -2408,15 +2408,15 @@ async def test_cached_entity_property_class_attribute(hass: HomeAssistant) -> No ] for ent in entities: - assert getattr(ent[0], property) == values[0] - assert getattr(ent[1], property) == values[0] + assert getattr(ent[0], property_name) == values[0] + assert getattr(ent[1], property_name) == values[0] # Test update for ent in entities: - setattr(ent[0], f"_attr_{property}", values[1]) + setattr(ent[0], f"_attr_{property_name}", values[1]) for ent in entities: - assert getattr(ent[0], property) == values[1] - assert getattr(ent[1], property) == values[0] + assert getattr(ent[0], property_name) == values[1] + assert getattr(ent[1], property_name) == values[0] async def test_cached_entity_property_override(hass: HomeAssistant) -> None: diff --git a/tests/test_core.py b/tests/test_core.py index ce71fcd42e5..30665619fcd 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1148,11 +1148,11 @@ async def test_eventbus_filtered_listener(hass: HomeAssistant) -> None: calls.append(event) @ha.callback - def filter(event_data): + def mock_filter(event_data): """Mock filter.""" return not event_data["filtered"] - unsub = hass.bus.async_listen("test", listener, event_filter=filter) + unsub = hass.bus.async_listen("test", listener, event_filter=mock_filter) hass.bus.async_fire("test", {"filtered": True}) await hass.async_block_till_done() @@ -3274,11 +3274,11 @@ async def test_eventbus_lazy_object_creation(hass: HomeAssistant) -> None: calls.append(event) @ha.callback - def filter(event_data): + def mock_filter(event_data): """Mock filter.""" return not event_data["filtered"] - unsub = hass.bus.async_listen("test_1", listener, event_filter=filter) + unsub = hass.bus.async_listen("test_1", listener, event_filter=mock_filter) # Test lazy creation of Event objects with patch("homeassistant.core.Event") as mock_event: @@ -3343,7 +3343,7 @@ async def test_statemachine_report_state(hass: HomeAssistant) -> None: """Test report state event.""" @ha.callback - def filter(event_data): + def mock_filter(event_data): """Mock filter.""" return True @@ -3354,7 +3354,7 @@ async def test_statemachine_report_state(hass: HomeAssistant) -> None: hass.states.async_set("light.bowl", "on", {}) state_changed_events = async_capture_events(hass, EVENT_STATE_CHANGED) state_reported_events = [] - hass.bus.async_listen(EVENT_STATE_REPORTED, listener, event_filter=filter) + hass.bus.async_listen(EVENT_STATE_REPORTED, listener, event_filter=mock_filter) hass.states.async_set("light.bowl", "on") await hass.async_block_till_done() @@ -3385,7 +3385,7 @@ async def test_report_state_listener_restrictions(hass: HomeAssistant) -> None: """Mock listener.""" @ha.callback - def filter(event_data): + def mock_filter(event_data): """Mock filter.""" return False @@ -3394,7 +3394,7 @@ async def test_report_state_listener_restrictions(hass: HomeAssistant) -> None: hass.bus.async_listen(EVENT_STATE_REPORTED, listener) # Both filter and run_immediately - hass.bus.async_listen(EVENT_STATE_REPORTED, listener, event_filter=filter) + hass.bus.async_listen(EVENT_STATE_REPORTED, listener, event_filter=mock_filter) @pytest.mark.parametrize( diff --git a/tests/util/test_percentage.py b/tests/util/test_percentage.py index 2fc054fb4f1..3af42310e94 100644 --- a/tests/util/test_percentage.py +++ b/tests/util/test_percentage.py @@ -104,77 +104,77 @@ async def test_percentage_to_ordered_list_item() -> None: async def test_ranged_value_to_percentage_large() -> None: """Test a large range of low and high values convert a single value to a percentage.""" - range = (1, 255) + value_range = (1, 255) - assert ranged_value_to_percentage(range, 255) == 100 - assert ranged_value_to_percentage(range, 127) == 49 - assert ranged_value_to_percentage(range, 10) == 3 - assert ranged_value_to_percentage(range, 1) == 0 + assert ranged_value_to_percentage(value_range, 255) == 100 + assert ranged_value_to_percentage(value_range, 127) == 49 + assert ranged_value_to_percentage(value_range, 10) == 3 + assert ranged_value_to_percentage(value_range, 1) == 0 async def test_percentage_to_ranged_value_large() -> None: """Test a large range of low and high values convert a percentage to a single value.""" - range = (1, 255) + value_range = (1, 255) - assert percentage_to_ranged_value(range, 100) == 255 - assert percentage_to_ranged_value(range, 50) == 127.5 - assert percentage_to_ranged_value(range, 4) == 10.2 + assert percentage_to_ranged_value(value_range, 100) == 255 + assert percentage_to_ranged_value(value_range, 50) == 127.5 + assert percentage_to_ranged_value(value_range, 4) == 10.2 - assert math.ceil(percentage_to_ranged_value(range, 100)) == 255 - assert math.ceil(percentage_to_ranged_value(range, 50)) == 128 - assert math.ceil(percentage_to_ranged_value(range, 4)) == 11 + assert math.ceil(percentage_to_ranged_value(value_range, 100)) == 255 + assert math.ceil(percentage_to_ranged_value(value_range, 50)) == 128 + assert math.ceil(percentage_to_ranged_value(value_range, 4)) == 11 async def test_ranged_value_to_percentage_small() -> None: """Test a small range of low and high values convert a single value to a percentage.""" - range = (1, 6) + value_range = (1, 6) - assert ranged_value_to_percentage(range, 1) == 16 - assert ranged_value_to_percentage(range, 2) == 33 - assert ranged_value_to_percentage(range, 3) == 50 - assert ranged_value_to_percentage(range, 4) == 66 - assert ranged_value_to_percentage(range, 5) == 83 - assert ranged_value_to_percentage(range, 6) == 100 + assert ranged_value_to_percentage(value_range, 1) == 16 + assert ranged_value_to_percentage(value_range, 2) == 33 + assert ranged_value_to_percentage(value_range, 3) == 50 + assert ranged_value_to_percentage(value_range, 4) == 66 + assert ranged_value_to_percentage(value_range, 5) == 83 + assert ranged_value_to_percentage(value_range, 6) == 100 async def test_percentage_to_ranged_value_small() -> None: """Test a small range of low and high values convert a percentage to a single value.""" - range = (1, 6) + value_range = (1, 6) - assert math.ceil(percentage_to_ranged_value(range, 16)) == 1 - assert math.ceil(percentage_to_ranged_value(range, 33)) == 2 - assert math.ceil(percentage_to_ranged_value(range, 50)) == 3 - assert math.ceil(percentage_to_ranged_value(range, 66)) == 4 - assert math.ceil(percentage_to_ranged_value(range, 83)) == 5 - assert math.ceil(percentage_to_ranged_value(range, 100)) == 6 + assert math.ceil(percentage_to_ranged_value(value_range, 16)) == 1 + assert math.ceil(percentage_to_ranged_value(value_range, 33)) == 2 + assert math.ceil(percentage_to_ranged_value(value_range, 50)) == 3 + assert math.ceil(percentage_to_ranged_value(value_range, 66)) == 4 + assert math.ceil(percentage_to_ranged_value(value_range, 83)) == 5 + assert math.ceil(percentage_to_ranged_value(value_range, 100)) == 6 async def test_ranged_value_to_percentage_starting_at_one() -> None: """Test a range that starts with 1.""" - range = (1, 4) + value_range = (1, 4) - assert ranged_value_to_percentage(range, 1) == 25 - assert ranged_value_to_percentage(range, 2) == 50 - assert ranged_value_to_percentage(range, 3) == 75 - assert ranged_value_to_percentage(range, 4) == 100 + assert ranged_value_to_percentage(value_range, 1) == 25 + assert ranged_value_to_percentage(value_range, 2) == 50 + assert ranged_value_to_percentage(value_range, 3) == 75 + assert ranged_value_to_percentage(value_range, 4) == 100 async def test_ranged_value_to_percentage_starting_high() -> None: """Test a range that does not start with 1.""" - range = (101, 255) + value_range = (101, 255) - assert ranged_value_to_percentage(range, 101) == 0 - assert ranged_value_to_percentage(range, 139) == 25 - assert ranged_value_to_percentage(range, 178) == 50 - assert ranged_value_to_percentage(range, 217) == 75 - assert ranged_value_to_percentage(range, 255) == 100 + assert ranged_value_to_percentage(value_range, 101) == 0 + assert ranged_value_to_percentage(value_range, 139) == 25 + assert ranged_value_to_percentage(value_range, 178) == 50 + assert ranged_value_to_percentage(value_range, 217) == 75 + assert ranged_value_to_percentage(value_range, 255) == 100 async def test_ranged_value_to_percentage_starting_zero() -> None: """Test a range that starts with 0.""" - range = (0, 3) + value_range = (0, 3) - assert ranged_value_to_percentage(range, 0) == 25 - assert ranged_value_to_percentage(range, 1) == 50 - assert ranged_value_to_percentage(range, 2) == 75 - assert ranged_value_to_percentage(range, 3) == 100 + assert ranged_value_to_percentage(value_range, 0) == 25 + assert ranged_value_to_percentage(value_range, 1) == 50 + assert ranged_value_to_percentage(value_range, 2) == 75 + assert ranged_value_to_percentage(value_range, 3) == 100 diff --git a/tests/util/yaml/test_init.py b/tests/util/yaml/test_init.py index 113a348c1d1..f17489e1488 100644 --- a/tests/util/yaml/test_init.py +++ b/tests/util/yaml/test_init.py @@ -568,13 +568,13 @@ def test_no_recursive_secrets( def test_input_class() -> None: """Test input class.""" - input = yaml_loader.Input("hello") - input2 = yaml_loader.Input("hello") + yaml_input = yaml_loader.Input("hello") + yaml_input2 = yaml_loader.Input("hello") - assert input.name == "hello" - assert input == input2 + assert yaml_input.name == "hello" + assert yaml_input == yaml_input2 - assert len({input, input2}) == 1 + assert len({yaml_input, yaml_input2}) == 1 def test_input(try_both_loaders, try_both_dumpers) -> None: