third version before modbus cleanup

This commit is contained in:
Dusan Vojacek
2026-04-03 16:03:06 +02:00
parent 9f4126946d
commit 182d5a37e1
18 changed files with 846 additions and 128 deletions

View File

@@ -151,7 +151,8 @@ async def get_site_status_full(
reserve_row = await conn.fetchrow(
"""
SELECT MIN(reserve_soc_percent)::float AS reserve_soc
SELECT MIN(reserve_soc_percent)::float AS reserve_soc,
MIN(min_soc_percent)::float AS min_soc
FROM ems.asset_battery
WHERE site_id = $1
""",
@@ -173,7 +174,10 @@ async def get_site_status_full(
if run_row:
int_rows = await conn.fetch(
"""
SELECT interval_start, battery_setpoint_w
SELECT interval_start, battery_setpoint_w,
load_baseline_w,
pv_a_forecast_raw_w, pv_b_forecast_raw_w,
pv_a_forecast_solver_w, pv_b_forecast_solver_w
FROM ems.planning_interval
WHERE run_id = $1
ORDER BY interval_start
@@ -243,6 +247,7 @@ async def get_site_status_full(
mode_code = (mode_row["mode_code"] if mode_row else None) or ""
reserve_soc = float(reserve_row["reserve_soc"]) if reserve_row and reserve_row["reserve_soc"] is not None else None
min_soc = float(reserve_row["min_soc"]) if reserve_row and reserve_row["min_soc"] is not None else None
soc = float(inv_row["battery_soc_percent"]) if inv_row and inv_row["battery_soc_percent"] is not None else None
alerts: list[dict[str, str]] = []
@@ -265,8 +270,10 @@ async def get_site_status_full(
if mode_code.upper() == "MANUAL":
add_alert("warn", "Systém v manuálním režimu")
if reserve_soc is not None and soc is not None and soc < reserve_soc:
add_alert("error", "SoC baterie pod rezervou")
if min_soc is not None and soc is not None and soc < min_soc:
add_alert("error", "SoC baterie pod minimálním limitem")
elif reserve_soc is not None and soc is not None and soc < reserve_soc:
add_alert("warn", "SoC pod ekonomickou rezervou (arbitrážní podlaha)")
if hb_age is None or hb_age > HEARTBEAT_STALE_SEC:
add_alert("error", "EMS heartbeat výpadek")
@@ -300,6 +307,7 @@ def _infrastructure_notification_items(
has_plan: bool,
tomorrow_slots: int,
mode_code: str,
min_soc: float | None,
reserve_soc: float | None,
soc: float | None,
inv_age: int | None,
@@ -354,8 +362,20 @@ def _infrastructure_notification_items(
if mode_code.upper() == "MANUAL":
push("mode_manual", "info", "Manuální režim", "Automatická optimalizace je vypnutá.")
if reserve_soc is not None and soc is not None and soc < reserve_soc:
push("soc_reserve", "error", "SoC pod rezervou", "Nabití baterie je pod nastavenou bezpečnostní rezervou.")
if min_soc is not None and soc is not None and soc < min_soc:
push(
"soc_min",
"error",
"SoC pod minimem",
"SoC je pod absolutním minimem z konfigurace baterie.",
)
elif reserve_soc is not None and soc is not None and soc < reserve_soc:
push(
"soc_reserve",
"warning",
"SoC pod ekonomickou rezervou",
"SoC je pod arbitrážní podlahou plánovač může v tomto pásmu omezovat export.",
)
if hb_age is None or hb_age > HEARTBEAT_STALE_SEC:
push("heartbeat", "error", "EMS heartbeat", "Služba EMS nehlásí pravidelný heartbeat.")
@@ -402,7 +422,8 @@ async def get_site_notifications(
)
reserve_row = await conn.fetchrow(
"""
SELECT MIN(reserve_soc_percent)::float AS reserve_soc
SELECT MIN(reserve_soc_percent)::float AS reserve_soc,
MIN(min_soc_percent)::float AS min_soc
FROM ems.asset_battery
WHERE site_id = $1
""",
@@ -512,6 +533,11 @@ async def get_site_notifications(
if reserve_row and reserve_row["reserve_soc"] is not None
else None
)
min_soc = (
float(reserve_row["min_soc"])
if reserve_row and reserve_row["min_soc"] is not None
else None
)
soc = (
float(inv_row["battery_soc_percent"])
if inv_row and inv_row["battery_soc_percent"] is not None
@@ -524,6 +550,7 @@ async def get_site_notifications(
has_plan=has_plan,
tomorrow_slots=int(tomorrow_slots or 0),
mode_code=mode_code,
min_soc=min_soc,
reserve_soc=reserve_soc,
soc=soc,
inv_age=inv_age,