Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions electrasmart/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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":
Expand Down