diff --git a/electrasmart/client.py b/electrasmart/client.py index db1b08b..218c01e 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -142,6 +142,7 @@ def __init__(self, imei, token, ac_id, sid=None, use_single_sid=False): self.sid = sid self._status = None self._model = None + self.last_update_status = None def renew_sid(self): try: @@ -155,6 +156,7 @@ def renew_sid(self): def update_status(self): self._status = self._fetch_status() + self.last_update_status = datetime.now() @property def status(self): @@ -193,8 +195,9 @@ def _parse_status_group(cls, v): return json.loads(v) @contextmanager - def _modify_oper_and_send_command(self): - self.update_status() + def _modify_oper_and_send_command(self, update_status=True): + if self._status is None or update_status: + self.update_status() new_oper = self.status.raw["OPER"]["OPER"].copy() # make any needed modifications inplace within the context yield new_oper @@ -213,8 +216,9 @@ def modify_oper( shabat=None, ac_sleep=None, ifeel=None, + update_status=True, ): - with self._modify_oper_and_send_command() as oper: + with self._modify_oper_and_send_command(update_status=update_status) as oper: if ac_mode is not None: if self.model.on_off_flag: if ac_mode == "STBY":