diff --git a/homeassistant/components/nest/legacy/sensor.py b/homeassistant/components/nest/legacy/sensor.py index e4061df1a75..3c397f3d1f4 100644 --- a/homeassistant/components/nest/legacy/sensor.py +++ b/homeassistant/components/nest/legacy/sensor.py @@ -139,7 +139,7 @@ async def async_setup_legacy_entry( ] structures_has_camera = {} - for structure, device in nest.cameras(): + for structure, _ in nest.cameras(): structures_has_camera[structure] = True for structure in structures_has_camera: all_sensors += [ diff --git a/homeassistant/components/spotify/browse_media.py b/homeassistant/components/spotify/browse_media.py index 98eac019bac..e6a1f16eede 100644 --- a/homeassistant/components/spotify/browse_media.py +++ b/homeassistant/components/spotify/browse_media.py @@ -140,7 +140,7 @@ async def async_browse_media( # Check if caller is requesting the root nodes if media_content_type is None and media_content_id is None: children = [] - for config_entry_id, info in hass.data[DOMAIN].items(): + for config_entry_id in hass.data[DOMAIN]: config_entry = hass.config_entries.async_get_entry(config_entry_id) assert config_entry is not None children.append( diff --git a/pyproject.toml b/pyproject.toml index 64b22222086..6b3904522a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -240,6 +240,7 @@ filterwarnings = ["error::sqlalchemy.exc.SAWarning"] target-version = "py310" select = [ + "B007", # Loop control variable {name} not used within loop body "C", # complexity "D", # docstrings "E", # pycodestyle diff --git a/tests/components/group/test_recorder.py b/tests/components/group/test_recorder.py index cf471ec73be..2831c82b31e 100644 --- a/tests/components/group/test_recorder.py +++ b/tests/components/group/test_recorder.py @@ -46,9 +46,7 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant) attr_ids[ db_state_attributes.attributes_id ] = db_state_attributes.to_native() - for db_state, db_state_attributes in session.query( - States, StateAttributes - ).outerjoin( + for db_state, _ in session.query(States, StateAttributes).outerjoin( StateAttributes, States.attributes_id == StateAttributes.attributes_id ): state = db_state.to_native() diff --git a/tests/components/hue/test_migration.py b/tests/components/hue/test_migration.py index 9102a662925..b03834c3249 100644 --- a/tests/components/hue/test_migration.py +++ b/tests/components/hue/test_migration.py @@ -111,7 +111,7 @@ async def test_sensor_entity_migration( } # create entities with V1 schema in registry for Hue motion sensor - for dev_class, platform, new_id in sensor_mappings: + for dev_class, platform, _ in sensor_mappings: ent_reg.async_get_or_create( platform, hue.DOMAIN, diff --git a/tests/components/modbus/test_init.py b/tests/components/modbus/test_init.py index 90fc0c086e8..d9d2e0055fe 100644 --- a/tests/components/modbus/test_init.py +++ b/tests/components/modbus/test_init.py @@ -888,7 +888,7 @@ async def test_integration_reload( with mock.patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path): await hass.services.async_call(DOMAIN, SERVICE_RELOAD, blocking=True) await hass.async_block_till_done() - for i in range(4): + for _ in range(4): freezer.tick(timedelta(seconds=1)) async_fire_time_changed(hass) await hass.async_block_till_done() diff --git a/tests/components/sensor/test_recorder.py b/tests/components/sensor/test_recorder.py index 4bad0fdda37..add7bc5e016 100644 --- a/tests/components/sensor/test_recorder.py +++ b/tests/components/sensor/test_recorder.py @@ -3278,7 +3278,7 @@ def test_compile_statistics_hourly_daily_monthly_summary( # Generate 5-minute statistics for two hours start = zero - for i in range(24): + for _ in range(24): do_adhoc_statistics(hass, start=start) wait_recording_done(hass) start += timedelta(minutes=5) diff --git a/tests/components/surepetcare/test_lock.py b/tests/components/surepetcare/test_lock.py index 2276bae4200..19e27bbe9a5 100644 --- a/tests/components/surepetcare/test_lock.py +++ b/tests/components/surepetcare/test_lock.py @@ -87,7 +87,7 @@ async def test_lock_failing(hass: HomeAssistant, surepetcare) -> None: surepetcare.lock_out.side_effect = SurePetcareError surepetcare.lock.side_effect = SurePetcareError - for entity_id, unique_id in EXPECTED_ENTITY_IDS.items(): + for entity_id in EXPECTED_ENTITY_IDS: with pytest.raises(SurePetcareError): await hass.services.async_call( "lock", "lock", {"entity_id": entity_id}, blocking=True diff --git a/tests/components/zha/test_diagnostics.py b/tests/components/zha/test_diagnostics.py index e04e0aaf157..61f855af9af 100644 --- a/tests/components/zha/test_diagnostics.py +++ b/tests/components/zha/test_diagnostics.py @@ -89,7 +89,7 @@ async def test_diagnostics_for_device( ) assert diagnostics_data device_info: dict = zha_device.zha_device_info - for key, value in device_info.items(): + for key in device_info: assert key in diagnostics_data if key not in KEYS_TO_REDACT: assert key in diagnostics_data diff --git a/tests/components/zwave_js/test_migrate.py b/tests/components/zwave_js/test_migrate.py index f110f62a629..849759cc833 100644 --- a/tests/components/zwave_js/test_migrate.py +++ b/tests/components/zwave_js/test_migrate.py @@ -226,7 +226,7 @@ async def test_old_entity_migration( assert entity_entry.unique_id == old_unique_id # Do this twice to make sure re-interview doesn't do anything weird - for i in range(0, 2): + for _ in range(2): # Add a ready node, unique ID should be migrated event = {"node": node} driver.controller.emit("node added", event) @@ -274,7 +274,7 @@ async def test_different_endpoint_migration_status_sensor( assert entity_entry.unique_id == old_unique_id # Do this twice to make sure re-interview doesn't do anything weird - for i in range(0, 2): + for _ in range(0, 2): # Add a ready node, unique ID should be migrated event = {"node": node} driver.controller.emit("node added", event) diff --git a/tests/helpers/test_entity_platform.py b/tests/helpers/test_entity_platform.py index aa2467df213..26e948fc5d2 100644 --- a/tests/helpers/test_entity_platform.py +++ b/tests/helpers/test_entity_platform.py @@ -437,7 +437,7 @@ async def test_async_remove_with_platform_update_finishes(hass: HomeAssistant) - # Add, remove, add, remove and make sure no updates # cause the entity to reappear after removal - for i in range(2): + for _ in range(2): await component.async_add_entities([entity1]) assert len(hass.states.async_entity_ids()) == 1 entity1.async_write_ha_state() diff --git a/tests/util/test_dt.py b/tests/util/test_dt.py index 76f9a52f25e..1f4758a75d8 100644 --- a/tests/util/test_dt.py +++ b/tests/util/test_dt.py @@ -724,7 +724,7 @@ def test_find_next_time_expression_tenth_second_pattern_does_not_drift_entering_ ) assert next_time == datetime(2021, 3, 15, 2, 30, 10, tzinfo=tz) prev_target = next_time - for i in range(1000): + for _ in range(1000): next_target = dt_util.find_next_time_expression_time( prev_target.replace(microsecond=999999) + timedelta(seconds=1), matching_seconds,