feat: improve actor-specific context selection
This commit is contained in:
@@ -14,19 +14,6 @@ from app.ha.models import HaEntitySummary
|
||||
from app.ha.reader import HaReader
|
||||
|
||||
router = APIRouter(prefix="/v1/actuators", tags=["actuators"])
|
||||
_MANUAL_CONTEXT_DOMAINS = frozenset({
|
||||
"binary_sensor",
|
||||
"climate",
|
||||
"cover",
|
||||
"device_tracker",
|
||||
"fan",
|
||||
"humidifier",
|
||||
"light",
|
||||
"person",
|
||||
"sensor",
|
||||
"switch",
|
||||
"weather",
|
||||
})
|
||||
|
||||
|
||||
class ConfigureActuatorRequest(BaseModel):
|
||||
@@ -62,19 +49,16 @@ def discover_actuators(ha_reader: HaReader = Depends(get_ha_reader)) -> list[HaE
|
||||
|
||||
|
||||
@router.get("/context-options", response_model=list[HaEntitySummary])
|
||||
def context_options(ha_reader: HaReader = Depends(get_ha_reader)) -> list[HaEntitySummary]:
|
||||
return sorted(
|
||||
[
|
||||
entity
|
||||
for entity in ha_reader.read_entities()
|
||||
if entity.domain in _MANUAL_CONTEXT_DOMAINS
|
||||
],
|
||||
key=lambda entity: (
|
||||
entity.area_name or "",
|
||||
entity.friendly_name or entity.entity_id,
|
||||
entity.entity_id,
|
||||
),
|
||||
)
|
||||
def context_options(
|
||||
request: Request,
|
||||
actuator_entity_id: str | None = Query(default=None, pattern=r"^[a-z0-9_]+\.[a-z0-9_]+$"),
|
||||
) -> list[HaEntitySummary]:
|
||||
if actuator_entity_id is None:
|
||||
return []
|
||||
try:
|
||||
return _service(request).suggest_context_options(actuator_entity_id)
|
||||
except KeyError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@router.get("", response_model=list[ActuatorRecord])
|
||||
|
||||
Reference in New Issue
Block a user