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

Changed the way I handle inactive

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2511 b32b6428-25c9-4566-ad07-03861ab6144f
parent 289d021c
No related branches found
No related tags found
No related merge requests found
......@@ -68,10 +68,10 @@ class TuyaDev:
elif ev_type == tuyaclient.Event.CONNECTED:
self.request_dps()
self.parent.remove_inactive([k.address for k in self.devices])
self.parent.update_inactive()
elif ev_type == tuyaclient.Event.DISCONNECTED:
self.parent.add_inactive([k.address for k in self.devices])
self.parent.trigger_update_inactive()
def post_dps(self,data):
self.tuya_client.post_dps(data)
......
......@@ -20,15 +20,15 @@ CFG_MAP = { 'powerrelay' : devices.PowerRelay,
class GW:
def __init__(self,engine):
self.booted = False
self.engine = engine
self.devices = {}
atexit.register(self._exit)
self.config()
self.setup()
engine.add_timer(self.boot_inactive,10,1)
engine.add_timer(self.boot,10,1)
engine.add_timer(self.update,4*60)
def config(self):
cfg = tools.load_cfg(PACKAGE_NAME)
if not cfg:
......@@ -71,16 +71,24 @@ class GW:
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 trigger_update_inactive(self):
self.gw.engine.add_timer(self.update_inactive,5,1)
def boot(self):
logger.info('Booted')
self.booted = True
self.update_inactive()
def remove_inactive(self,addrs):
self.gw.attributes['inactive_embedded'] = list(set(self.gw.attributes['inactive_embedded']) - set(addrs))
def update_inactive(self):
if self.booted == False:
return
def boot_inactive(self):
for d in self.devices.values():
if not d.connected:
self.add_inactive([k.address for k in d.devices ])
r = []
for dev in self.devices.values():
if not dev.connected:
r = r + [k.address for k in dev.devices]
if set(self.gw.attributes['inactive_embedded']) != set(r):
self.gw.attributes['inactive_embedded'] = r
def update(self):
now = time.time()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment