Improve automation reload (#81854)
* Improve automation reload * Small tweak * Improve
This commit is contained in:
parent
ee9231363f
commit
9bd676aff6
2 changed files with 61 additions and 3 deletions
|
@ -817,9 +817,28 @@ async def _async_process_config(
|
|||
"""
|
||||
automation_matches: set[int] = set()
|
||||
config_matches: set[int] = set()
|
||||
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)
|
||||
continue
|
||||
automation_configs_without_id.append((config_idx, config))
|
||||
|
||||
for automation_idx, automation in enumerate(automations):
|
||||
for config_idx, config in enumerate(automation_configs):
|
||||
if automation.unique_id:
|
||||
if automation.unique_id not in automation_configs_with_id:
|
||||
continue
|
||||
config_idx, config = automation_configs_with_id.pop(
|
||||
automation.unique_id
|
||||
)
|
||||
if automation_matches_config(automation, config):
|
||||
automation_matches.add(automation_idx)
|
||||
config_matches.add(config_idx)
|
||||
continue
|
||||
|
||||
for config_idx, config in automation_configs_without_id:
|
||||
if config_idx in config_matches:
|
||||
# Only allow an automation config to match at most once
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue