Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Added retry logic to improve state change success #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
12 changes: 9 additions & 3 deletions pytuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,15 @@ def set_status(self, on, switch=1):
switch = str(switch) # index and payload is a string
payload = self.generate_payload(SET, {switch:on})
#print('payload %r' % payload)

data = self._send_receive(payload)
log.debug('set_status received data=%r', data)
for i in range(3):
try:
data = self._send_receive(payload)
log.debug('set_status received data=%r', data)
except Exception:
if i == 2:
raise Exception('set_status failed after 3 consecutive attempts')
else:
continue

return data

Expand Down