diff --git a/apps/api/main.py b/apps/api/main.py index b6c58d4..1eca37d 100644 --- a/apps/api/main.py +++ b/apps/api/main.py @@ -1,71 +1,4 @@ -@app.get("/devices/{device_id}/layout") -async def get_device_layout(device_id: str): - """Gibt die layout-spezifischen Informationen für ein einzelnes Gerät zurück.""" - layout = load_layout() - for room in layout.get("rooms", []): - for device in room.get("devices", []): - if device.get("device_id") == device_id: - # Rückgabe: Layout-Infos + Raumname - return { - "device_id": device_id, - "room": room.get("name"), - "title": device.get("title"), - "icon": device.get("icon"), - "rank": device.get("rank"), - } - raise HTTPException(status_code=404, detail="Device layout not found") -@app.get("/devices/{device_id}/state") -async def get_device_state(device_id: str): - """Gibt den aktuellen State für ein einzelnes Gerät zurück.""" - state_path = Path(__file__).parent.parent.parent / "config" / "devices.yaml" - if not state_path.exists(): - raise HTTPException(status_code=500, detail="State file not found") - with open(state_path, "r") as f: - config = yaml.safe_load(f) - states = config.get("states", {}) - state = states.get(device_id) - if state is None: - raise HTTPException(status_code=404, detail="Device state not found") - return state -# --- Minimal-invasive: Einzelgerät-Layout-Endpunkt --- -from fastapi import Query - - - -# --- Minimal-invasive: Einzelgerät-Layout-Endpunkt --- -@app.get("/devices/{device_id}/layout") -async def get_device_layout(device_id: str): - """Gibt die layout-spezifischen Informationen für ein einzelnes Gerät zurück.""" - layout = load_layout() - for room in layout.get("rooms", []): - for device in room.get("devices", []): - if device.get("device_id") == device_id: - # Rückgabe: Layout-Infos + Raumname - return { - "device_id": device_id, - "room": room.get("name"), - "title": device.get("title"), - "icon": device.get("icon"), - "rank": device.get("rank"), - } - raise HTTPException(status_code=404, detail="Device layout not found") - -# --- Minimal-invasive: Einzelgerät-State-Endpunkt --- -@app.get("/devices/{device_id}/state") -async def get_device_state(device_id: str): - """Gibt den aktuellen State für ein einzelnes Gerät zurück.""" - # States werden wie im Bulk-Endpoint geladen - state_path = Path(__file__).parent.parent.parent / "config" / "devices.yaml" - if not state_path.exists(): - raise HTTPException(status_code=500, detail="State file not found") - with open(state_path, "r") as f: - config = yaml.safe_load(f) - states = config.get("states", {}) - state = states.get(device_id) - if state is None: - raise HTTPException(status_code=404, detail="Device state not found") - return state """API main entry point. API-Analyse für HomeKit-Bridge Kompatibilität @@ -280,6 +213,74 @@ app.add_middleware( allow_headers=["*"], ) +@app.get("/devices/{device_id}/layout") +async def get_device_layout(device_id: str): + """Gibt die layout-spezifischen Informationen für ein einzelnes Gerät zurück.""" + layout = load_layout() + for room in layout.get("rooms", []): + for device in room.get("devices", []): + if device.get("device_id") == device_id: + # Rückgabe: Layout-Infos + Raumname + return { + "device_id": device_id, + "room": room.get("name"), + "title": device.get("title"), + "icon": device.get("icon"), + "rank": device.get("rank"), + } + raise HTTPException(status_code=404, detail="Device layout not found") + +@app.get("/devices/{device_id}/state") +async def get_device_state(device_id: str): + """Gibt den aktuellen State für ein einzelnes Gerät zurück.""" + state_path = Path(__file__).parent.parent.parent / "config" / "devices.yaml" + if not state_path.exists(): + raise HTTPException(status_code=500, detail="State file not found") + with open(state_path, "r") as f: + config = yaml.safe_load(f) + states = config.get("states", {}) + state = states.get(device_id) + if state is None: + raise HTTPException(status_code=404, detail="Device state not found") + return state +# --- Minimal-invasive: Einzelgerät-Layout-Endpunkt --- +from fastapi import Query + + + +# --- Minimal-invasive: Einzelgerät-Layout-Endpunkt --- +@app.get("/devices/{device_id}/layout") +async def get_device_layout(device_id: str): + """Gibt die layout-spezifischen Informationen für ein einzelnes Gerät zurück.""" + layout = load_layout() + for room in layout.get("rooms", []): + for device in room.get("devices", []): + if device.get("device_id") == device_id: + # Rückgabe: Layout-Infos + Raumname + return { + "device_id": device_id, + "room": room.get("name"), + "title": device.get("title"), + "icon": device.get("icon"), + "rank": device.get("rank"), + } + raise HTTPException(status_code=404, detail="Device layout not found") + +# --- Minimal-invasive: Einzelgerät-State-Endpunkt --- +@app.get("/devices/{device_id}/state") +async def get_device_state(device_id: str): + """Gibt den aktuellen State für ein einzelnes Gerät zurück.""" + # States werden wie im Bulk-Endpoint geladen + state_path = Path(__file__).parent.parent.parent / "config" / "devices.yaml" + if not state_path.exists(): + raise HTTPException(status_code=500, detail="State file not found") + with open(state_path, "r") as f: + config = yaml.safe_load(f) + states = config.get("states", {}) + state = states.get(device_id) + if state is None: + raise HTTPException(status_code=404, detail="Device state not found") + return state @app.on_event("startup") async def startup_event():