From 7651252dea3d0ee80c134ab1e80683475275a366 Mon Sep 17 00:00:00 2001 From: Ruben Date: Fri, 9 Dec 2022 02:58:35 +0200 Subject: [PATCH 01/11] Get status after POST --- electrasmart/client.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index a1d0772..f9534e1 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -198,13 +198,24 @@ def _modify_oper_and_send_command(self): new_oper = self.status.raw["OPER"]["OPER"].copy() # make any needed modifications inplace within the context yield new_oper - self._post_with_sid_check( + r = self._post_with_sid_check( "SEND_COMMAND", dict(id=self.ac_id, commandJson=json.dumps({"OPER": new_oper})), ) + cj = r["commandJson"] + self._status = {k: self._parse_status_group(v) for k, v in cj.items()} def modify_oper( - self, *, ac_mode=None, fan_speed=None, temperature=None, ac_stsrc="WI-FI", permissive_args=False, **kwargs): + self, + *, + ac_mode=None, + fan_speed=None, + temperature=None, + ac_stsrc="WI-FI", + shabat=None, + ac_sleep=None, + ifeel=None, + ): with self._modify_oper_and_send_command() as oper: if ac_mode is not None: if self.model.on_off_flag: @@ -229,19 +240,12 @@ def modify_oper( oper["SPT"] = temperature if ac_stsrc is not None and "AC_STSRC" in oper: oper["AC_STSRC"] = ac_stsrc - - for k, v in kwargs.items(): - if permissive_args: - # Fallback for easyfix next time - if k in oper: - oper[k] = v - else: - if k == "SHABAT" and "SHABAT" in oper: - oper["SHABAT"] = v - if k == "SLEEP" and "SLEEP" in oper: - oper["SLEEP"] = v - if k == "IFEEL" and "IFEEL" in oper: - oper["IFEEL"] = v + if shabat is not None and "SHABAT" in oper: + oper["SHABAT"] = shabat + if ac_sleep is not None and "SLEEP" in oper: + oper["SLEEP"] = ac_sleep + if ifeel is not None and "IFEEL" in oper: + oper["IFEEL"] = ifeel def turn_off(self): with self._modify_oper_and_send_command() as oper: From 01c6f2b1dcb4247b332fe93335efeac7191f673b Mon Sep 17 00:00:00 2001 From: Ruben Date: Fri, 9 Dec 2022 03:08:06 +0200 Subject: [PATCH 02/11] Revert "Get status after POST" This reverts commit 7651252dea3d0ee80c134ab1e80683475275a366. --- electrasmart/client.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index f9534e1..a1d0772 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -198,24 +198,13 @@ def _modify_oper_and_send_command(self): new_oper = self.status.raw["OPER"]["OPER"].copy() # make any needed modifications inplace within the context yield new_oper - r = self._post_with_sid_check( + self._post_with_sid_check( "SEND_COMMAND", dict(id=self.ac_id, commandJson=json.dumps({"OPER": new_oper})), ) - cj = r["commandJson"] - self._status = {k: self._parse_status_group(v) for k, v in cj.items()} def modify_oper( - self, - *, - ac_mode=None, - fan_speed=None, - temperature=None, - ac_stsrc="WI-FI", - shabat=None, - ac_sleep=None, - ifeel=None, - ): + self, *, ac_mode=None, fan_speed=None, temperature=None, ac_stsrc="WI-FI", permissive_args=False, **kwargs): with self._modify_oper_and_send_command() as oper: if ac_mode is not None: if self.model.on_off_flag: @@ -240,12 +229,19 @@ def modify_oper( oper["SPT"] = temperature if ac_stsrc is not None and "AC_STSRC" in oper: oper["AC_STSRC"] = ac_stsrc - if shabat is not None and "SHABAT" in oper: - oper["SHABAT"] = shabat - if ac_sleep is not None and "SLEEP" in oper: - oper["SLEEP"] = ac_sleep - if ifeel is not None and "IFEEL" in oper: - oper["IFEEL"] = ifeel + + for k, v in kwargs.items(): + if permissive_args: + # Fallback for easyfix next time + if k in oper: + oper[k] = v + else: + if k == "SHABAT" and "SHABAT" in oper: + oper["SHABAT"] = v + if k == "SLEEP" and "SLEEP" in oper: + oper["SLEEP"] = v + if k == "IFEEL" and "IFEEL" in oper: + oper["IFEEL"] = v def turn_off(self): with self._modify_oper_and_send_command() as oper: From 374f0aab11b9f4b26e66931cbbaa6321d3e6991b Mon Sep 17 00:00:00 2001 From: Ruben Date: Sat, 10 Dec 2022 19:25:08 +0200 Subject: [PATCH 03/11] Add Async update --- electrasmart/client.py | 117 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 103 insertions(+), 14 deletions(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index a1d0772..6c593c4 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -6,6 +6,8 @@ import requests import logging +import aiohttp +import asyncio logger = logging.getLogger(__name__) @@ -52,6 +54,39 @@ def post(cls, cmd, data, sid=None, os_details=False, is_second_try=False): raise cls.RenewSidAndRetryException(j) return j["data"] + @classmethod + async def async_post(cls, cmd, data, sid=None, os_details=False, is_second_try=False): + if os_details: + data = data.copy() + data.update(cls.MOCK_OS_DATA) + random_id = random.randint(1000, 1999) + post_data = dict(pvdid=1, id=random_id, sid=sid, cmd=cmd, data=data) + logger.debug( + f"[ASYNC] Posting request\nid: {random_id}\nurl: {cls.URL}\nheaders: {cls.HEADERS}\n" + f"[ASYNC] post json data:\n{pformat(post_data)}" + ) + try: + async with aiohttp.ClientSession() as session: + async with session.post(cls.URL, headers=cls.HEADERS, json=post_data) as response: + j = await response.json(content_type=None) + except: + logger.exception( + "[ASYNC] ElectraAPI: Exception caught when posting to cloud service" + ) + raise + logger.debug(f"[ASYNC] Response received (id={random_id}):\n{pformat(j)}") + if is_second_try: + try: + assert j["status"] == 0, "invalid status returned from command" + assert j["data"]["res"] == 0, "invalid res returned from command" + except: + logger.exception(f"Error status when posting command") + raise + else: + if j["status"] != 0 or j["data"] is None or j["data"]["res"] != 0: + raise cls.RenewSidAndRetryException(j) + return j["data"] + # raised upon failure in the first try of a post class RenewSidAndRetryException(Exception): def __init__(self, post_response): @@ -104,6 +139,13 @@ def generate_sid(imei, token): return result["sid"] +async def async_generate_sid(imei, token): + result = await ElectraAPI.async_post( + "VALIDATE_TOKEN", dict(imei=imei, token=token), os_details=True + ) + return result["sid"] + + def get_shared_sid(imei, token): date_now = datetime.now() if ( @@ -118,6 +160,20 @@ def get_shared_sid(imei, token): return ElectraAPI.SID +async def async_get_shared_sid(imei, token): + date_now = datetime.now() + if ( + ElectraAPI.SID is None + or ElectraAPI.LAST_SID_UPDATE_DATETIME is None + or date_diff_in_seconds(date_now, ElectraAPI.LAST_SID_UPDATE_DATETIME) + > ElectraAPI.MIN_TIME_BETWEEN_SID_UPDATES + ): + ElectraAPI.SID = await async_generate_sid(imei, token) + ElectraAPI.LAST_SID_UPDATE_DATETIME = date_now + logger.info(f"renewed shared sid: {ElectraAPI.SID}") + return ElectraAPI.SID + + def date_diff_in_seconds(dt2, dt1): timedelta = dt2 - dt1 return timedelta.total_seconds() @@ -153,9 +209,22 @@ def renew_sid(self): except ElectraAPI.RenewSidAndRetryException as exc: raise Exception(f"Failed to renew sid: {exc.res_desc}") + async def async_renew_sid(self): + try: + if self.use_singe_sid: + self.sid = get_shared_sid(self.imei, self.token) + else: + self.sid = await async_generate_sid(self.imei, self.token) + logger.debug(f"renewed sid: {self.sid}") + except ElectraAPI.RenewSidAndRetryException as exc: + raise Exception(f"Failed to renew sid: {exc.res_desc}") + def update_status(self): self._status = self._fetch_status() + async def async_update_status(self): + self._status = await self._async_fetch_status() + @property def status(self): if self._status is None: @@ -170,6 +239,14 @@ def _fetch_status(self): status = {k: self._parse_status_group(v) for k, v in cj.items()} return status + async def _async_fetch_status(self): + r = await self._async_post_with_sid_check( + "GET_LAST_TELEMETRY", dict(id=self.ac_id, commandName="OPER,DIAG_L2,HB") + ) + cj = r["commandJson"] + status = {k: self._parse_status_group(v) for k, v in cj.items()} + return status + def _post_with_sid_check(self, cmd, data, os_details=False): try: return self._post(cmd, data, os_details, False) @@ -177,9 +254,19 @@ def _post_with_sid_check(self, cmd, data, os_details=False): self.renew_sid() return self._post(cmd, data, os_details, True) + async def _async_post_with_sid_check(self, cmd, data, os_details=False): + try: + return await self._async_post(cmd, data, os_details, False) + except ElectraAPI.RenewSidAndRetryException: + await self.async_renew_sid() + return await self._async_post(cmd, data, os_details, True) + def _post(self, cmd, data, os_details=False, is_second_try=False): return ElectraAPI.post(cmd, data, self._get_sid(), os_details, is_second_try) + async def _async_post(self, cmd, data, os_details=False, is_second_try=False): + return await ElectraAPI.async_post(cmd, data, self._get_sid(), os_details, is_second_try) + def _get_sid(self): if self.use_singe_sid: return ElectraAPI.SID @@ -204,7 +291,16 @@ def _modify_oper_and_send_command(self): ) def modify_oper( - self, *, ac_mode=None, fan_speed=None, temperature=None, ac_stsrc="WI-FI", permissive_args=False, **kwargs): + self, + *, + ac_mode=None, + fan_speed=None, + temperature=None, + ac_stsrc="WI-FI", + shabat=None, + ac_sleep=None, + ifeel=None, + ): with self._modify_oper_and_send_command() as oper: if ac_mode is not None: if self.model.on_off_flag: @@ -229,19 +325,12 @@ def modify_oper( oper["SPT"] = temperature if ac_stsrc is not None and "AC_STSRC" in oper: oper["AC_STSRC"] = ac_stsrc - - for k, v in kwargs.items(): - if permissive_args: - # Fallback for easyfix next time - if k in oper: - oper[k] = v - else: - if k == "SHABAT" and "SHABAT" in oper: - oper["SHABAT"] = v - if k == "SLEEP" and "SLEEP" in oper: - oper["SLEEP"] = v - if k == "IFEEL" and "IFEEL" in oper: - oper["IFEEL"] = v + if shabat is not None and "SHABAT" in oper: + oper["SHABAT"] = shabat + if ac_sleep is not None and "SLEEP" in oper: + oper["SLEEP"] = ac_sleep + if ifeel is not None and "IFEEL" in oper: + oper["IFEEL"] = ifeel def turn_off(self): with self._modify_oper_and_send_command() as oper: From 9dcab86a226e7d8f7e40520b2886d03651b61bb2 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sat, 10 Dec 2022 20:08:41 +0200 Subject: [PATCH 04/11] Add Async update --- electrasmart/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index 6c593c4..74ac033 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -212,7 +212,7 @@ def renew_sid(self): async def async_renew_sid(self): try: if self.use_singe_sid: - self.sid = get_shared_sid(self.imei, self.token) + self.sid = await async_get_shared_sid(self.imei, self.token) else: self.sid = await async_generate_sid(self.imei, self.token) logger.debug(f"renewed sid: {self.sid}") From ffa4a6b6b87fc3bcf9672450fa5cea91f95d5d5b Mon Sep 17 00:00:00 2001 From: Ruben Date: Sat, 10 Dec 2022 20:37:04 +0200 Subject: [PATCH 05/11] Updates for lint --- electrasmart/client.py | 48 ++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index 74ac033..d14d705 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -55,7 +55,9 @@ def post(cls, cmd, data, sid=None, os_details=False, is_second_try=False): return j["data"] @classmethod - async def async_post(cls, cmd, data, sid=None, os_details=False, is_second_try=False): + async def async_post( + cls, cmd, data, sid=None, os_details=False, is_second_try=False + ): if os_details: data = data.copy() data.update(cls.MOCK_OS_DATA) @@ -67,7 +69,9 @@ async def async_post(cls, cmd, data, sid=None, os_details=False, is_second_try=F ) try: async with aiohttp.ClientSession() as session: - async with session.post(cls.URL, headers=cls.HEADERS, json=post_data) as response: + async with session.post( + cls.URL, headers=cls.HEADERS, json=post_data + ) as response: j = await response.json(content_type=None) except: logger.exception( @@ -110,7 +114,7 @@ def send_otp_request(phone): :return: imei """ # generate a random imei with a valid prefix (note: this might not be checked today, but just in case) - imei = f"2b950000{random.randint(10**7, 10**8-1)}" + imei = f"2b950000{random.randint(10 ** 7, 10 ** 8 - 1)}" ElectraAPI.post("SEND_OTP", dict(imei=imei, phone=phone)) return imei @@ -149,10 +153,10 @@ async def async_generate_sid(imei, token): def get_shared_sid(imei, token): date_now = datetime.now() if ( - ElectraAPI.SID is None - or ElectraAPI.LAST_SID_UPDATE_DATETIME is None - or date_diff_in_seconds(date_now, ElectraAPI.LAST_SID_UPDATE_DATETIME) - > ElectraAPI.MIN_TIME_BETWEEN_SID_UPDATES + ElectraAPI.SID is None + or ElectraAPI.LAST_SID_UPDATE_DATETIME is None + or date_diff_in_seconds(date_now, ElectraAPI.LAST_SID_UPDATE_DATETIME) + > ElectraAPI.MIN_TIME_BETWEEN_SID_UPDATES ): ElectraAPI.SID = generate_sid(imei, token) ElectraAPI.LAST_SID_UPDATE_DATETIME = date_now @@ -163,10 +167,10 @@ def get_shared_sid(imei, token): async def async_get_shared_sid(imei, token): date_now = datetime.now() if ( - ElectraAPI.SID is None - or ElectraAPI.LAST_SID_UPDATE_DATETIME is None - or date_diff_in_seconds(date_now, ElectraAPI.LAST_SID_UPDATE_DATETIME) - > ElectraAPI.MIN_TIME_BETWEEN_SID_UPDATES + ElectraAPI.SID is None + or ElectraAPI.LAST_SID_UPDATE_DATETIME is None + or date_diff_in_seconds(date_now, ElectraAPI.LAST_SID_UPDATE_DATETIME) + > ElectraAPI.MIN_TIME_BETWEEN_SID_UPDATES ): ElectraAPI.SID = await async_generate_sid(imei, token) ElectraAPI.LAST_SID_UPDATE_DATETIME = date_now @@ -265,7 +269,9 @@ def _post(self, cmd, data, os_details=False, is_second_try=False): return ElectraAPI.post(cmd, data, self._get_sid(), os_details, is_second_try) async def _async_post(self, cmd, data, os_details=False, is_second_try=False): - return await ElectraAPI.async_post(cmd, data, self._get_sid(), os_details, is_second_try) + return await ElectraAPI.async_post( + cmd, data, self._get_sid(), os_details, is_second_try + ) def _get_sid(self): if self.use_singe_sid: @@ -291,15 +297,15 @@ def _modify_oper_and_send_command(self): ) def modify_oper( - self, - *, - ac_mode=None, - fan_speed=None, - temperature=None, - ac_stsrc="WI-FI", - shabat=None, - ac_sleep=None, - ifeel=None, + self, + *, + ac_mode=None, + fan_speed=None, + temperature=None, + ac_stsrc="WI-FI", + shabat=None, + ac_sleep=None, + ifeel=None, ): with self._modify_oper_and_send_command() as oper: if ac_mode is not None: From 63f27774214cd4dfa422fd76db81ef48140e3257 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sat, 10 Dec 2022 20:40:36 +0200 Subject: [PATCH 06/11] Updates for lint --- electrasmart/client.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index d14d705..c98173d 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -56,7 +56,7 @@ def post(cls, cmd, data, sid=None, os_details=False, is_second_try=False): @classmethod async def async_post( - cls, cmd, data, sid=None, os_details=False, is_second_try=False + cls, cmd, data, sid=None, os_details=False, is_second_try=False ): if os_details: data = data.copy() @@ -70,7 +70,7 @@ async def async_post( try: async with aiohttp.ClientSession() as session: async with session.post( - cls.URL, headers=cls.HEADERS, json=post_data + cls.URL, headers=cls.HEADERS, json=post_data ) as response: j = await response.json(content_type=None) except: @@ -153,10 +153,10 @@ async def async_generate_sid(imei, token): def get_shared_sid(imei, token): date_now = datetime.now() if ( - ElectraAPI.SID is None - or ElectraAPI.LAST_SID_UPDATE_DATETIME is None - or date_diff_in_seconds(date_now, ElectraAPI.LAST_SID_UPDATE_DATETIME) - > ElectraAPI.MIN_TIME_BETWEEN_SID_UPDATES + ElectraAPI.SID is None + or ElectraAPI.LAST_SID_UPDATE_DATETIME is None + or date_diff_in_seconds(date_now, ElectraAPI.LAST_SID_UPDATE_DATETIME) + > ElectraAPI.MIN_TIME_BETWEEN_SID_UPDATES ): ElectraAPI.SID = generate_sid(imei, token) ElectraAPI.LAST_SID_UPDATE_DATETIME = date_now @@ -167,10 +167,10 @@ def get_shared_sid(imei, token): async def async_get_shared_sid(imei, token): date_now = datetime.now() if ( - ElectraAPI.SID is None - or ElectraAPI.LAST_SID_UPDATE_DATETIME is None - or date_diff_in_seconds(date_now, ElectraAPI.LAST_SID_UPDATE_DATETIME) - > ElectraAPI.MIN_TIME_BETWEEN_SID_UPDATES + ElectraAPI.SID is None + or ElectraAPI.LAST_SID_UPDATE_DATETIME is None + or date_diff_in_seconds(date_now, ElectraAPI.LAST_SID_UPDATE_DATETIME) + > ElectraAPI.MIN_TIME_BETWEEN_SID_UPDATES ): ElectraAPI.SID = await async_generate_sid(imei, token) ElectraAPI.LAST_SID_UPDATE_DATETIME = date_now @@ -297,15 +297,15 @@ def _modify_oper_and_send_command(self): ) def modify_oper( - self, - *, - ac_mode=None, - fan_speed=None, - temperature=None, - ac_stsrc="WI-FI", - shabat=None, - ac_sleep=None, - ifeel=None, + self, + *, + ac_mode=None, + fan_speed=None, + temperature=None, + ac_stsrc="WI-FI", + shabat=None, + ac_sleep=None, + ifeel=None, ): with self._modify_oper_and_send_command() as oper: if ac_mode is not None: From f2864585a3fb8e74eaeaa147be766b654ed22a84 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 18 Dec 2022 11:20:31 +0200 Subject: [PATCH 07/11] Add option to the caller to not always get the status online (in case the update is managed by the caller) --- electrasmart/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index db1b08b..bba6e3e 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 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": From 7c21027b0380c482dab20f23a638688ff7969f03 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 18 Dec 2022 11:22:22 +0200 Subject: [PATCH 08/11] Add option to the caller to not always get the status online (in case the update is managed by the caller) --- electrasmart/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index bba6e3e..b28762c 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -196,7 +196,7 @@ def _parse_status_group(cls, v): @contextmanager def _modify_oper_and_send_command(self, update_status=True): - if update_status: + 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 From ed0a1eee11a4b1aeaeb19234291e0a22fd309a72 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 18 Dec 2022 11:24:35 +0200 Subject: [PATCH 09/11] Add option to the caller to not always get the status online (in case the update is managed by the caller) --- electrasmart/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index b28762c..218c01e 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -216,7 +216,7 @@ def modify_oper( shabat=None, ac_sleep=None, ifeel=None, - update_status=True + update_status=True, ): with self._modify_oper_and_send_command(update_status=update_status) as oper: if ac_mode is not None: From f099e4aba2ea4be607f24fa652909e81d0f2e131 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 18 Dec 2022 11:55:03 +0200 Subject: [PATCH 10/11] Cache operoper sent to server --- electrasmart/client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index 4d8ab4c..cd27e21 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -224,8 +224,11 @@ async def async_renew_sid(self): except ElectraAPI.RenewSidAndRetryException as exc: raise Exception(f"Failed to renew sid: {exc.res_desc}") - def update_status(self): - self._status = self._fetch_status() + def update_status(self, operoper_dict=None): + if operoper_dict is None: + self._status = self._fetch_status() + else: + self._status["OPER"]["OPER"] = operoper_dict.copy() self.last_update_status = datetime.now() async def async_update_status(self): @@ -298,6 +301,7 @@ def _modify_oper_and_send_command(self, update_status=True): "SEND_COMMAND", dict(id=self.ac_id, commandJson=json.dumps({"OPER": new_oper})), ) + self.update_status(operoper_dict=new_oper) def modify_oper( self, From d36141fd189dc146fd112a6883915eb8bb257843 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 18 Dec 2022 11:58:51 +0200 Subject: [PATCH 11/11] Cache operoper sent to server --- electrasmart/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/electrasmart/client.py b/electrasmart/client.py index cd27e21..21b461e 100644 --- a/electrasmart/client.py +++ b/electrasmart/client.py @@ -346,8 +346,8 @@ def modify_oper( if ifeel is not None and "IFEEL" in oper: oper["IFEEL"] = ifeel - def turn_off(self): - with self._modify_oper_and_send_command() as oper: + def turn_off(self, update_status=True): + with self._modify_oper_and_send_command(update_status=update_status) as oper: if self.model.on_off_flag: oper["TURN_ON_OFF"] = "OFF" else: