Skip to content
Snippets Groups Projects
Commit 72de146a authored by jkerdreu's avatar jkerdreu
Browse files

Some debugging again & again

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2417 b32b6428-25c9-4566-ad07-03861ab6144f
parent 892f9f49
No related branches found
No related tags found
No related merge requests found
......@@ -9,9 +9,13 @@ when this gateway is running. This should be ok, but attributes can be out of
sync. The gateway polls devices state every 30 seconds but due to socket error,
this can be a little longuer.
This gateway use a forked github pytuya lib. The main reason: The official one
doesn't support outlet w/ version 3.3 of the protocol which seems to be the
default now.
The pytuya binding version 7.0.5 fixes the issue with version 3.3 devices.
The complete guide to extract keys is there:
- https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md
Notes :
pytuya send commmands (including updates) with socket in no-wait mode, and close
it at each request. I have a lot of random connection reset by peer, so I decided
to use tenacity. The main issue is that tuya devices close every connection after
10 seconds, so doing something else isn't really easy.
\ No newline at end of file
......@@ -50,13 +50,14 @@ class TuyaDev:
except RetryError as e:
logger.warn(e)
#@retry(stop=stop_after_attempt(2),wait=wait_fixed(0.15), before_sleep=before_sleep_log(logger, logging.DEBUG))
@retry(stop=stop_after_attempt(2))
def _update_status(self):
#time.sleep(0.1)
logger.info("Updating %s" % self.tuya_id)
time.sleep(0.15)
#logger.info("Updating %s" % self.tuya_id)
self.last_update = now()
status = self.tuya_dev.status()
logger.warning(status)
#logger.warning(status)
self.on_status(status)
def on_status(self,status):
......@@ -71,14 +72,15 @@ class OnOffMixing(object):
xaal_dev.methods['on'] = self.on
xaal_dev.methods['off'] = self.off
xaal_dev.methods['toggle'] = self.toggle
xaal_dev.methods['update'] = self.update_status
self.xaal_dev = xaal_dev
@retry(stop=stop_after_attempt(2))
@retry(stop=stop_after_attempt(3))
def on(self):
self.tuya_dev.turn_on()
self.update_status()
@retry(stop=stop_after_attempt(2))
@retry(stop=stop_after_attempt(3))
def off(self):
self.tuya_dev.turn_off()
self.update_status()
......@@ -98,7 +100,6 @@ class PowerRelay(TuyaDev,OnOffMixing):
relay = devices.powerrelay_toggle(self.base_addr)
relay.product_id = 'Generic Tuya Outlet'
outlet = pytuya.OutletDevice(self.tuya_id,self.tuya_ip,self.tuya_key)
outlet.set_version(3.3)
self.setup_onoff(outlet,relay)
self.devices.append(relay)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment