34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Sequence
|
|
|
|
from app.ha.models import HaEntitySummary
|
|
from app.rules.recommender import Rule
|
|
|
|
|
|
class HeatingRule(Rule):
|
|
"""Heizungsregel: Nur auf heizungsrelevante Entitäten reagieren.
|
|
|
|
Triggert bei:
|
|
- `climate`-Entitäten direkt
|
|
- `sensor` mit `device_class` in {temperature, humidity}
|
|
- `binary_sensor` mit `device_class` in {occupancy, presence}
|
|
|
|
Alle anderen Domains/Device-Klassen bleiben ohne Effekt.
|
|
"""
|
|
|
|
HEATING_SENSOR_CLASSES: frozenset[str] = frozenset({"temperature", "humidity"})
|
|
HEATING_PRESENCE_CLASSES: frozenset[str] = frozenset({"occupancy", "presence"})
|
|
|
|
def matches(self, entities: Sequence[HaEntitySummary]) -> bool:
|
|
for item in entities:
|
|
if item.domain == "climate":
|
|
return True
|
|
if item.domain == "sensor" and item.device_class in self.HEATING_SENSOR_CLASSES:
|
|
return True
|
|
if item.domain == "binary_sensor" and item.device_class in self.HEATING_PRESENCE_CLASSES:
|
|
return True
|
|
return False
|
|
|
|
def recommendation(self, entities: Sequence[HaEntitySummary]) -> str:
|
|
return "Prüfe Heizungsregelung: Aktiviere energiesparenden Modus bei Abwesenheit." |