update: Major Overhaul to all subsystems
This commit is contained in:
@@ -18,6 +18,10 @@ async def handle_message(serial: str, topic_type: str, payload: dict):
|
||||
try:
|
||||
if topic_type == "status/heartbeat":
|
||||
await _handle_heartbeat(serial, payload)
|
||||
elif topic_type == "status/alerts":
|
||||
await _handle_alerts(serial, payload)
|
||||
elif topic_type == "status/info":
|
||||
await _handle_info(serial, payload)
|
||||
elif topic_type == "logs":
|
||||
await _handle_log(serial, payload)
|
||||
elif topic_type == "data":
|
||||
@@ -29,6 +33,8 @@ async def handle_message(serial: str, topic_type: str, payload: dict):
|
||||
|
||||
|
||||
async def _handle_heartbeat(serial: str, payload: dict):
|
||||
# Store silently — do not log as a visible event.
|
||||
# The console surfaces an alert only when the device goes silent (no heartbeat for 90s).
|
||||
inner = payload.get("payload", {})
|
||||
await db.insert_heartbeat(
|
||||
device_serial=serial,
|
||||
@@ -55,6 +61,31 @@ async def _handle_log(serial: str, payload: dict):
|
||||
)
|
||||
|
||||
|
||||
async def _handle_alerts(serial: str, payload: dict):
|
||||
subsystem = payload.get("subsystem", "")
|
||||
state = payload.get("state", "")
|
||||
if not subsystem or not state:
|
||||
logger.warning(f"Malformed alert payload from {serial}: {payload}")
|
||||
return
|
||||
|
||||
if state == "CLEARED":
|
||||
await db.delete_alert(serial, subsystem)
|
||||
else:
|
||||
await db.upsert_alert(serial, subsystem, state, payload.get("msg"))
|
||||
|
||||
|
||||
async def _handle_info(serial: str, payload: dict):
|
||||
event_type = payload.get("type", "")
|
||||
data = payload.get("payload", {})
|
||||
|
||||
if event_type == "playback_started":
|
||||
logger.debug(f"{serial}: playback started — melody_uid={data.get('melody_uid')}")
|
||||
elif event_type == "playback_stopped":
|
||||
logger.debug(f"{serial}: playback stopped")
|
||||
else:
|
||||
logger.debug(f"{serial}: info event '{event_type}'")
|
||||
|
||||
|
||||
async def _handle_data_response(serial: str, payload: dict):
|
||||
status = payload.get("status", "")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user