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

Added inactive_embedded.

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2507 b32b6428-25c9-4566-ad07-03861ab6144f
parent 7a489398
No related branches found
No related tags found
No related merge requests found
......@@ -24,8 +24,19 @@ d3 = { 'ip' : '192.168.1.61','deviceid' : '74012545dc4f229f058f','localkey' : '
# shp-7
d4 = { 'ip' : '192.168.1.66', 'deviceid' : '42361312d8f15bd5a25d','localkey' : 'af6430180fd6dde7', 'protocol' : '3.3' }
# LSC edison
d5 = { 'ip' : '192.168.1.172', 'deviceid' : '40005734840d8e4d5500','localkey' : 'da6d966a4585ced5', 'protocol' : '3.3' }
# utorch rgb
d6 = { 'ip' : '192.168.1.162', 'deviceid' : '00747018f4cfa262ea13','localkey' : 'f598419fef804b7f', 'protocol' : '3.3' }
d0 = { 'ip' : '192.168.1.60', 'deviceid' : '42361312d8f15bd5a25d','localkey' : 'af6430180fd6dde7', 'protocol' : '3.3' }
devices = [d1,d2,d3,d4]
def color_to_hex(hsv):
......
......@@ -25,8 +25,10 @@ class GW:
atexit.register(self._exit)
self.config()
self.setup()
engine.add_timer(self.boot_inactive,10,1)
engine.add_timer(self.update,4*60)
def config(self):
cfg = tools.load_cfg(PACKAGE_NAME)
if not cfg:
......@@ -43,6 +45,7 @@ class GW:
gw.product_id = 'Generic Tuya Gateway'
gw.info = 'Tuya Gateway'
gw.attributes['embedded'] = []
gw.new_attribute('inactive_embedded',[])
self.gw = gw
devs = self.cfg.get('devices',[])
......@@ -51,7 +54,7 @@ class GW:
tmp = cfg.get('type','PowerRelay')
dev_type = CFG_MAP.get(tmp,None)
if dev_type:
dev = dev_type(d,cfg)
dev = dev_type(d,cfg,self)
if dev.is_valid:
self.add_device(d,dev)
else:
......@@ -67,8 +70,18 @@ class GW:
for d in dev.devices:
self.engine.add_device(d)
self.gw.attributes['embedded'].append(d.address)
def add_inactive(self,addrs):
self.gw.attributes['inactive_embedded'] = list(set(self.gw.attributes['inactive_embedded'] + addrs))
def remove_inactive(self,addrs):
self.gw.attributes['inactive_embedded'] = list(set(self.gw.attributes['inactive_embedded']) - set(addrs))
def boot_inactive(self):
for d in self.devices.values():
if not d.connected:
self.add_inactive([k.address for k in d.devices ])
def update(self):
now = time.time()
for dev in self.devices.values():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment