Files
xterra-overland-dashboard/pico-dashboard/alarms/alarm_manager.py
T

45 lines
1.4 KiB
Python

from .alarm_definitions import (
BATTERY_SOC_LOW,
BATTERY_VOLTAGE_LOW,
FRIDGE_ZONE_1_HIGH,
FRIDGE_ZONE_2_HIGH,
SENSOR_FAILURE,
COMMUNICATION_LOST,
DEFAULT_THRESHOLDS,
)
class AlarmManager:
def __init__(self, thresholds=None):
self.thresholds = dict(DEFAULT_THRESHOLDS)
if thresholds:
self.thresholds.update(thresholds)
def evaluate(self, state):
alarms = []
soc = state.battery.get("soc")
if soc is not None and soc < self.thresholds["battery_soc_low"]:
alarms.append(BATTERY_SOC_LOW)
voltage = state.battery.get("voltage")
if voltage is not None and voltage < self.thresholds["battery_voltage_low"]:
alarms.append(BATTERY_VOLTAGE_LOW)
z1 = state.temps.get("fridge_zone_1")
if z1 is not None and z1 > self.thresholds["fridge_temp_high"]:
alarms.append(FRIDGE_ZONE_1_HIGH)
z2 = state.temps.get("fridge_zone_2")
if z2 is not None and z2 > self.thresholds["fridge_temp_high"]:
alarms.append(FRIDGE_ZONE_2_HIGH)
if not state.network.get("uart_connected", False):
alarms.append(COMMUNICATION_LOST)
for sensor_name, online in state.sensor_health.items():
if not online:
alarms.append(f"{SENSOR_FAILURE}:{sensor_name}")
return alarms