fix rs485 s eror self_sustain
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
@@ -40,6 +41,32 @@ async def notify_operating_mode_changed(
|
||||
await send_discord(msg, level=lvl)
|
||||
|
||||
|
||||
async def _auto_rolling_replan_after_self_sustain_exit(site_id: int) -> None:
|
||||
"""Po návratu z SELF_SUSTAIN do AUTO přepočítat rolling plán (nové DB spojení)."""
|
||||
try:
|
||||
from app.deps import get_pg_pool
|
||||
from services.planning_engine import run_plan_api
|
||||
|
||||
pool = await get_pg_pool()
|
||||
except Exception as e:
|
||||
logger.warning("Auto replan after SELF_SUSTAIN→AUTO: pool unavailable: %s", e)
|
||||
return
|
||||
try:
|
||||
async with pool.acquire() as replan_conn:
|
||||
await run_plan_api(
|
||||
site_id,
|
||||
"rolling",
|
||||
replan_conn,
|
||||
triggered_by="mode:self_sustain_exit",
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"Auto rolling replan after SELF_SUSTAIN→AUTO failed: %s",
|
||||
e,
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
|
||||
async def run_fn_set_mode_with_discord(
|
||||
conn: asyncpg.Connection,
|
||||
site_id: int,
|
||||
@@ -84,6 +111,15 @@ async def run_fn_set_mode_with_discord(
|
||||
notes,
|
||||
level=notify_level,
|
||||
)
|
||||
prev_u = str(prev).upper()
|
||||
new_u = str(new).upper()
|
||||
if prev_u == "SELF_SUSTAIN" and new_u == "AUTO":
|
||||
try:
|
||||
asyncio.get_running_loop().create_task(
|
||||
_auto_rolling_replan_after_self_sustain_exit(site_id)
|
||||
)
|
||||
except RuntimeError:
|
||||
logger.debug("No event loop; skip auto rolling replan")
|
||||
return str(new)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user