Skip to content
Snippets Groups Projects
Commit 2188fadb authored by jkerdreu's avatar jkerdreu
Browse files

0.7 migration

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2371 b32b6428-25c9-4566-ad07-03861ab6144f
parent d2357481
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ import logging
# to tenacity once again.
#from tenacity import *
from tenacity import retry,stop_after_attempt
from tenacity import retry,stop_after_attempt,RetryError
logger = logging.getLogger(__name__)
......@@ -42,7 +42,7 @@ class TuyaDev:
dev.hw_id = self.tuya_id
dev.info = 'Tuya device: %s @ %s' % (self.tuya_id,self.tuya_ip)
if len(self.devices) > 1:
dev.group_id = self.base_addr + 'ff'
dev.group_id = self.base_addr + 0xff
def update_status(self):
try:
......@@ -95,7 +95,7 @@ class OnOffMixing(object):
class PowerRelay(TuyaDev,OnOffMixing):
def setup(self):
relay = devices.powerrelay_toggle(self.base_addr + '00')
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)
......@@ -109,12 +109,12 @@ class PowerRelay(TuyaDev,OnOffMixing):
class SmartPlug(TuyaDev,OnOffMixing):
def setup(self):
# TBD switch to the right schema, but right now nothing exists
relay = devices.powerrelay_toggle(self.base_addr + '00')
relay = devices.powerrelay_toggle(self.base_addr)
relay.product_id = 'Tuya Smart Plug Outlet'
plug = pytuya.OutletDevice(self.tuya_id,self.tuya_ip,self.tuya_key)
self.setup_onoff(plug,relay)
pmeter = devices.powermeter(self.base_addr + '01')
pmeter = devices.powermeter(self.base_addr + 1)
pmeter.product_id = 'Tuya Smart Plug Power Meter'
pmeter.new_attribute('voltage')
pmeter.new_attribute('current')
......
......@@ -34,7 +34,8 @@ class GW:
self.cfg = cfg
def setup(self):
gw = schemas.devices.gateway(self.cfg['config']['addr'])
addr = tools.get_uuid(self.cfg['config']['addr'])
gw = schemas.devices.gateway(addr)
gw.vendor_id = 'IHSEV'
gw.product_id = 'Generic Tuya Gateway'
gw.info = 'Tuya Gateway'
......@@ -44,13 +45,14 @@ class GW:
devices = self.cfg.get('devices',[])
for d in devices:
cfg = devices.get(d,{})
base_addr = cfg.get('base_addr',None)
base_addr = tools.get_uuid(cfg.get('base_addr',None))
ip = cfg.get('ip',None)
key = cfg.get('key',None)
type_ = cfg.get('type','PowerRelay')
if base_addr == None:
cfg['base_addr'] = base_addr = tools.get_random_uuid()[:-2]
base_addr = tools.get_random_base_uuid()
cfg['base_addr'] = str(base_addr)
if ip and key:
self.add_device(d,key,ip,base_addr,type_)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment