uprava zapisovani casu do deye (nevyvolava self_sustain), notifikace na discord pri zmene rezimu
Some checks failed
deploy / deploy (push) Failing after 20s
test / smoke-test (push) Successful in 3s

This commit is contained in:
Dusan Vojacek
2026-04-06 20:53:58 +02:00
parent 4881966d00
commit c955efb9cb
9 changed files with 182 additions and 96 deletions

View File

@@ -40,6 +40,10 @@ from services.control_exporter import (
)
from services.heartbeat_service import send_heartbeat
from services.forecast_service import fetch_pv_forecast
from services.notification_service import (
notify_operating_mode_changed,
run_fn_set_mode_with_discord,
)
from services.price_importer import import_ote_prices
from services.telemetry_collector import run_telemetry_loop_wrapper
from pydantic import BaseModel, Field
@@ -123,7 +127,15 @@ async def lifespan(app: FastAPI):
async def scheduled_expire_modes() -> None:
async with app.state.pg_pool.acquire() as conn:
try:
await conn.fetchval("SELECT ems.fn_expire_modes()")
rows = await conn.fetch("SELECT * FROM ems.fn_expire_modes()")
for r in rows:
await notify_operating_mode_changed(
str(r["site_code"]),
str(r["old_mode"]),
str(r["new_mode"]),
"system:expiry",
"Automatické vypršení dočasného režimu",
)
except Exception:
logger.exception("scheduled_expire_modes failed")
@@ -1215,8 +1227,8 @@ async def set_site_mode(
raise HTTPException(status_code=404, detail="Site not found")
try:
await conn.execute(
"SELECT ems.fn_set_mode($1, $2, $3, $4, $5)",
await run_fn_set_mode_with_discord(
conn,
site_id,
mode,
"user:api",