Skip to content

Commit 1eb7bb1

Browse files
committed
fix(search): retain group signal in domain grouping
1 parent e1f49a3 commit 1eb7bb1

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/ha_mcp/tools/tools_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ def _build_domain_only_by_domain(
13891389
"""Build the by_domain dict for domain-listing mode (all results are one domain)."""
13901390
items = results[:per_domain_limit] if per_domain_limit is not None else results
13911391
if parsed_result_fields is not None:
1392-
items = _project_records(items, parsed_result_fields)
1392+
items = _project_records(items, _effective_result_fields(parsed_result_fields))
13931393
return {domain: items}
13941394

13951395

tests/src/unit/test_search_fields_projection.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,26 @@ async def test_per_domain_limit_domain_listing_branch(self, search_tool):
621621
assert "light" in by_domain
622622
assert len(by_domain["light"]) <= 1
623623

624+
@pytest.mark.asyncio
625+
async def test_domain_listing_member_only_projection_keeps_group_signal(
626+
self, search_tool
627+
):
628+
"""Member-only domain grouping retains the group discriminator."""
629+
result = await search_tool(
630+
domain_filter="light",
631+
group_by_domain=True,
632+
result_fields=["member_entity_ids"],
633+
limit=20,
634+
)
635+
636+
expected_group = {
637+
"is_group": True,
638+
"member_entity_ids": ["light.member_one", "light.member_two"],
639+
}
640+
assert expected_group in result["entities"]
641+
assert expected_group in result["by_domain"]["light"]
642+
assert {"is_group": False} in result["by_domain"]["light"]
643+
624644

625645
class TestHaSearchEntitiesStateFilter(_SearchToolFixture):
626646
"""Tests for state_filter= normalization and per-branch behavior (issue #1199)."""

0 commit comments

Comments
 (0)