-
Notifications
You must be signed in to change notification settings - Fork 55
retry if material down /and resolve set_timer on specific port #63
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking to improve this! Some minor changes needed before they can be accepted
pytuya/__init__.py
Outdated
@@ -136,18 +136,18 @@ def hex2bin(x): | |||
} | |||
|
|||
class XenonDevice(object): | |||
def __init__(self, dev_id, address, local_key=None, dev_type=None, connection_timeout=10): | |||
def __init__(self, dev_id, address, local_key=None, dev_type=None, connection_timeout=20): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeout should stay the same.
retry code below is a nice idea, this should be a parameter and default to 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the connect WiFi is slow the material didn't réponse correctly
pytuya/__init__.py
Outdated
s.connect((self.address, self.port)) | ||
except (ConnectionRefusedError, ConnectionAbortedError): | ||
pass | ||
time.sleep(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sleep should be in the except block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if don't wait your send so fast request and don't wait correctly for retry connection
pytuya/__init__.py
Outdated
try: | ||
s.connect((self.address, self.port)) | ||
except (ConnectionRefusedError, ConnectionAbortedError): | ||
for i in range(0, 3): | ||
try: | ||
s.connect((self.address, self.port)) | ||
except (ConnectionRefusedError, ConnectionAbortedError): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this tries 4 times. Remove one of the try/except blocks and move into a for loop.
retry cont should come from self.retry_count (set in __init__
)
pytuya/__init__.py
Outdated
# try/except for resolve connection reset error. | ||
try: | ||
data = s.recv(1024) | ||
except: | ||
s.close() | ||
return None | ||
s.close() | ||
return data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be in a try/finally
pytuya/__init__.py
Outdated
if self.set_status(True, switch) == None: | ||
for i in range(0, 3): | ||
if self.set_status(True, switch) == None: | ||
continue | ||
else: | ||
return True | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like retry logic - use self.retry_count
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes correctly
pytuya/__init__.py
Outdated
if self.set_status(False, switch) == None: | ||
for i in range(0, 3): | ||
if self.set_status(False, switch) == None: | ||
continue | ||
else: | ||
return True | ||
return False | ||
else: | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like retry logic, should use retry count
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again correctly
pytuya/__init__.py
Outdated
dps_id = devices_numbers[-1] | ||
print(devices_numbers) | ||
dps_list = [] | ||
for dps in devices_numbers: | ||
if int(dps) > 5: | ||
dps_list.append(int(dps)) | ||
dps_list.sort() | ||
|
||
if number_dps >= 1 and number_dps <=4: | ||
number_dps = number_dps-1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure what this is doing - it needs an explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum if for detect the plug number > 4 but the return true or false or numerical I check for fix last time
No description provided.