Skip to content

Commit b3cc759

Browse files
committed
fix: correct test result parsing and get_config_entry implementation
1 parent 76c3cba commit b3cc759

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/ha_mcp/client/rest_client.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ async def get_config_entry(self, entry_id: str) -> dict[str, Any]:
633633
"""
634634
Get config entry details.
635635
636+
Note: Home Assistant doesn't have a direct REST API endpoint for individual
637+
config entries. This method lists all entries and filters by entry_id.
638+
636639
Args:
637640
entry_id: Config entry ID
638641
@@ -643,7 +646,23 @@ async def get_config_entry(self, entry_id: str) -> dict[str, Any]:
643646
HomeAssistantAPIError: If entry not found or API error
644647
"""
645648
logger.debug(f"Getting config entry: {entry_id}")
646-
return await self._request("GET", f"/config/config_entries/entry/{entry_id}")
649+
# List all entries and filter by entry_id
650+
entries = await self._request("GET", "/config/config_entries/entry")
651+
652+
if not isinstance(entries, list):
653+
raise HomeAssistantAPIError(
654+
"Unexpected response format from config entries API",
655+
status_code=500,
656+
)
657+
658+
for entry in entries:
659+
if entry.get("entry_id") == entry_id:
660+
return entry
661+
662+
raise HomeAssistantAPIError(
663+
f"Config entry not found: {entry_id}",
664+
status_code=404,
665+
)
647666

648667
async def send_websocket_message(self, message: dict[str, Any]) -> dict[str, Any]:
649668
"""Send message via WebSocket and wait for response.

tests/src/e2e/workflows/entities/test_entity_management.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ async def test_set_entity_enabled_string_bool(self, mcp_client, cleanup_tracker)
8989

9090
async def test_set_entity_enabled_nonexistent(self, mcp_client):
9191
"""Test error handling for non-existent entity."""
92+
from tests.src.e2e.utilities.assertions import parse_mcp_result
93+
9294
result = await mcp_client.call_tool(
9395
"ha_set_entity_enabled",
9496
{"entity_id": "sensor.nonexistent_entity", "enabled": True},
9597
)
9698
# Should fail - either through validation or API error
97-
assert not result.get("success", False)
99+
data = parse_mcp_result(result)
100+
assert not data.get("success", False)

tests/src/e2e/workflows/integrations/test_integration_management.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ async def test_delete_config_entry_string_confirm(self, mcp_client):
116116

117117
async def test_set_integration_enabled_nonexistent(self, mcp_client):
118118
"""Test error handling for non-existent integration."""
119+
from tests.src.e2e.utilities.assertions import parse_mcp_result
120+
119121
result = await mcp_client.call_tool(
120122
"ha_set_integration_enabled",
121123
{"entry_id": "nonexistent_entry_id", "enabled": True},
122124
)
123125
# Should fail - either through validation or API error
124-
assert not result.get("success", False)
126+
data = parse_mcp_result(result)
127+
assert not data.get("success", False)

0 commit comments

Comments
 (0)