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

- better state handling

- support for shutters added


git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2698 b32b6428-25c9-4566-ad07-03861ab6144f
parent 55ab7dcc
No related branches found
No related tags found
No related merge requests found
[config]
addr = 194f2490-155d-11ec-a7e9-d6bd5fe18726
base_port = 49000
[devices]
[[lampe bureau]]
......
......@@ -8,6 +8,12 @@ logger = logging.getLogger()
monitor = None
on_off = ['off','on']
MAP = {
'lamp': ['turn_on','turn_off','light'],
'powerrelay': ['turn_on','turn_off','power'],
'shutter': ['up','down',None],
}
def setup(device,filter_func):
global monitor
......@@ -22,11 +28,6 @@ def send(addr,action,body=None):
eng = monitor.engine
eng.send_request(monitor.dev,[addr,],action,body)
MAP = {
'lamp': ['turn_on','turn_off','light'],
'powerrelay': ['turn_on','turn_off','power'],
}
class XAALPlugin(FauxmoPlugin):
def setup(self,targets):
self.targets = targets
......@@ -45,11 +46,13 @@ class XAALPlugin(FauxmoPlugin):
for k in MAP.keys():
if device.dev_type.startswith(k):
return MAP[k]
logger.warning(f"Unable to find mapping for {device}")
return None
def on(self):
for dev in self.get_devices():
tmp = self.get_mapping(dev)
if tmp == None: continue
if tmp[0]:
send(dev.address,tmp[0])
return True
......@@ -57,16 +60,30 @@ class XAALPlugin(FauxmoPlugin):
def off(self):
for dev in self.get_devices():
tmp = self.get_mapping(dev)
if tmp == None: continue
if tmp[1]:
send(dev.address,tmp[1])
return True
def get_state(self):
"loops throught devices to find a least one w/ the right state"
for dev in self.get_devices():
tmp = self.get_mapping(dev)
if tmp == None: continue
if tmp[2]:
value = dev.attributes.get(tmp[2],None)
if value == None: continue
if value == True:
return 'on'
return 'off'
if on_off[value] == self._latest_action:
return self._latest_action
else:
# fake state
return self._latest_action
# no device found with the right state, so send
# the current state instead. sending "unknown"
# should be better, but it raise a big warning
if self._latest_action == 'on':
return 'off'
return 'on'
......@@ -31,7 +31,6 @@ class GW(object):
cfg = tools.load_cfg(PACKAGE_NAME)
if not cfg:
cfg= tools.new_cfg(PACKAGE_NAME)
cfg['config']['base_port'] = 49000
cfg['devices'] = {}
logger.warn("Created an empty config file")
cfg.write()
......@@ -49,7 +48,6 @@ class GW(object):
binding.setup(gw,self.filter)
def filter(self,msg):
#import pdb;pdb.set_trace()
if msg.source in self.addrs:
return True
return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment