Improve learning discovery and dashboard i18n
This commit is contained in:
@@ -646,6 +646,81 @@ def test_prediction_ignores_stale_causal_context_state() -> None:
|
||||
) is None
|
||||
|
||||
|
||||
def test_prediction_respects_learned_context_delay() -> None:
|
||||
now = datetime.now(timezone.utc).replace(second=0, microsecond=0)
|
||||
patterns = [
|
||||
BehaviorPattern(
|
||||
target_state="on",
|
||||
minute_of_day=60,
|
||||
weekday=0,
|
||||
context_states={"input_boolean.gaste_wc_occupied": "on"},
|
||||
trigger_entity_id="input_boolean.gaste_wc_occupied",
|
||||
trigger_from_state="off",
|
||||
trigger_to_state="on",
|
||||
trigger_delay_seconds=180,
|
||||
source="automation",
|
||||
weight=1.0,
|
||||
observed_at=now - timedelta(days=days_ago),
|
||||
)
|
||||
for days_ago in (3, 2, 1)
|
||||
]
|
||||
|
||||
early = predict_behavior(
|
||||
patterns,
|
||||
current_context={"input_boolean.gaste_wc_occupied": "on"},
|
||||
current_context_changed_at={
|
||||
"input_boolean.gaste_wc_occupied": now - timedelta(seconds=30)
|
||||
},
|
||||
now=now,
|
||||
min_support=3,
|
||||
window_minutes=30,
|
||||
causal_window_seconds=240,
|
||||
)
|
||||
due = predict_behavior(
|
||||
patterns,
|
||||
current_context={"input_boolean.gaste_wc_occupied": "on"},
|
||||
current_context_changed_at={
|
||||
"input_boolean.gaste_wc_occupied": now - timedelta(seconds=185)
|
||||
},
|
||||
now=now,
|
||||
min_support=3,
|
||||
window_minutes=30,
|
||||
causal_window_seconds=240,
|
||||
)
|
||||
|
||||
assert early is None
|
||||
assert due is not None
|
||||
assert due.target_state == "on"
|
||||
|
||||
|
||||
def test_light_prediction_carries_brightness_attributes() -> None:
|
||||
now = datetime.now(timezone.utc).replace(second=0, microsecond=0)
|
||||
patterns = [
|
||||
BehaviorPattern(
|
||||
target_state="on",
|
||||
target_attributes={"brightness": brightness},
|
||||
minute_of_day=now.astimezone().hour * 60 + now.astimezone().minute,
|
||||
weekday=now.astimezone().weekday(),
|
||||
context_states={"binary_sensor.pir_kuche_motion_detection": "on"},
|
||||
source="automation",
|
||||
weight=1.0,
|
||||
observed_at=now - timedelta(days=days_ago),
|
||||
)
|
||||
for days_ago, brightness in zip((3, 2, 1), (80, 90, 100), strict=True)
|
||||
]
|
||||
|
||||
prediction = predict_behavior(
|
||||
patterns,
|
||||
current_context={"binary_sensor.pir_kuche_motion_detection": "on"},
|
||||
now=now,
|
||||
min_support=3,
|
||||
window_minutes=30,
|
||||
)
|
||||
|
||||
assert prediction is not None
|
||||
assert prediction.target_attributes["brightness"] == 90
|
||||
|
||||
|
||||
def test_state_change_uses_websocket_context_state_for_immediate_action(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user