from fastapi import APIRouter, HTTPException, Path from models.schemas import HAEntitiesResponse, HAEntity, HAAttributes from services.config import SERVICES router = APIRouter() @router.get("/home-assistant/entities", response_model=HAEntitiesResponse, summary="Get Home Assistant Entities", description="Retrieve all entities from Home Assistant", responses={ 200: {"description": "Successfully retrieved entities"}, 503: {"description": "Home Assistant integration not configured"} }, tags=["Home Assistant"]) async def get_ha_entities(): """Get Home Assistant entities including sensors, switches, and other devices""" if not SERVICES["home_assistant"]["enabled"]: raise HTTPException( status_code=503, detail="Home Assistant integration not configured. Please set HOME_ASSISTANT_TOKEN environment variable." ) # This would make actual API calls to Home Assistant # For now, return mock data return HAEntitiesResponse( entities=[ HAEntity( entity_id="sensor.cpu_usage", state="45.2", attributes=HAAttributes( unit_of_measurement="%", friendly_name="CPU Usage" ) ), HAEntity( entity_id="sensor.memory_usage", state="2.1", attributes=HAAttributes( unit_of_measurement="GB", friendly_name="Memory Usage" ) ) ] ) @router.get("/home-assistant/entity/{entity_id}", response_model=HAEntity, summary="Get Specific HA Entity", description="Get a specific Home Assistant entity by ID", responses={ 200: {"description": "Successfully retrieved entity"}, 404: {"description": "Entity not found"}, 503: {"description": "Home Assistant integration not configured"} }, tags=["Home Assistant"]) async def get_ha_entity(entity_id: str = Path(..., description="Entity ID")): """Get a specific Home Assistant entity by its ID""" if not SERVICES["home_assistant"]["enabled"]: raise HTTPException( status_code=503, detail="Home Assistant integration not configured. Please set HOME_ASSISTANT_TOKEN environment variable." ) # This would make actual API calls to Home Assistant # For now, return mock data return HAEntity( entity_id=entity_id, state="unknown", attributes=HAAttributes( unit_of_measurement="", friendly_name=f"Entity {entity_id}" ) )