Skip to content

Commit 881ca6f

Browse files
authored
feat(debug): add verbose logging and connection test for add-on (#421)
1 parent 2929f40 commit 881ca6f

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

homeassistant-addon/start.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,45 @@ def main() -> int:
111111
log_info(f"Home Assistant URL: {os.environ['HOMEASSISTANT_URL']}")
112112
log_info("Authentication configured via Supervisor token")
113113

114+
# Debug: Test Supervisor API connectivity
115+
try:
116+
import asyncio
117+
118+
import httpx
119+
120+
async def debug_supervisor() -> None:
121+
url = os.environ["HOMEASSISTANT_URL"]
122+
token = os.environ["HOMEASSISTANT_TOKEN"]
123+
log_info(f"DEBUG: Testing Supervisor API at {url}")
124+
125+
async with httpx.AsyncClient(
126+
headers={"Authorization": f"Bearer {token}"}
127+
) as client:
128+
# Test 1: GET / (Core root via proxy)
129+
# Note: http://supervisor/core might redirect or return 404/401 depending on path
130+
try:
131+
target = f"{url}/api/"
132+
resp = await client.get(target)
133+
log_info(f"DEBUG: GET {target} -> {resp.status_code}")
134+
except Exception as e:
135+
log_error(f"DEBUG: GET {target} failed: {e}")
136+
137+
# Test 2: DELETE /api/config/automation/config/test_delete_debug
138+
# This mimics the failing call
139+
target = f"{url}/api/config/automation/config/test_delete_debug"
140+
log_info(f"DEBUG: Attempting DELETE {target}")
141+
try:
142+
resp = await client.delete(target)
143+
log_info(
144+
f"DEBUG: DELETE result -> {resp.status_code} {resp.text[:200]}"
145+
)
146+
except Exception as e:
147+
log_error(f"DEBUG: DELETE failed: {e}")
148+
149+
asyncio.run(debug_supervisor())
150+
except Exception as e:
151+
log_error(f"DEBUG setup failed: {e}")
152+
114153
# Fixed port (internal container port)
115154
port = 9583
116155

src/ha_mcp/client/rest_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,13 @@ async def _request(self, method: str, endpoint: str, **kwargs: Any) -> dict[str,
121121
# Ensure endpoint doesn't start with a slash to properly join with base_url
122122
endpoint = endpoint.lstrip("/")
123123

124+
logger.info(f"API Request: {method} {endpoint} (Base: {self.httpx_client.base_url})")
125+
124126
try:
125127
response = await self.httpx_client.request(method, endpoint, **kwargs)
128+
logger.info(f"API Response: {response.status_code} {response.url}")
129+
130+
# Handle authentication errors
126131

127132
# Handle authentication errors
128133
if response.status_code == 401:

0 commit comments

Comments
 (0)