Fix ruff redefined-argument-from-local PLR1704 (#120729)

* Fix PLR1704

* Fix
This commit is contained in:
Joost Lekkerkerker 2024-06-28 12:31:07 +02:00 committed by GitHub
parent 4437c4a204
commit 6ef8e87f88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 59 additions and 46 deletions

View file

@ -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

View file

@ -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,
)

View file

@ -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,
)

View file

@ -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(

View file

@ -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(

View file

@ -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

View file

@ -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,
)

View file

@ -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)

View file

@ -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"
)

View file

@ -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 = (

View file

@ -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(