49 lines
2.0 KiB
Python
49 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
from app.ha.models import HaEntitySummary
|
|
from app.rules.heating import HeatingRule
|
|
from app.rules.recommender import Recommender
|
|
|
|
|
|
def _sensor(entity_id: str, device_class: str | None = None) -> HaEntitySummary:
|
|
return HaEntitySummary(entity_id=entity_id, domain="sensor", device_class=device_class)
|
|
|
|
|
|
def _binary_sensor(entity_id: str, device_class: str | None = None) -> HaEntitySummary:
|
|
return HaEntitySummary(
|
|
entity_id=entity_id,
|
|
domain="binary_sensor",
|
|
device_class=device_class,
|
|
)
|
|
|
|
|
|
def _climate(entity_id: str) -> HaEntitySummary:
|
|
return HaEntitySummary(entity_id=entity_id, domain="climate")
|
|
|
|
|
|
def test_heating_rule_triggers() -> None:
|
|
rule = HeatingRule()
|
|
assert rule.matches([_climate("climate.living_room")])
|
|
assert rule.matches([_sensor("sensor.temperature_living", device_class="temperature")])
|
|
assert rule.matches([_sensor("sensor.humidity_bath", device_class="humidity")])
|
|
assert rule.matches([_binary_sensor("binary_sensor.occupancy_living", "occupancy")])
|
|
assert rule.matches([_binary_sensor("binary_sensor.presence_entry", "presence")])
|
|
|
|
|
|
def test_heating_rule_ignores_non_relevant_sensors() -> None:
|
|
rule = HeatingRule()
|
|
assert not rule.matches([_sensor("sensor.temperature_living")])
|
|
assert not rule.matches([_sensor("sensor.power", device_class="power")])
|
|
assert not rule.matches([_sensor("sensor.voltage", device_class="voltage")])
|
|
assert not rule.matches([_sensor("sensor.door", device_class="door")])
|
|
assert not rule.matches([_sensor("sensor.window", device_class="window")])
|
|
assert not rule.matches([_sensor("sensor.light", device_class="illuminance")])
|
|
assert not rule.matches([_binary_sensor("binary_sensor.window", device_class="window")])
|
|
|
|
|
|
def test_recommender_uses_rule() -> None:
|
|
recommender = Recommender(rules=[HeatingRule()])
|
|
assert recommender.run([_climate("climate.living_room")]) == [
|
|
"Prüfe Heizungsregelung: Aktiviere energiesparenden Modus bei Abwesenheit."
|
|
]
|