Skip to content

Commit

Permalink
Get status after POST
Browse files Browse the repository at this point in the history
  • Loading branch information
rubeecube committed Dec 9, 2022
1 parent 8135568 commit 7651252
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions electrasmart/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 7651252

Please sign in to comment.