BEHAVIOR-004: trust HA automation actions
This commit is contained in:
@@ -124,7 +124,9 @@ class BehaviorEngine:
|
||||
logbook=logbook,
|
||||
own_executions=record.behavior.execution_events,
|
||||
)
|
||||
high_confidence = sum(1 for pattern in patterns if pattern.source == "user")
|
||||
trusted_actions = sum(
|
||||
1 for pattern in patterns if pattern.source in {"user", "automation"}
|
||||
)
|
||||
status = (
|
||||
BehaviorStatus.TRAINED
|
||||
if len(patterns) >= self._settings.min_behavior_actions
|
||||
@@ -142,7 +144,7 @@ class BehaviorEngine:
|
||||
update={
|
||||
"status": status,
|
||||
"sample_count": len(patterns),
|
||||
"high_confidence_sample_count": high_confidence,
|
||||
"high_confidence_sample_count": trusted_actions,
|
||||
"patterns": patterns[-_MAX_PATTERNS:],
|
||||
"last_trained_at": now,
|
||||
"reason": reason,
|
||||
@@ -296,8 +298,8 @@ class BehaviorEngine:
|
||||
< self._settings.min_behavior_actions
|
||||
):
|
||||
raise ValueError(
|
||||
"Für die Freigabe fehlen noch eindeutig dir zugeordnete Handlungen. "
|
||||
"Bediene den Aktor einige Male über Home Assistant."
|
||||
"Für die Freigabe fehlen noch eindeutig zugeordnete manuelle "
|
||||
"oder automatisierte Handlungen."
|
||||
)
|
||||
mode = BehaviorMode.ACTIVE
|
||||
approved_at = now
|
||||
@@ -338,8 +340,6 @@ class BehaviorEngine:
|
||||
context_ids,
|
||||
point.timestamp,
|
||||
)
|
||||
if source == "automation" and trigger is None:
|
||||
continue
|
||||
contexts = {
|
||||
entity_id: state
|
||||
for entity_id in context_ids
|
||||
@@ -520,7 +520,7 @@ def _action_source(
|
||||
if nearest.context_user_id:
|
||||
return "user", 1.0
|
||||
if nearest.context_domain in _AUTOMATION_CONTEXT_DOMAINS:
|
||||
return "automation", 0.1
|
||||
return "automation", 1.0
|
||||
return "physical_or_unknown", 0.7
|
||||
|
||||
|
||||
|
||||
@@ -239,20 +239,20 @@ async function showActuator(actuatorId, evaluationMessage = "") {
|
||||
.map(candidate => `<li><strong>${escapeHtml(candidate.friendly_name || candidate.entity_id)}</strong>: ${candidate.evidence.map(escapeHtml).join(", ") || "statistisch relevanter Kandidat"}</li>`)
|
||||
.join("");
|
||||
const prediction = record.behavior.prediction;
|
||||
const requiredUserActions = 3;
|
||||
const requiredTrustedActions = 3;
|
||||
const learnedAutomationActions = record.behavior.patterns.filter(
|
||||
pattern => pattern.source === "automation",
|
||||
).length;
|
||||
const missingUserActions = Math.max(
|
||||
const missingTrustedActions = Math.max(
|
||||
0,
|
||||
requiredUserActions - record.behavior.high_confidence_sample_count,
|
||||
requiredTrustedActions - record.behavior.high_confidence_sample_count,
|
||||
);
|
||||
const activationButton = record.behavior.mode === "active"
|
||||
? `<button class="danger" onclick="setActivation('${escapeHtml(record.actuator_entity_id)}', false)">Autonomes Schalten stoppen</button>`
|
||||
: record.behavior.status === "trained" && missingUserActions === 0
|
||||
: record.behavior.status === "trained" && missingTrustedActions === 0
|
||||
? `<button onclick="setActivation('${escapeHtml(record.actuator_entity_id)}', true)">Lernen und Schalten freigeben</button>`
|
||||
: record.behavior.status === "trained"
|
||||
? `<p class='muted'>Freigabe noch gesperrt: ${missingUserActions} eindeutig manuelle Bedienung${missingUserActions === 1 ? "" : "en"} fehlen. Bediene das Licht dafür direkt über Home Assistant.</p>`
|
||||
? `<p class='muted'>Freigabe noch gesperrt: ${missingTrustedActions} eindeutig zugeordnete manuelle oder automatisierte Handlung${missingTrustedActions === 1 ? "" : "en"} fehlen.</p>`
|
||||
: "<p class='muted'>Freigabe wird möglich, sobald genügend Handlungen gelernt wurden.</p>";
|
||||
box.innerHTML = `
|
||||
<div class="grid-two">
|
||||
@@ -268,7 +268,7 @@ async function showActuator(actuatorId, evaluationMessage = "") {
|
||||
<h3>Lernfortschritt</h3>
|
||||
<p><strong>Betriebsart:</strong> ${escapeHtml(behaviorLabel(record))}</p>
|
||||
<p><strong>Gelernte Handlungen:</strong> ${record.behavior.sample_count}</p>
|
||||
<p><strong>Davon eindeutig Benutzer:</strong> ${record.behavior.high_confidence_sample_count}</p>
|
||||
<p><strong>Davon eindeutig geregelt:</strong> ${record.behavior.high_confidence_sample_count}</p>
|
||||
<p><strong>Davon erkannte HA-Automationen:</strong> ${learnedAutomationActions}</p>
|
||||
<p><strong>Letztes Training:</strong> ${escapeHtml(record.behavior.last_trained_at || "noch nicht")}</p>
|
||||
<p><strong>Was noch passiert:</strong> ${escapeHtml(record.behavior.reason)}</p>
|
||||
|
||||
Reference in New Issue
Block a user