diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 5a53179cf2c..f2ef404ab34 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -1048,29 +1048,32 @@ async def _async_process_config( automation_configs_with_id: dict[str, tuple[int, AutomationEntityConfig]] = {} automation_configs_without_id: list[tuple[int, AutomationEntityConfig]] = [] - for config_idx, config in enumerate(automation_configs): - if automation_id := config.config_block.get(CONF_ID): - automation_configs_with_id[automation_id] = (config_idx, config) + for config_idx, automation_config in enumerate(automation_configs): + if automation_id := automation_config.config_block.get(CONF_ID): + automation_configs_with_id[automation_id] = ( + config_idx, + automation_config, + ) continue - automation_configs_without_id.append((config_idx, config)) + automation_configs_without_id.append((config_idx, automation_config)) for automation_idx, automation in enumerate(automations): if automation.unique_id: if automation.unique_id not in automation_configs_with_id: continue - config_idx, config = automation_configs_with_id.pop( + config_idx, automation_config = automation_configs_with_id.pop( automation.unique_id ) - if automation_matches_config(automation, config): + if automation_matches_config(automation, automation_config): automation_matches.add(automation_idx) config_matches.add(config_idx) continue - for config_idx, config in automation_configs_without_id: + for config_idx, automation_config in automation_configs_without_id: if config_idx in config_matches: # Only allow an automation config to match at most once continue - if automation_matches_config(automation, config): + if automation_matches_config(automation, automation_config): automation_matches.add(automation_idx) config_matches.add(config_idx) # Only allow an automation to match at most once diff --git a/homeassistant/components/elkm1/discovery.py b/homeassistant/components/elkm1/discovery.py index 8a68b6524b7..916e8a8aeac 100644 --- a/homeassistant/components/elkm1/discovery.py +++ b/homeassistant/components/elkm1/discovery.py @@ -46,8 +46,10 @@ async def async_discover_devices( targets = [address] else: targets = [ - str(address) - for address in await network.async_get_ipv4_broadcast_addresses(hass) + str(broadcast_address) + for broadcast_address in await network.async_get_ipv4_broadcast_addresses( + hass + ) ] scanner = AIOELKDiscovery() @@ -55,8 +57,8 @@ async def async_discover_devices( for idx, discovered in enumerate( await asyncio.gather( *[ - scanner.async_scan(timeout=timeout, address=address) - for address in targets + scanner.async_scan(timeout=timeout, address=target_address) + for target_address in targets ], return_exceptions=True, ) diff --git a/homeassistant/components/flux_led/discovery.py b/homeassistant/components/flux_led/discovery.py index 9600f773701..d55f560193f 100644 --- a/homeassistant/components/flux_led/discovery.py +++ b/homeassistant/components/flux_led/discovery.py @@ -178,16 +178,20 @@ async def async_discover_devices( targets = [address] else: targets = [ - str(address) - for address in await network.async_get_ipv4_broadcast_addresses(hass) + str(broadcast_address) + for broadcast_address in await network.async_get_ipv4_broadcast_addresses( + hass + ) ] scanner = AIOBulbScanner() for idx, discovered in enumerate( await asyncio.gather( *[ - create_eager_task(scanner.async_scan(timeout=timeout, address=address)) - for address in targets + create_eager_task( + scanner.async_scan(timeout=timeout, address=target_address) + ) + for target_address in targets ], return_exceptions=True, ) diff --git a/homeassistant/components/habitica/__init__.py b/homeassistant/components/habitica/__init__.py index e8c0af8f97f..b50e5855f00 100644 --- a/homeassistant/components/habitica/__init__.py +++ b/homeassistant/components/habitica/__init__.py @@ -110,7 +110,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -async def async_setup_entry(hass: HomeAssistant, entry: HabiticaConfigEntry) -> bool: +async def async_setup_entry( + hass: HomeAssistant, config_entry: HabiticaConfigEntry +) -> bool: """Set up habitica from a config entry.""" class HAHabitipyAsync(HabitipyAsync): @@ -147,9 +149,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: HabiticaConfigEntry) -> websession = async_get_clientsession(hass) - url = entry.data[CONF_URL] - username = entry.data[CONF_API_USER] - password = entry.data[CONF_API_KEY] + url = config_entry.data[CONF_URL] + username = config_entry.data[CONF_API_USER] + password = config_entry.data[CONF_API_KEY] api = await hass.async_add_executor_job( HAHabitipyAsync, @@ -169,18 +171,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: HabiticaConfigEntry) -> ) from e raise ConfigEntryNotReady(e) from e - if not entry.data.get(CONF_NAME): + if not config_entry.data.get(CONF_NAME): name = user["profile"]["name"] hass.config_entries.async_update_entry( - entry, - data={**entry.data, CONF_NAME: name}, + config_entry, + data={**config_entry.data, CONF_NAME: name}, ) coordinator = HabiticaDataUpdateCoordinator(hass, api) await coordinator.async_config_entry_first_refresh() - entry.runtime_data = coordinator - await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + config_entry.runtime_data = coordinator + await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS) if not hass.services.has_service(DOMAIN, SERVICE_API_CALL): hass.services.async_register( diff --git a/homeassistant/components/hardware/websocket_api.py b/homeassistant/components/hardware/websocket_api.py index 694c6e782e1..dfbcfd4c4ac 100644 --- a/homeassistant/components/hardware/websocket_api.py +++ b/homeassistant/components/hardware/websocket_api.py @@ -99,8 +99,8 @@ def ws_subscribe_system_status( "memory_free_mb": round(virtual_memory.available / 1024**2, 1), "timestamp": dt_util.utcnow().isoformat(), } - for connection, msg_id in system_status.subscribers: - connection.send_message(websocket_api.event_message(msg_id, json_msg)) + for conn, msg_id in system_status.subscribers: + conn.send_message(websocket_api.event_message(msg_id, json_msg)) if not system_status.subscribers: system_status.remove_periodic_timer = async_track_time_interval( diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index f19a48fea33..2b9f87f368b 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -369,11 +369,11 @@ async def _async_process_config( config_matches: set[int] = set() for script_idx, script in enumerate(scripts): - for config_idx, config in enumerate(script_configs): + for config_idx, script_config in enumerate(script_configs): if config_idx in config_matches: # Only allow a script config to match at most once continue - if script_matches_config(script, config): + if script_matches_config(script, script_config): script_matches.add(script_idx) config_matches.add(config_idx) # Only allow a script to match at most once diff --git a/homeassistant/components/steamist/discovery.py b/homeassistant/components/steamist/discovery.py index 5c3262ce4eb..2abe2343f99 100644 --- a/homeassistant/components/steamist/discovery.py +++ b/homeassistant/components/steamist/discovery.py @@ -62,16 +62,18 @@ async def async_discover_devices( targets = [address] else: targets = [ - str(address) - for address in await network.async_get_ipv4_broadcast_addresses(hass) + str(broadcast_address) + for broadcast_address in await network.async_get_ipv4_broadcast_addresses( + hass + ) ] scanner = AIODiscovery30303() for idx, discovered in enumerate( await asyncio.gather( *[ - scanner.async_scan(timeout=timeout, address=address) - for address in targets + scanner.async_scan(timeout=timeout, address=target_address) + for target_address in targets ], return_exceptions=True, ) diff --git a/homeassistant/components/unifi/hub/entity_helper.py b/homeassistant/components/unifi/hub/entity_helper.py index c4bcf237386..782b026d6e4 100644 --- a/homeassistant/components/unifi/hub/entity_helper.py +++ b/homeassistant/components/unifi/hub/entity_helper.py @@ -146,8 +146,8 @@ class UnifiDeviceCommand: """Execute previously queued commands.""" queue = self._command_queue.copy() self._command_queue.clear() - for device_id, device_commands in queue.items(): - device = self.api.devices[device_id] + for dev_id, device_commands in queue.items(): + device = self.api.devices[dev_id] commands = list(device_commands.items()) await self.api.request( DeviceSetPoePortModeRequest.create(device, targets=commands) diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index 479b7f02024..d47444e3994 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -89,9 +89,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return True def check_entry_id(interface: str) -> str: - for entry in hass.config_entries.async_entries(DOMAIN): - if "port" in entry.data and entry.data["port"] == interface: - return entry.entry_id + for config_entry in hass.config_entries.async_entries(DOMAIN): + if "port" in config_entry.data and config_entry.data["port"] == interface: + return config_entry.entry_id raise vol.Invalid( "The interface provided is not defined as a port in a Velbus integration" ) diff --git a/homeassistant/helpers/collection.py b/homeassistant/helpers/collection.py index 036aaacf0e9..9151a9dfc6b 100644 --- a/homeassistant/helpers/collection.py +++ b/homeassistant/helpers/collection.py @@ -642,8 +642,8 @@ class StorageCollectionWebsocket[_StorageCollectionT: StorageCollection]: } for change in change_set ] - for connection, msg_id in self._subscribers: - connection.send_message(websocket_api.event_message(msg_id, json_msg)) + for conn, msg_id in self._subscribers: + conn.send_message(websocket_api.event_message(msg_id, json_msg)) if not self._subscribers: self._remove_subscription = ( diff --git a/tests/components/bluetooth/test_passive_update_processor.py b/tests/components/bluetooth/test_passive_update_processor.py index 8e1163c0bdb..079ac2200fc 100644 --- a/tests/components/bluetooth/test_passive_update_processor.py +++ b/tests/components/bluetooth/test_passive_update_processor.py @@ -1653,12 +1653,12 @@ async def test_integration_multiple_entity_platforms_with_reload_and_restart( unregister_binary_sensor_processor() unregister_sensor_processor() - async with async_test_home_assistant() as hass: - await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) + async with async_test_home_assistant() as test_hass: + await async_setup_component(test_hass, DOMAIN, {DOMAIN: {}}) current_entry.set(entry) coordinator = PassiveBluetoothProcessorCoordinator( - hass, + test_hass, _LOGGER, "aa:bb:cc:dd:ee:ff", BluetoothScanningMode.ACTIVE, @@ -1706,7 +1706,7 @@ async def test_integration_multiple_entity_platforms_with_reload_and_restart( ] sensor_entity_one: PassiveBluetoothProcessorEntity = sensor_entities[0] - sensor_entity_one.hass = hass + sensor_entity_one.hass = test_hass assert sensor_entity_one.available is False # service data not injected assert sensor_entity_one.unique_id == "aa:bb:cc:dd:ee:ff-pressure" assert sensor_entity_one.device_info == { @@ -1723,7 +1723,7 @@ async def test_integration_multiple_entity_platforms_with_reload_and_restart( binary_sensor_entity_one: PassiveBluetoothProcessorEntity = ( binary_sensor_entities[0] ) - binary_sensor_entity_one.hass = hass + binary_sensor_entity_one.hass = test_hass assert binary_sensor_entity_one.available is False # service data not injected assert binary_sensor_entity_one.unique_id == "aa:bb:cc:dd:ee:ff-motion" assert binary_sensor_entity_one.device_info == { @@ -1739,7 +1739,7 @@ async def test_integration_multiple_entity_platforms_with_reload_and_restart( cancel_coordinator() unregister_binary_sensor_processor() unregister_sensor_processor() - await hass.async_stop() + await test_hass.async_stop() NAMING_PASSIVE_BLUETOOTH_DATA_UPDATE = PassiveBluetoothDataUpdate(