Filter autopilot trigger candidates
This commit is contained in:
37
app/main.py
37
app/main.py
@@ -155,7 +155,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||
app = FastAPI(
|
||||
title="SillyHome Future API",
|
||||
description="SillyHome v2 event-core side project.",
|
||||
version="2.0.0-alpha.13",
|
||||
version="2.0.0-alpha.14",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
@@ -951,6 +951,11 @@ def _run_autopilot_once() -> AutopilotRunResult:
|
||||
if not settings.enabled:
|
||||
return AutopilotRunResult(candidates=[], trained_models=[], evaluations=[])
|
||||
learning = stores.learning()
|
||||
learning.candidates = {
|
||||
candidate_id: candidate
|
||||
for candidate_id, candidate in learning.candidates.items()
|
||||
if _is_good_trigger_id(candidate.trigger_entity_id)
|
||||
}
|
||||
candidates = _generate_candidates(settings)
|
||||
for candidate in candidates:
|
||||
learning.candidates[candidate.candidate_id] = candidate
|
||||
@@ -974,7 +979,7 @@ def _generate_candidates(settings: AutopilotSettings) -> list[CandidateRecommend
|
||||
triggers = [
|
||||
entity
|
||||
for entity in runtime.entities.values()
|
||||
if entity.domain in {"binary_sensor", "sensor"}
|
||||
if entity.domain == "binary_sensor" and _is_good_trigger_id(entity.entity_id)
|
||||
][:500]
|
||||
result: list[CandidateRecommendation] = []
|
||||
for actuator in actuators:
|
||||
@@ -1023,6 +1028,34 @@ def _candidate_score(actuator: EntityState, trigger: EntityState) -> tuple[float
|
||||
return 0.0, ""
|
||||
|
||||
|
||||
def _is_good_trigger_id(entity_id: str) -> bool:
|
||||
raw = entity_id.lower()
|
||||
bad = {
|
||||
"battery",
|
||||
"batterie",
|
||||
"low",
|
||||
"update",
|
||||
"problem",
|
||||
"connectivity",
|
||||
"linkquality",
|
||||
"tamper",
|
||||
}
|
||||
good = {
|
||||
"door",
|
||||
"tuer",
|
||||
"ture",
|
||||
"window",
|
||||
"fenster",
|
||||
"motion",
|
||||
"pir",
|
||||
"occupancy",
|
||||
"presence",
|
||||
"kontakt",
|
||||
"contact",
|
||||
}
|
||||
return not any(token in raw for token in bad) and any(token in raw for token in good)
|
||||
|
||||
|
||||
def _entity_tokens(entity: EntityState) -> set[str]:
|
||||
raw = f"{entity.entity_id} {entity.friendly_name or ''}".lower()
|
||||
return {part for part in raw.replace(".", "_").split("_") if len(part) >= 4}
|
||||
|
||||
Reference in New Issue
Block a user