Compare commits
6 Commits
feature/ha
...
6b1e2ad0dc
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b1e2ad0dc | |||
| 6bba8f5947 | |||
| 009d4b68cb | |||
| 9016dbad18 | |||
| d81ebf399c | |||
| bdf33458f0 |
19
app/api/v1/entities.py
Normal file
19
app/api/v1/entities.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List, Sequence
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.ha.models import HaEntitySummary
|
||||
|
||||
router = APIRouter(prefix="/v1", tags=["entities"])
|
||||
|
||||
|
||||
@router.get(
|
||||
"/entities",
|
||||
summary="Home-Assistant-Entities auflisten",
|
||||
description="Gibt eine kompakte Zusammenfassung aller erreichbaren HA-Entitäten zurück.",
|
||||
response_model=List[HaEntitySummary],
|
||||
)
|
||||
def list_entities() -> Sequence[HaEntitySummary]:
|
||||
raise NotImplementedError("Integration mit dem HA-Client folgt in separatem Issue.")
|
||||
1
app/ha/__init__.py
Normal file
1
app/ha/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# sillyhome-next.ha
|
||||
38
app/main.py
38
app/main.py
@@ -1,12 +1,46 @@
|
||||
from fastapi import FastAPI
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI, Depends
|
||||
|
||||
from app.api.v1.entities import router as entities_router
|
||||
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)
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="SillyHome Next API",
|
||||
description="Lokales Smart-Home-Intelligenzsystem für Home Assistant.",
|
||||
version="0.1.0",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
|
||||
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.get("/health")
|
||||
def health() -> dict[str, str]:
|
||||
return {"status": "ok"}
|
||||
@@ -14,4 +48,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"}
|
||||
10
tests/api/test_entities.py
Normal file
10
tests/api/test_entities.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_openapi_docs_are_available() -> None:
|
||||
response = client.get("/docs")
|
||||
assert response.status_code == 200
|
||||
assert "SillyHome Next API" in response.text
|
||||
Reference in New Issue
Block a user