2024-04-22 14:05:24 +02:00
|
|
|
from fastapi import FastAPI, APIRouter
|
|
|
|
|
|
|
|
from hue.hue_adapter import HueAdapter
|
|
|
|
from ..core.module import Module
|
2023-12-11 00:25:20 +01:00
|
|
|
from fastapi import APIRouter
|
|
|
|
from fastapi.responses import HTMLResponse
|
|
|
|
|
2024-04-22 14:05:24 +02:00
|
|
|
router = APIRouter(tags=["hue"])
|
|
|
|
hue = HueAdapter("192.168.178.85")
|
|
|
|
|
|
|
|
########## Module ##########
|
|
|
|
|
|
|
|
|
|
|
|
class HueModule(Module):
|
|
|
|
def __init__(self) -> None:
|
|
|
|
super().__init__("hue")
|
|
|
|
|
|
|
|
def add_routes(self, server: FastAPI) -> None:
|
|
|
|
server.include_router(router, prefix="/hue")
|
|
|
|
|
|
|
|
|
|
|
|
########## Routes ##########
|
2023-12-11 00:25:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
@router.get("/scenes", tags=["scene"])
|
|
|
|
async def get_scenes():
|
|
|
|
return hue.list_scenes()
|
|
|
|
|
|
|
|
|
|
|
|
@router.post(
|
|
|
|
"/room/{room_name}/scene/{scene_name}",
|
|
|
|
tags=["room", "scene"],
|
|
|
|
)
|
|
|
|
async def activate_scene(room_name: str, scene_name: str):
|
|
|
|
try:
|
|
|
|
hue.in_room_activate_scene(room_name, scene_name)
|
|
|
|
except Exception as e:
|
|
|
|
return HTMLResponse(status_code=400, content=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
@router.post(
|
|
|
|
"/room/{room_name}/off",
|
|
|
|
tags=["room"],
|
|
|
|
)
|
|
|
|
async def deactivate_room(room_name: str):
|
|
|
|
try:
|
|
|
|
hue.in_room_deactivate_lights(room_name)
|
|
|
|
except Exception as e:
|
|
|
|
return HTMLResponse(status_code=400, content=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
@router.post(
|
|
|
|
"/room/{room_name}/on",
|
|
|
|
tags=["room"],
|
|
|
|
)
|
|
|
|
async def activate_room(room_name: str):
|
|
|
|
try:
|
|
|
|
hue.in_room_activate_lights(room_name)
|
|
|
|
except Exception as e:
|
|
|
|
return HTMLResponse(status_code=400, content=str(e))
|