64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from app.ha.models import HaEntitySummary
|
|
from app.rules.heating import HeatingRule
|
|
|
|
|
|
def _entity(entity_id: str, domain: str, device_class: str | None = None) -> HaEntitySummary:
|
|
return HaEntitySummary(entity_id=entity_id, domain=domain, device_class=device_class)
|
|
|
|
|
|
# --- positive cases --------------------------------------------------------
|
|
@pytest.mark.parametrize(
|
|
"entity",
|
|
[
|
|
_entity("climate.living_room", "climate"),
|
|
_entity("sensor.temperature_living", "sensor", "temperature"),
|
|
_entity("sensor.humidity_bathroom", "sensor", "humidity"),
|
|
_entity("binary_sensor.living_room_occupancy", "binary_sensor", "occupancy"),
|
|
_entity("binary_sensor.entrance_presence", "binary_sensor", "presence"),
|
|
],
|
|
ids=lambda e: e.entity_id,
|
|
)
|
|
def test_heating_rule_triggers_for_relevant_entities(entity: HaEntitySummary) -> None:
|
|
rule = HeatingRule()
|
|
assert rule.matches([entity]) is True
|
|
|
|
|
|
# --- negative cases -------------------------------------------------------
|
|
@pytest.mark.parametrize(
|
|
"entity",
|
|
[
|
|
_entity("sensor.power_consumption", "sensor", "power"),
|
|
_entity("sensor.door", "sensor", "door"),
|
|
_entity("sensor.energy", "sensor", "energy"),
|
|
_entity("binary_sensor.door_window", "binary_sensor", "door"),
|
|
_entity("binary_sensor.motion", "binary_sensor", "motion"),
|
|
_entity("light.living_room", "light"),
|
|
_entity("switch.plug", "switch"),
|
|
_entity("sensor.some_random", "sensor"),
|
|
_entity("binary_sensor.some_binary", "binary_sensor"),
|
|
],
|
|
ids=lambda e: e.entity_id,
|
|
)
|
|
def test_heating_rule_ignores_non_heating_entities(entity: HaEntitySummary) -> None:
|
|
rule = HeatingRule()
|
|
assert rule.matches([entity]) is False
|
|
|
|
|
|
def test_heating_rule_mixed_list_returns_true() -> None:
|
|
rule = HeatingRule()
|
|
entities = [
|
|
_entity("sensor.power", "sensor", "power"),
|
|
_entity("climate.living_room", "climate"),
|
|
_entity("light.ceiling", "light"),
|
|
]
|
|
assert rule.matches(entities) is True
|
|
|
|
|
|
def test_heating_rule_recommendation_is_stable() -> None:
|
|
rule = HeatingRule()
|
|
expected = "Prüfe Heizungsregelung: Aktiviere energiesparenden Modus bei Abwesenheit."
|
|
assert rule.recommendation([_entity("climate.living_room", "climate")]) == expected |