Wait, is this peak ?
This commit is contained in:
+27
-9
@@ -13,6 +13,7 @@ class CookingState:
|
||||
self.temperature_provider = temperature_provider
|
||||
self.on_state_change = on_state_change
|
||||
self.on_refresh = on_refresh
|
||||
self.on_pause = None
|
||||
|
||||
self.state = CookingStates.COOKING
|
||||
self.paused = False
|
||||
@@ -24,6 +25,7 @@ class CookingState:
|
||||
self.estimated_remaining_time = float(cook_time)
|
||||
self._last_temperature_sample = None
|
||||
self._last_refresh_signature = None
|
||||
self._stirred = False
|
||||
|
||||
def set_temperature_provider(self, temperature_provider):
|
||||
self.temperature_provider = temperature_provider
|
||||
@@ -33,6 +35,9 @@ class CookingState:
|
||||
|
||||
def set_refresh_callback(self, callback):
|
||||
self.on_refresh = callback
|
||||
|
||||
def set_pause_callback(self, callback):
|
||||
self.on_pause = callback
|
||||
|
||||
def pause(self):
|
||||
if self.paused:
|
||||
@@ -40,8 +45,9 @@ class CookingState:
|
||||
|
||||
self.paused = True
|
||||
self._pause_started_at = time.time()
|
||||
self._notify_refresh(force=True)
|
||||
|
||||
# self._notify_refresh(force=True)
|
||||
if self.on_pause:
|
||||
self.on_pause(self)
|
||||
def unpause(self):
|
||||
if not self.paused:
|
||||
return
|
||||
@@ -50,15 +56,16 @@ class CookingState:
|
||||
if self._pause_started_at is not None:
|
||||
self._paused_duration += now - self._pause_started_at
|
||||
|
||||
self._pause_started_at = None
|
||||
# self._pause_started_at = None
|
||||
self.paused = False
|
||||
self._notify_refresh(force=True)
|
||||
# self._notify_refresh(force=True)
|
||||
|
||||
def toggle_pause(self):
|
||||
if self.paused:
|
||||
self.unpause()
|
||||
else:
|
||||
self.pause()
|
||||
self.on_pause(self)
|
||||
|
||||
def set_state(self, state):
|
||||
if self.state == state:
|
||||
@@ -154,6 +161,8 @@ class CookingState:
|
||||
self.on_refresh(self)
|
||||
|
||||
def update_tick(self):
|
||||
if self.state == CookingStates.IDLE:
|
||||
return self.state
|
||||
if self.paused:
|
||||
self._notify_refresh()
|
||||
return self.state
|
||||
@@ -169,18 +178,20 @@ class CookingState:
|
||||
now = time.time()
|
||||
elapsed_time = self.get_elapsed_time()
|
||||
self.estimated_remaining_time = self.get_remaining_time_estimation()
|
||||
|
||||
print(elapsed_time, self.cook_time, self.current_dish_temp, self.target_temp, self._paused_duration, self._pause_started_at, now)
|
||||
|
||||
if self.current_dish_temp is not None:
|
||||
if elapsed_time < (self.cook_time / 2.0) and self.current_dish_temp >= self.target_temp:
|
||||
if elapsed_time < (self.cook_time / 2.0) and self.current_dish_temp >= self.target_temp and (self._paused_duration == None or self._paused_duration < 5): # If the dish is heating too fast, we require stirring
|
||||
self.state = CookingStates.STIRRING_REQUIRED
|
||||
self.pause()
|
||||
elif elapsed_time >= self.cook_time and self.current_dish_temp >= (self.target_temp - self.TEMPERATURE_TOLERANCE):
|
||||
self.state = CookingStates.DONE
|
||||
elif self.state == CookingStates.DONE and self.current_dish_temp < (self.target_temp - self.TEMPERATURE_TOLERANCE):
|
||||
self.state = CookingStates.COOKING
|
||||
elif elapsed_time >= self.cook_time * 1.25: # If the dish is not heating up
|
||||
elif elapsed_time >= self.cook_time * 1.25 and (self._paused_duration == None or self._paused_duration < 5): # If the dish is not heating up
|
||||
self.state = CookingStates.STIRRING_REQUIRED
|
||||
self.pause()
|
||||
elif self._pause_started_at != None and (self._pause_started_at + self._paused_duration) < (now - (self.cook_time * 0.75)): # If the dish had to be pause and it's been a long time, we stop the cooking
|
||||
self.state = CookingStates.DONE
|
||||
|
||||
self._last_temperature_sample = (now, self.current_dish_temp)
|
||||
|
||||
@@ -196,4 +207,11 @@ class CookingStates:
|
||||
STIRRING_REQUIRED = 1
|
||||
DONE = 2
|
||||
ALERT = 3 # Microwave is too hot internally or other alerts
|
||||
IDLE = 4 # Waiting for cooking parameters to be set, or after cooking is done
|
||||
IDLE = 4 # Waiting for cooking parameters to be set, or after cooking is done
|
||||
|
||||
@staticmethod
|
||||
def get_state_name(state_val):
|
||||
for key, value in CookingStates.__dict__.items():
|
||||
if value == state_val and not key.startswith('__'):
|
||||
return key
|
||||
return "UNKNOWN"
|
||||
Reference in New Issue
Block a user