device state setting fix 2
This commit is contained in:
@@ -365,17 +365,15 @@ async def publish_mqtt(topic: str, payload: dict[str, Any]) -> None:
|
|||||||
@app.get("/devices/{device_id}")
|
@app.get("/devices/{device_id}")
|
||||||
async def get_device(device_id: str) -> DeviceInfo:
|
async def get_device(device_id: str) -> DeviceInfo:
|
||||||
devices = load_devices()
|
devices = load_devices()
|
||||||
|
device = next((d for d in devices if d["device_id"] == device_id), None)
|
||||||
try:
|
if not device:
|
||||||
device = devices[device_id]
|
raise HTTPException(status_code=404, detail="Device not found")
|
||||||
return DeviceInfo(
|
return DeviceInfo(
|
||||||
device_id=device["device_id"],
|
device_id=device["device_id"],
|
||||||
type=device["type"],
|
type=device["type"],
|
||||||
name=device.get("name", device["device_id"]),
|
name=device.get("name", device["device_id"]),
|
||||||
features=device.get("features", {})
|
features=device.get("features", {})
|
||||||
)
|
)
|
||||||
except KeyError:
|
|
||||||
raise HTTPException(status_code=404, detail="Device not found")
|
|
||||||
|
|
||||||
@app.get("/devices")
|
@app.get("/devices")
|
||||||
async def get_devices() -> list[DeviceInfo]:
|
async def get_devices() -> list[DeviceInfo]:
|
||||||
|
|||||||
Reference in New Issue
Block a user