Improve learning discovery and dashboard i18n
This commit is contained in:
@@ -87,7 +87,7 @@ def _service(
|
||||
|
||||
|
||||
def test_reconciliation_auto_assigns_and_trains_numeric_model(tmp_path: Path) -> None:
|
||||
start = datetime(2026, 6, 1, tzinfo=timezone.utc)
|
||||
start = datetime.now(timezone.utc) - timedelta(days=1)
|
||||
entities = [
|
||||
HaEntitySummary(
|
||||
entity_id="light.abstellkammer",
|
||||
@@ -352,6 +352,100 @@ def test_fan_prefers_humidity_over_power_sensor(tmp_path: Path) -> None:
|
||||
assert record.assignment.selected_numeric_entity_id == "sensor.bad_luftfeuchtigkeit"
|
||||
|
||||
|
||||
def test_lidl_light_uses_room_presence_not_brand_overlap(tmp_path: Path) -> None:
|
||||
entities = [
|
||||
HaEntitySummary(
|
||||
entity_id="light.lidl_kuche",
|
||||
domain="light",
|
||||
friendly_name="Lidl Küche",
|
||||
),
|
||||
HaEntitySummary(
|
||||
entity_id="light.lidl_wohnzimmer",
|
||||
domain="light",
|
||||
friendly_name="Lidl Wohnzimmer",
|
||||
),
|
||||
HaEntitySummary(
|
||||
entity_id="binary_sensor.pir_kuche_motion_detection",
|
||||
domain="binary_sensor",
|
||||
device_class="motion",
|
||||
friendly_name="Bewegungsmelder",
|
||||
device_name="PIR_Küche",
|
||||
),
|
||||
HaEntitySummary(
|
||||
entity_id="binary_sensor.pir_wohnzimmer_sensor_state_any",
|
||||
domain="binary_sensor",
|
||||
device_class="motion",
|
||||
friendly_name="Bewegungsmelder",
|
||||
device_name="PIR_Wohnzimmer",
|
||||
),
|
||||
]
|
||||
service = _service(tmp_path, entities, {})
|
||||
|
||||
record = service.configure_actuator("light.lidl_kuche")
|
||||
|
||||
assert record.assignment.selected_context_entity_ids == [
|
||||
"binary_sensor.pir_kuche_motion_detection"
|
||||
]
|
||||
|
||||
|
||||
def test_mailbox_reset_button_uses_cabinet_door_context(tmp_path: Path) -> None:
|
||||
entities = [
|
||||
HaEntitySummary(
|
||||
entity_id="button.smart_mailbox_als_geleert_markieren",
|
||||
domain="button",
|
||||
friendly_name="Smart Mailbox Als geleert markieren",
|
||||
),
|
||||
HaEntitySummary(
|
||||
entity_id="binary_sensor.schrank_strasse_open",
|
||||
domain="binary_sensor",
|
||||
device_class="door",
|
||||
friendly_name="Schrank Straße",
|
||||
),
|
||||
]
|
||||
service = _service(tmp_path, entities, {})
|
||||
|
||||
record = service.configure_actuator("button.smart_mailbox_als_geleert_markieren")
|
||||
|
||||
assert record.assignment.selected_context_entity_ids == [
|
||||
"binary_sensor.schrank_strasse_open"
|
||||
]
|
||||
assert record.assignment.review_required is False
|
||||
|
||||
|
||||
def test_fan_auto_selects_humidity_and_occupancy_context(tmp_path: Path) -> None:
|
||||
start = datetime(2026, 6, 1, tzinfo=timezone.utc)
|
||||
entities = [
|
||||
HaEntitySummary(
|
||||
entity_id="humidifier.gastewc_luftung",
|
||||
domain="humidifier",
|
||||
friendly_name="GästeWC Lüftung",
|
||||
),
|
||||
HaEntitySummary(
|
||||
entity_id="sensor.pir_gastewc_humidity",
|
||||
domain="sensor",
|
||||
device_class="humidity",
|
||||
state_class="measurement",
|
||||
unit_of_measurement="%",
|
||||
friendly_name="Gäste WC Luftfeuchtigkeit",
|
||||
),
|
||||
HaEntitySummary(
|
||||
entity_id="input_boolean.gaste_wc_occupied",
|
||||
domain="input_boolean",
|
||||
friendly_name="gaste_wc_occupied",
|
||||
),
|
||||
]
|
||||
service = _service(
|
||||
tmp_path,
|
||||
entities,
|
||||
{"sensor.pir_gastewc_humidity": _points(8, start, 55.0)},
|
||||
)
|
||||
|
||||
record = service.configure_actuator("humidifier.gastewc_luftung")
|
||||
|
||||
assert record.assignment.selected_numeric_entity_id == "sensor.pir_gastewc_humidity"
|
||||
assert "input_boolean.gaste_wc_occupied" in record.assignment.selected_context_entity_ids
|
||||
|
||||
|
||||
def test_manual_assignment_persists_and_wins_over_automatic_mapping(tmp_path: Path) -> None:
|
||||
start = datetime(2026, 6, 1, tzinfo=timezone.utc)
|
||||
entities = [
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -120,6 +120,28 @@ def test_normalize_state_history_keeps_categorical_changes() -> None:
|
||||
assert [point.state for point in result[0].points] == ["off", "on"]
|
||||
|
||||
|
||||
def test_normalize_state_history_keeps_light_attribute_changes() -> None:
|
||||
result = normalize_state_history_payload(
|
||||
[
|
||||
[
|
||||
{
|
||||
"entity_id": "light.office",
|
||||
"state": "on",
|
||||
"attributes": {"brightness": 80, "friendly_name": "Office"},
|
||||
"last_changed": "2026-06-01T08:00:00+00:00",
|
||||
},
|
||||
{
|
||||
"state": "on",
|
||||
"attributes": {"brightness": 120, "friendly_name": "Office"},
|
||||
"last_changed": "2026-06-01T08:05:00+00:00",
|
||||
},
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
assert [point.attributes["brightness"] for point in result[0].points] == [80, 120]
|
||||
|
||||
|
||||
def test_normalize_logbook_preserves_action_origin() -> None:
|
||||
result = normalize_logbook_payload(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user