device state setting fix 2

This commit is contained in:
2025-11-19 10:16:39 +01:00
parent a382d58601
commit 381f8521d4

View File

@@ -365,17 +365,15 @@ async def publish_mqtt(topic: str, payload: dict[str, Any]) -> None:
@app.get("/devices/{device_id}")
async def get_device(device_id: str) -> DeviceInfo:
devices = load_devices()
try:
device = devices[device_id]
return DeviceInfo(
device_id=device["device_id"],
type=device["type"],
name=device.get("name", device["device_id"]),
features=device.get("features", {})
)
except KeyError:
device = next((d for d in devices if d["device_id"] == device_id), None)
if not device:
raise HTTPException(status_code=404, detail="Device not found")
return DeviceInfo(
device_id=device["device_id"],
type=device["type"],
name=device.get("name", device["device_id"]),
features=device.get("features", {})
)
@app.get("/devices")
async def get_devices() -> list[DeviceInfo]: