Some checks failed
Docker Build and Push / build-and-push (push) Failing after 37s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m16s
Integration Tests / integration-tests (push) Failing after 58s
Integration Tests / performance-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.1) (push) Failing after 12s
LabFusion CI/CD Pipeline / api-docs (push) Successful in 1m42s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 46s
Service Adapters (Python FastAPI) / test (3.9) (push) Failing after 47s
Service Adapters (Python FastAPI) / build (push) Has been skipped
LabFusion CI/CD Pipeline / frontend (push) Failing after 1m53s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 45s
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 28s
### Summary of Changes - Updated the `isort` command in both CI workflows to include the `--profile black` option for consistent code formatting. - Refactored function definitions in service adapters to improve readability by consolidating parameters into single lines. ### Expected Results - Enhanced consistency in code formatting checks across CI workflows, ensuring adherence to the Black style guide. - Improved readability and maintainability of function definitions in service adapters.
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
from fastapi import APIRouter, HTTPException, Path
|
|
|
|
from models.schemas import HAAttributes, HAEntitiesResponse, HAEntity
|
|
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}"),
|
|
)
|