Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions automation_inspector/app/dependency_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ def build_inspection(snapshot: SourceSnapshot, settings: Settings) -> dict[str,
)
if file_automation:
matched_file_keys.add(file_automation.key)
if config_id:
for candidate in file_by_id.get(config_id, []):
if candidate.config == file_automation.config:
matched_file_keys.add(candidate.key)
if not settings.include_disabled and state.get("state") != "on":
continue

Expand Down
63 changes: 63 additions & 0 deletions tests/test_dependency_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,69 @@ def test_duplicate_file_id_and_registry_only_helper_remain_visible() -> None:
]


def test_identical_file_duplicates_matching_loaded_automation_do_not_create_unloaded_rows() -> None:
config = {
"id": "duplicate",
"alias": "Loaded copy",
"triggers": [],
"actions": [],
}
snapshot = SourceSnapshot(
states=[
{
"entity_id": "automation.loaded_copy",
"state": "on",
"attributes": {"id": "duplicate"},
}
],
home_assistant_config={"version": "2026.7.2"},
automation_configs={"automation.loaded_copy": config},
file_automations=[
FileAutomation(0, "duplicate", config),
FileAutomation(1, "duplicate", dict(config)),
FileAutomation(2, "duplicate", dict(config)),
],
)

report = build_inspection(snapshot, Settings())

assert report["summary"]["automations"] == 1
assert report["summary"]["unloaded"] == 0
assert list(report["automations"]) == ["automation.loaded_copy"]


def test_duplicate_file_entries_collapse_even_when_runtime_config_differs() -> None:
file_config = {
"id": "duplicate",
"alias": "Loaded copy",
"triggers": [],
"actions": [],
}
runtime_config = dict(file_config) | {"mode": "single"}
snapshot = SourceSnapshot(
states=[
{
"entity_id": "automation.loaded_copy",
"state": "on",
"attributes": {"id": "duplicate"},
}
],
home_assistant_config={"version": "2026.7.2"},
automation_configs={"automation.loaded_copy": runtime_config},
file_automations=[
FileAutomation(0, "duplicate", dict(file_config)),
FileAutomation(1, "duplicate", dict(file_config)),
FileAutomation(2, "duplicate", dict(file_config)),
],
)

report = build_inspection(snapshot, Settings())

assert report["summary"]["automations"] == 1
assert report["summary"]["unloaded"] == 0
assert list(report["automations"]) == ["automation.loaded_copy"]


def test_build_inspection_includes_loaded_scripts() -> None:
script_config = {
"alias": "Night lights",
Expand Down