retry if material down /and resolve set_timer on specific port#63
retry if material down /and resolve set_timer on specific port#63vBlackOut wants to merge 2 commits intoclach04:masterfrom
Conversation
clach04
left a comment
There was a problem hiding this comment.
Thanks for looking to improve this! Some minor changes needed before they can be accepted
pytuya/__init__.py
Outdated
|
|
||
| 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.
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.
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.
sleep should be in the except block
There was a problem hiding this comment.
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.
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 |
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.
this looks like retry logic - use self.retry_count
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.
looks like retry logic, should use retry count
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.
I'm not entirely sure what this is doing - it needs an explanation
There was a problem hiding this comment.
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.