fix api integration quality baseline

This commit is contained in:
2026-06-10 21:15:41 +02:00
parent 6540d62ff7
commit 8841a68c8d
14 changed files with 126 additions and 42 deletions

View File

@@ -1,20 +1,26 @@
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from fastapi import FastAPI, Depends
from fastapi import FastAPI
from app.api.v1.entities import router as entities_router
from app.config import load_settings
from app.ha.client import HaClient, HaClientSettings
from app.ha.reader import HaReader
@asynccontextmanager
async def lifespan(app: FastAPI):
settings = HaClientSettings(
url=app.state.settings.ha_url,
token=app.state.settings.ha_token,
)
client = HaClient(settings=settings)
app.state.ha_reader = HaReader(client=client)
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
settings = load_settings()
app.state.settings = settings
if settings.ha_configured:
client = HaClient(
settings=HaClientSettings(
url=settings.ha_url or "",
token=settings.ha_token or "",
)
)
app.state.ha_reader = HaReader(client=client)
yield
@@ -26,19 +32,7 @@ app = FastAPI(
)
class Settings:
ha_url: str
ha_token: str
app.state.settings = Settings()
def get_ha_reader() -> HaReader:
return app.state.ha_reader
app.include_router(entities_router, dependencies=[Depends(get_ha_reader)])
app.include_router(entities_router)
@app.get("/health")
@@ -48,4 +42,4 @@ def health() -> dict[str, str]:
@app.get("/")
def root() -> dict[str, str]:
return {"service": "sillyhome-next", "docs": "/docs"}
return {"service": "sillyhome-next", "docs": "/docs"}