dynamic dashboard initial

This commit is contained in:
2025-11-04 19:33:47 +01:00
parent 69e07056a1
commit ca623121a3
15 changed files with 1774 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
import asyncio
import json
import logging
import os
from pathlib import Path
from typing import Any, AsyncGenerator
@@ -16,6 +17,8 @@ from pydantic import BaseModel, ValidationError
from packages.home_capabilities import CAP_VERSION, LightState
logger = logging.getLogger(__name__)
app = FastAPI(
title="Home Automation API",
description="API for home automation system",
@@ -71,6 +74,7 @@ class DeviceInfo(BaseModel):
device_id: str
type: str
name: str
features: dict[str, Any] = {}
# Configuration helpers
@@ -145,19 +149,57 @@ async def get_devices() -> list[DeviceInfo]:
"""Get list of available devices.
Returns:
list: List of device information
list: List of device information including features
"""
devices = load_devices()
return [
DeviceInfo(
device_id=device["device_id"],
type=device["type"],
name=device.get("name", device["device_id"])
name=device.get("name", device["device_id"]),
features=device.get("features", {})
)
for device in devices
]
@app.get("/layout")
async def get_layout() -> dict[str, Any]:
"""Get UI layout configuration.
Returns:
dict: Layout configuration with rooms and device tiles
"""
from packages.home_capabilities import load_layout
try:
layout = load_layout()
# Convert Pydantic models to dict
rooms = []
for room in layout.rooms:
devices = []
for tile in room.devices:
devices.append({
"device_id": tile.device_id,
"title": tile.title,
"icon": tile.icon,
"rank": tile.rank
})
rooms.append({
"name": room.name,
"devices": devices
})
return {"rooms": rooms}
except Exception as e:
logger.error(f"Error loading layout: {e}")
# Return empty layout on error
return {"rooms": []}
@app.post("/devices/{device_id}/set", status_code=status.HTTP_202_ACCEPTED)
async def set_device(device_id: str, request: SetDeviceRequest) -> dict[str, str]:
"""Set device state.