Pretty display
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import asyncio
|
||||
import time
|
||||
import requests
|
||||
import ipaddress
|
||||
import datetime
|
||||
from typing import Dict
|
||||
from zeroconf import ServiceStateChange
|
||||
from zeroconf.asyncio import AsyncZeroconf, AsyncServiceBrowser, AsyncServiceInfo
|
||||
@@ -55,20 +55,45 @@ class DisplayManager:
|
||||
print(f"[DisplayManager] ❌ Screen disconnected: {name}")
|
||||
self.screens.pop(name, None)
|
||||
|
||||
async def broadcast_state(self, device_id: str, microwave_states: dict, button_state: bool, cloud_alert: bool):
|
||||
async def broadcast_state(self, microwave_states: dict, cloud_alert: bool):
|
||||
"""Broadcasts the system state JSON to all discovered screens concurrently."""
|
||||
if not self.screens:
|
||||
return
|
||||
|
||||
now_time = time.time()
|
||||
update_time_str = datetime.datetime.now().strftime("%H:%M")
|
||||
|
||||
microwaves_list = []
|
||||
for mw_id, state_info in microwave_states.items():
|
||||
# Extract state properties safely
|
||||
state_val = state_info.cooking_state
|
||||
paused = state_info.paused
|
||||
rem_time = state_info.cooking_estimated_remaining_time
|
||||
start_t = state_info.cooking_start_time
|
||||
name = state_info.friendly_name
|
||||
|
||||
# Calculate progress percentage (0 to 100)
|
||||
progress = 0
|
||||
if start_t > 0 and rem_time > 0:
|
||||
elapsed = now_time - start_t
|
||||
total = elapsed + rem_time
|
||||
if total > 0:
|
||||
progress = int((elapsed / total) * 100)
|
||||
progress = max(0, min(100, progress))
|
||||
|
||||
microwaves_list.append({
|
||||
"id": mw_id,
|
||||
"name": name,
|
||||
"state": state_val,
|
||||
"paused": paused,
|
||||
"remaining_time": rem_time,
|
||||
"progress": progress
|
||||
})
|
||||
|
||||
payload = {
|
||||
"device_id": device_id,
|
||||
"timestamp": int(time.time()),
|
||||
"cloud_alert": cloud_alert,
|
||||
"defrost_mode": button_state,
|
||||
"microwaves": [
|
||||
{"id": mw_id, "state": state}
|
||||
for mw_id, state in microwave_states.items()
|
||||
]
|
||||
"update_time": update_time_str,
|
||||
"microwaves": microwaves_list
|
||||
}
|
||||
|
||||
# Dispatch POST requests in parallel without blocking the main loop
|
||||
|
||||
Reference in New Issue
Block a user