From 2eadd80c072696692bb69ae8b149ec989f8102d6 Mon Sep 17 00:00:00 2001 From: Tucker Kern Date: Thu, 12 Jan 2023 18:26:52 -0700 Subject: [PATCH] Expose sleep_mode in appliance class --- msmart/device/AC/appliance.py | 13 +++++++++++++ msmart/device/AC/command.py | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/msmart/device/AC/appliance.py b/msmart/device/AC/appliance.py index 351e0a3c..f9180e66 100644 --- a/msmart/device/AC/appliance.py +++ b/msmart/device/AC/appliance.py @@ -82,6 +82,7 @@ def __init__(self, *args, **kwargs): self._eco_mode = False self._turbo_mode = False self._freeze_protection_mode = False + self._sleep_mode = False self._fahrenheit_unit = False # Display temperature in Fahrenheit self._display_on = False self._filter_alert = False @@ -183,6 +184,7 @@ def apply(self): cmd.eco_mode = self._eco_mode cmd.turbo_mode = self._turbo_mode cmd.freeze_protection_mode = self._freeze_protection_mode + cmd.sleep_mode = self._sleep_mode cmd.fahrenheit = self._fahrenheit_unit self._send_cmd(cmd, self._defer_update) finally: @@ -205,6 +207,7 @@ def update(self, res: state_response): self._eco_mode = res.eco_mode self._turbo_mode = res.turbo_mode self._freeze_protection_mode = res.freeze_protection_mode + self._sleep_mode = res.sleep_mode self._indoor_temperature = res.indoor_temperature self._outdoor_temperature = res.outdoor_temperature @@ -345,6 +348,16 @@ def freeze_protection_mode(self, enabled: bool): self._defer_update = True self._freeze_protection_mode = enabled + @property + def sleep_mode(self): + return self._sleep_mode + + @sleep_mode.setter + def sleep_mode(self, enabled: bool): + if self._updating: + self._defer_update = True + self._sleep_mode = enabled + @property def fahrenheit(self): return self._fahrenheit_unit diff --git a/msmart/device/AC/command.py b/msmart/device/AC/command.py index 87fbd172..529578a2 100644 --- a/msmart/device/AC/command.py +++ b/msmart/device/AC/command.py @@ -100,7 +100,7 @@ def __init__(self, device_type): self.swing_mode = 0 self.turbo_mode = False self.fahrenheit = True - self.sleep = False + self.sleep_mode = False self.freeze_protection_mode = False @property @@ -121,7 +121,7 @@ def payload(self): eco_mode = 0x80 if self.eco_mode else 0 # Build sleep, turbo and fahrenheit byte - sleep = 0x01 if self.sleep else 0 + sleep = 0x01 if self.sleep_mode else 0 turbo = 0x02 if self.turbo_mode else 0 fahrenheit = 0x04 if self.fahrenheit else 0 @@ -148,7 +148,7 @@ def payload(self): turbo_alt, # ECO mode eco_mode, - # Sleep, turbo mode and fahrenheit + # Sleep mode, turbo mode and fahrenheit sleep | turbo | fahrenheit, # Unknown 0x00, 0x00, 0x00, 0x00, @@ -506,7 +506,7 @@ def read_state(self, payload: memoryview): # self.clean_up = (payload[9] & 0x20) > 0 # self.temp_unit = (payload[9] & 0x80) > 0 - self.sleep = bool(payload[10] & 0x1) + self.sleep_mode = bool(payload[10] & 0x1) self.turbo_mode |= bool(payload[10] & 0x2) self.fahrenheit = bool(payload[10] & 0x4) # self.catch_cold = (payload[10] & 0x08) > 0