Loading...
Loading...
Compare original and translation side by side
python ~/.claude/skills/ha-error-checking/scripts/check_dashboard.py climate-controlpython ~/.claude/skills/ha-error-checking/scripts/check_dashboard.py climate-controlimport json
import websocket
import os
HA_URL = "http://192.168.68.123:8123"
HA_TOKEN = os.environ["HA_LONG_LIVED_TOKEN"]
def check_dashboard_errors(url_path: str):
"""Check for errors in a specific dashboard."""
ws_url = HA_URL.replace("http://", "ws://") + "/api/websocket"
ws = websocket.create_connection(ws_url)
msg_id = 1
# 1. Auth
ws.recv()
ws.send(json.dumps({"type": "auth", "access_token": HA_TOKEN}))
ws.recv()
# 2. Check system logs for lovelace errors
ws.send(json.dumps({"id": msg_id, "type": "system_log/list"}))
msg_id += 1
logs = json.loads(ws.recv())
lovelace_errors = [
log for log in logs.get("result", [])
if "lovelace" in log.get("name", "").lower()
or "frontend" in log.get("name", "").lower()
]
# 3. Validate dashboard config
ws.send(json.dumps({
"id": msg_id,
"type": "lovelace/config",
"url_path": url_path
}))
msg_id += 1
config_response = json.loads(ws.recv())
# 4. Get all entity states
ws.send(json.dumps({"id": msg_id, "type": "get_states"}))
msg_id += 1
states_response = json.loads(ws.recv())
ws.close()
return {
"lovelace_errors": lovelace_errors,
"config": config_response.get("result"),
"available_entities": [s["entity_id"] for s in states_response.get("result", [])]
}import json
import websocket
import os
HA_URL = "http://192.168.68.123:8123"
HA_TOKEN = os.environ["HA_LONG_LIVED_TOKEN"]
def check_dashboard_errors(url_path: str):
"""Check for errors in a specific dashboard."""
ws_url = HA_URL.replace("http://", "ws://") + "/api/websocket"
ws = websocket.create_connection(ws_url)
msg_id = 1
# 1. Auth
ws.recv()
ws.send(json.dumps({"type": "auth", "access_token": HA_TOKEN}))
ws.recv()
# 2. Check system logs for lovelace errors
ws.send(json.dumps({"id": msg_id, "type": "system_log/list"}))
msg_id += 1
logs = json.loads(ws.recv())
lovelace_errors = [
log for log in logs.get("result", [])
if "lovelace" in log.get("name", "").lower()
or "frontend" in log.get("name", "").lower()
]
# 3. Validate dashboard config
ws.send(json.dumps({
"id": msg_id,
"type": "lovelace/config",
"url_path": url_path
}))
msg_id += 1
config_response = json.loads(ws.recv())
# 4. Get all entity states
ws.send(json.dumps({"id": msg_id, "type": "get_states"}))
msg_id += 1
states_response = json.loads(ws.recv())
ws.close()
return {
"lovelace_errors": lovelace_errors,
"config": config_response.get("result"),
"available_entities": [s["entity_id"] for s in states_response.get("result", [])]
}ws.send(json.dumps({"id": 1, "type": "system_log/list"}))
response = json.loads(ws.recv())
logs = response.get("result", [])ws.send(json.dumps({"id": 1, "type": "system_log/list"}))
response = json.loads(ws.recv())
logs = response.get("result", [])undefinedundefinedlovelace_errors = [
log for log in logs
if "lovelace" in log.get("name", "").lower()
or "frontend" in log.get("name", "").lower()
]
for error in lovelace_errors:
print(f"[{error['level']}] {error['name']}: {error['message']}")lovelace_errors = [
log for log in logs
if "lovelace" in log.get("name", "").lower()
or "frontend" in log.get("name", "").lower()
]
for error in lovelace_errors:
print(f"[{error['level']}] {error['name']}: {error['message']}")ws.send(json.dumps({
"id": 1,
"type": "lovelace/config",
"url_path": "climate-control" # Must contain hyphen
}))
response = json.loads(ws.recv())
config = response.get("result")ws.send(json.dumps({
"id": 1,
"type": "lovelace/config",
"url_path": "climate-control" # Must contain hyphen
}))
response = json.loads(ws.recv())
config = response.get("result")undefinedundefinedws.send(json.dumps({"id": 1, "type": "lovelace/dashboards/list"}))
response = json.loads(ws.recv())
dashboards = response.get("result", [])
dashboard_paths = [d["url_path"] for d in dashboards]
if "climate-control" in dashboard_paths:
print("Dashboard exists")
else:
print("Dashboard not found")ws.send(json.dumps({"id": 1, "type": "lovelace/dashboards/list"}))
response = json.loads(ws.recv())
dashboards = response.get("result", [])
dashboard_paths = [d["url_path"] for d in dashboards]
if "climate-control" in dashboard_paths:
print("Dashboard exists")
else:
print("Dashboard not found")def validate_url_path(url_path: str) -> tuple[bool, str]:
"""Validate dashboard URL path format.
Returns:
(is_valid, error_message)
"""
if "-" not in url_path:
return False, f"URL path must contain hyphen: '{url_path}' -> '{url_path}-view'"
if " " in url_path:
return False, f"URL path cannot contain spaces: '{url_path}'"
if not url_path.islower():
return False, f"URL path must be lowercase: '{url_path}'"
return True, ""def validate_url_path(url_path: str) -> tuple[bool, str]:
"""Validate dashboard URL path format.
Returns:
(is_valid, error_message)
"""
if "-" not in url_path:
return False, f"URL path must contain hyphen: '{url_path}' -> '{url_path}-view'"
if " " in url_path:
return False, f"URL path cannot contain spaces: '{url_path}'"
if not url_path.islower():
return False, f"URL path must be lowercase: '{url_path}'"
return True, ""undefinedundefinedws.send(json.dumps({"id": 1, "type": "get_states"}))
response = json.loads(ws.recv())
entities = response.get("result", [])
entity_ids = [e["entity_id"] for e in entities]ws.send(json.dumps({"id": 1, "type": "get_states"}))
response = json.loads(ws.recv())
entities = response.get("result", [])
entity_ids = [e["entity_id"] for e in entities]
See `examples/examples.md` for entity extraction from dashboard configs and pattern matching.
查看`examples/examples.md`获取从仪表盘配置提取实体和模式匹配的方法。def check_hacs_card_installed(ws, repository_id: int) -> bool:
"""Check if a HACS card is installed by repository ID."""
ws.send(json.dumps({
"id": 1,
"type": "hacs/repositories/list"
}))
response = json.loads(ws.recv())
repositories = response.get("result", [])
installed = [r for r in repositories if r.get("id") == repository_id]
return len(installed) > 0def check_hacs_card_installed(ws, repository_id: int) -> bool:
"""Check if a HACS card is installed by repository ID."""
ws.send(json.dumps({
"id": 1,
"type": "hacs/repositories/list"
}))
response = json.loads(ws.recv())
repositories = response.get("result", [])
installed = [r for r in repositories if r.get("id") == repository_id]
return len(installed) > 0
See `examples/examples.md` for programmatic HACS card installation.
查看`examples/examples.md`获取程序化安装HACS卡片的方法。span.endVALID_SPAN_END_VALUES = ["minute", "hour", "day", "week", "month", "year", "isoWeek"]
def validate_apexcharts_span(card_config: dict) -> tuple[bool, str]:
"""Validate ApexCharts span configuration.
Returns:
(is_valid, error_message)
"""
if "span" not in card_config:
return True, "" # span is optional
span = card_config["span"]
if "end" not in span:
return True, "" # end is optional within span
end_value = span["end"]
if end_value not in VALID_SPAN_END_VALUES:
return False, f"Invalid span.end: '{end_value}'. Must be one of: {VALID_SPAN_END_VALUES}"
return True, ""span.endVALID_SPAN_END_VALUES = ["minute", "hour", "day", "week", "month", "year", "isoWeek"]
def validate_apexcharts_span(card_config: dict) -> tuple[bool, str]:
"""Validate ApexCharts span configuration.
Returns:
(is_valid, error_message)
"""
if "span" not in card_config:
return True, "" # span is optional
span = card_config["span"]
if "end" not in span:
return True, "" # end is optional within span
end_value = span["end"]
if end_value not in VALID_SPAN_END_VALUES:
return False, f"Invalid span.end: '{end_value}'. Must be one of: {VALID_SPAN_END_VALUES}"
return True, ""undefinedundefined"Invalid value for span.end: now"undefined"Invalid value for span.end: now"undefinedundefinedundefinedundefinedundefinedundefinedundefined"Entity not found: sensor.temperature"undefined"Entity not found: sensor.temperature"undefined# Find similar entities
similar = [e for e in all_entities if "temperature" in e]
print(f"Did you mean: {similar}")
See `references/reference.md` for complete error patterns, browser debugging steps, best practices, and troubleshooting checklist.# Find similar entities
similar = [e for e in all_entities if "temperature" in e]
print(f"Did you mean: {similar}")
查看`references/reference.md`获取完整的错误模式、浏览器调试步骤、最佳实践和故障排除清单。span.endspan.end