first
This commit is contained in:
23
backend/app/routers/health.py
Normal file
23
backend/app/routers/health.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlmodel import Session, func, select
|
||||
|
||||
from app.database import get_session
|
||||
from app.ha_client import ha_client
|
||||
from app.models import EntityCache
|
||||
from app.scan_state import scan_state
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health(session: Session = Depends(get_session)):
|
||||
connected, message = await ha_client.check_connection()
|
||||
count = session.exec(select(func.count()).select_from(EntityCache)).one()
|
||||
|
||||
return {
|
||||
"status": "ok",
|
||||
"ha_connected": connected,
|
||||
"ha_message": message,
|
||||
"entity_count": count,
|
||||
**scan_state.to_dict(),
|
||||
}
|
||||
Reference in New Issue
Block a user