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