Compare commits
1 Commits
main
...
feature/bu
| Author | SHA1 | Date | |
|---|---|---|---|
| b8012de934 |
@@ -9,7 +9,21 @@ from app.rules.recommender import Rule
|
||||
class HeatingRule(Rule):
|
||||
def matches(self, entities: Sequence[HaEntitySummary]) -> bool:
|
||||
domains = {item.domain for item in entities}
|
||||
return "climate" in domains or "sensor" in domains
|
||||
if "climate" in domains:
|
||||
return True
|
||||
if "sensor" in domains:
|
||||
# Nur Sensoren mit Heizungs-/Klimarelevanz
|
||||
relevant_device_classes = {
|
||||
"temperature",
|
||||
"humidity",
|
||||
"occupancy",
|
||||
"presence",
|
||||
"heating",
|
||||
}
|
||||
for entity in entities:
|
||||
if entity.domain == "sensor" and entity.device_class in relevant_device_classes:
|
||||
return True
|
||||
return False
|
||||
|
||||
def recommendation(self, entities: Sequence[HaEntitySummary]) -> str:
|
||||
return "Prüfe Heizungsregelung: Aktiviere energiesparenden Modus bei Abwesenheit."
|
||||
@@ -5,8 +5,8 @@ from app.rules.heating import HeatingRule
|
||||
from app.rules.recommender import Recommender
|
||||
|
||||
|
||||
def _sensor(entity_id: str) -> HaEntitySummary:
|
||||
return HaEntitySummary(entity_id=entity_id, domain="sensor")
|
||||
def _sensor(entity_id: str, device_class: str | None = None) -> HaEntitySummary:
|
||||
return HaEntitySummary(entity_id=entity_id, domain="sensor", device_class=device_class)
|
||||
|
||||
|
||||
def _climate(entity_id: str) -> HaEntitySummary:
|
||||
@@ -16,7 +16,22 @@ def _climate(entity_id: str) -> HaEntitySummary:
|
||||
def test_heating_rule_triggers() -> None:
|
||||
rule = HeatingRule()
|
||||
assert rule.matches([_climate("climate.living_room")])
|
||||
assert rule.matches([_sensor("sensor.temperature_living")])
|
||||
# Relevante Sensoren
|
||||
assert rule.matches([_sensor("sensor.temperature_living", device_class="temperature")])
|
||||
assert rule.matches([_sensor("sensor.humidity_bath", device_class="humidity")])
|
||||
assert rule.matches([_sensor("sensor.occupancy_living", device_class="occupancy")])
|
||||
assert rule.matches([_sensor("sensor.presence_entry", device_class="presence")])
|
||||
assert rule.matches([_sensor("sensor.heating_status", device_class="heating")])
|
||||
|
||||
|
||||
def test_heating_rule_ignores_non_relevant_sensors() -> None:
|
||||
rule = HeatingRule()
|
||||
# Nicht-relevante Sensoren
|
||||
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")])
|
||||
|
||||
|
||||
def test_recommender_uses_rule() -> None:
|
||||
|
||||
Reference in New Issue
Block a user