From f4ae40eb19b17ac969920e9a5b5f8ad8edd7130a Mon Sep 17 00:00:00 2001 From: Simon Schirrmacher Date: Mon, 22 Apr 2024 21:17:53 +0200 Subject: [PATCH] updated multi coooker sensor properties and fixed ready_at property --- .../chunmi/cooker_multi/cooker_multi.py | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/miio/integrations/chunmi/cooker_multi/cooker_multi.py b/miio/integrations/chunmi/cooker_multi/cooker_multi.py index 8cf9d8a86..d7b3eff33 100644 --- a/miio/integrations/chunmi/cooker_multi/cooker_multi.py +++ b/miio/integrations/chunmi/cooker_multi/cooker_multi.py @@ -253,7 +253,7 @@ def stage(self) -> str: @property @sensor("Current temperature", unit="C") - def temperature(self) -> Optional[int]: + def temperature(self) -> int: """Current temperature, if idle. Example values: 29 @@ -262,30 +262,44 @@ def temperature(self) -> Optional[int]: @property @sensor("Cooking finish time") - def ready_at(self) -> datetime.datetime: + def ready_at(self) -> Optional[datetime.datetime]: """Remaining minutes of the cooking process.""" + + if self.mode != OperationMode.PreCook and self.mode != OperationMode.Running: + return None + return ( datetime.datetime.now() + datetime.timedelta( - 0, int(self.data["t_left"] + (self.data["t_pre"] * 60)) + minutes=self.remaining ) ).replace(second=0, microsecond=0) - + @property - @sensor("Cooking start delay") - def cooking_delayed(self) -> Optional[int]: - """Wait n minutes before cooking / scheduled cooking.""" - delay = int(self.data["t_pre"]) + @sensor("Cooking process time remaining in minutes") + def remaining(self) -> int: + """Remaining minutes of the cooking process. Includes optional precook phase.""" - if delay >= 0: - return delay + if self.mode != OperationMode.PreCook and self.mode != OperationMode.Running: + return 0 + + remaining_minutes = int(self.data["t_left"]/60) + if self.mode == OperationMode.PreCook: + remaining_minutes = int(self.data["t_pre"]) + + return remaining_minutes + + @property + @sensor("Cooking process delay time remaining in minutes (precook phase time remaining)") + def delay_remaining(self) -> int: + """Remaining minutes of the cooking delay (precook phase).""" - return None + return max(0, self.remaining - self.duration) @property - @sensor("Cooking duration") + @sensor("Cooking duration in minutes") def duration(self) -> int: - """Duration of the cooking process.""" + """Duration of the cooking process. Does not include optional precook phase.""" return int(self.data["t_cook"]) @property @@ -316,7 +330,7 @@ def favorite(self) -> None: class MultiCooker(Device): """Main class representing the multi cooker.""" - _supported_models = [*MODEL_MULTI] + _supported_models = [MODEL_MULTI] @command() def status(self) -> CookerStatus: