Skip to content
Snippets Groups Projects
Commit 98df4c9d authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Fix issue w/ latest version of Fauxmo

Fauxmo 0.8 has somne issues.
parent a221da5c
Branches
No related tags found
No related merge requests found
......@@ -32,3 +32,9 @@ The configuration (`fauxmo.ini`) file looks like this :
Device name are the name that will be used to control the device with the Amazon Echo.
The `targets` field is a list of xAAL device UUIDs that will be controlled.
Note
----
Fauxmo version 0.8 cause errors while getting _latest_action. I stick w/ 0.7 version
right now. It looks like Fauxmo had some work done. I need to check if nested async
is still needed.
......@@ -9,7 +9,7 @@ authors = [
license = { text = "GPL License" }
classifiers = ["Programming Language :: Python", "Topic :: Home Automation"]
keywords = ["xaal", "wemo", "alexa"]
dependencies = ["xaal.lib", "fauxmo", "nest_asyncio"]
dependencies = ["xaal.lib", "fauxmo==0.7", "nest_asyncio"]
[tool.setuptools.packages.find]
......
......@@ -3,10 +3,6 @@ import asyncio
from fauxmo.plugins import FauxmoPlugin
from xaal.monitor import Monitor
import time
import asyncio
import nest_asyncio
nest_asyncio.apply()
......@@ -29,10 +25,12 @@ def setup(device,filter_func):
return monitor
def get_device(addr):
assert monitor
return monitor.devices.get_with_addr(addr)
def send(addr,action,body=None):
assert monitor
eng = monitor.engine
eng.send_request(monitor.dev,[addr,],action,body)
......@@ -49,7 +47,7 @@ class XAALPlugin(FauxmoPlugin):
return r
def get_mapping(self,device):
if device.dev_type == None:
if device.dev_type is None:
return None
for k in MAP.keys():
if device.dev_type.startswith(k):
......@@ -60,7 +58,8 @@ class XAALPlugin(FauxmoPlugin):
def on(self):
for dev in self.get_devices():
tmp = self.get_mapping(dev)
if tmp == None: continue
if tmp is None:
continue
if tmp[0]:
send(dev.address,tmp[0])
return True
......@@ -68,7 +67,8 @@ class XAALPlugin(FauxmoPlugin):
def off(self):
for dev in self.get_devices():
tmp = self.get_mapping(dev)
if tmp == None: continue
if tmp is None:
continue
if tmp[1]:
send(dev.address,tmp[1])
return True
......@@ -92,27 +92,29 @@ class XAALPlugin(FauxmoPlugin):
# the next call
self.value = self.__get_state()
if self.value != self._latest_action:
logger.warning(f'state={self.value} != latest_action={self._latest_action}')
logger.warning(f'state={self.value} != latest_action={self.latest_action}')
await asyncio.sleep(0.2)
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 is None:
continue
if tmp[2]:
value = dev.attributes.get(tmp[2],None)
if value == None: continue
if on_off[value] == self._latest_action:
return self._latest_action
if value is None:
continue
if on_off[value] == self.latest_action:
return self.latest_action
else:
# fake state due to missing state for this device
return self._latest_action
return self.latest_action
# no device found with the right state, so send
# the wrong state instead. sending "unknown"
# should be better, but it raise a big warning
if self._latest_action == 'on':
if self.latest_action == 'on':
return 'off'
return 'on'
......@@ -31,7 +31,7 @@ class GW(object):
if not cfg:
cfg= tools.new_cfg(PACKAGE_NAME)
cfg['devices'] = {}
logger.warn("Created an empty config file")
logger.warning("Created an empty config file")
cfg.write()
self.cfg = cfg
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment