32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Sequence
|
|
|
|
from app.ha.models import HaEntitySummary
|
|
from app.rules.recommender import Rule
|
|
|
|
|
|
HEATING_SENSOR_DEVICE_CLASSES = frozenset({"temperature", "humidity"})
|
|
HEATING_BINARY_SENSOR_DEVICE_CLASSES = frozenset({"occupancy", "presence"})
|
|
|
|
|
|
class HeatingRule(Rule):
|
|
def matches(self, entities: Sequence[HaEntitySummary]) -> bool:
|
|
for entity in entities:
|
|
if entity.domain == "climate":
|
|
return True
|
|
if (
|
|
entity.domain == "sensor"
|
|
and entity.device_class in HEATING_SENSOR_DEVICE_CLASSES
|
|
):
|
|
return True
|
|
if (
|
|
entity.domain == "binary_sensor"
|
|
and entity.device_class in HEATING_BINARY_SENSOR_DEVICE_CLASSES
|
|
):
|
|
return True
|
|
return False
|
|
|
|
def recommendation(self, entities: Sequence[HaEntitySummary]) -> str:
|
|
return "Prüfe Heizungsregelung: Aktiviere energiesparenden Modus bei Abwesenheit."
|