Pretty display

This commit is contained in:
2026-08-15 15:00:22 +02:00
parent 2d06293325
commit e132d05a85
6 changed files with 323 additions and 121 deletions
+85
View File
@@ -0,0 +1,85 @@
from shared.cookingState import CookingStates
import shared.config as config
class MicrowaveState:
state = None
paused = False
cooking_state = None
cooking_estimated_remaining_time = 0
cooking_start_time = 0
def __init__(self, id, on_change_callback=None):
self.friendly_name = f"Microwave-{id}"
self.state = MicrowaveState.IDLE
self.cooking_state = CookingStates.IDLE
self.on_change_callback = on_change_callback
def _notify_change(self):
"""Invokes callback if registered on state attribute changes."""
if self.on_change_callback:
try:
self.on_change_callback()
except Exception as e:
print(f"[MicrowaveState] Error in change callback: {e}")
def set_state(self, new_state):
if config.DEBUG:
assert new_state in (
MicrowaveState.IDLE,
MicrowaveState.ANALYZING,
MicrowaveState.WAITING_FOR_CLOUD,
MicrowaveState.COOKING,
MicrowaveState.DONE
), f"Invalid state: {new_state}"
if self.state != new_state:
self.state = new_state
self._notify_change()
def set_paused(self, is_paused):
if self.paused != is_paused:
self.paused = is_paused
self._notify_change()
def toggle_pause(self):
self.paused = not self.paused
self._notify_change()
def set_cooking_state(self, new_cooking_state):
if config.DEBUG:
assert new_cooking_state in (
CookingStates.IDLE,
CookingStates.COOKING,
CookingStates.DONE,
CookingStates.STIRRING_REQUIRED,
CookingStates.ALERT
), "Invalid cooking state: " + str(new_cooking_state)
if self.cooking_state != new_cooking_state:
self.cooking_state = new_cooking_state
self._notify_change()
def set_cooking_estimated_remaining_time(self, time_seconds):
if self.cooking_estimated_remaining_time != time_seconds:
self.cooking_estimated_remaining_time = time_seconds
self._notify_change()
def set_cooking_start_time(self, start_time):
if self.cooking_start_time != start_time:
self.cooking_start_time = start_time
self._notify_change()
def to_dict(self):
return {
"friendly_name": self.friendly_name,
"state": self.state,
"paused": self.paused,
"cooking_estimated_remaining_time": self.cooking_estimated_remaining_time,
"cooking_start_time": self.cooking_start_time
}
IDLE = "IDLE" # Microwave is empty
ANALYZING = "ANALYZING" # Reading sensors & waiting for IR
WAITING_FOR_CLOUD = "WAITING_FOR_CLOUD" # Waiting for API parameters
COOKING = "COOKING" # Microwave is active
DONE = "DONE" # Finished/Stopped, waiting for dish removal