diff --git a/devices/emulations/Fauxmo/README.rst b/devices/emulations/Fauxmo/README.rst index 39cb9014fc4283862d5d5da4a590de4109cce390..160c214e971493860e2eaaa6640289b2b22ae372 100644 --- a/devices/emulations/Fauxmo/README.rst +++ b/devices/emulations/Fauxmo/README.rst @@ -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. diff --git a/devices/emulations/Fauxmo/pyproject.toml b/devices/emulations/Fauxmo/pyproject.toml index 860c965b7f5d9abcf561576d5829de9c11d47ff4..98b15ea9b170934ed0130b05d6c70aeb405eac81 100644 --- a/devices/emulations/Fauxmo/pyproject.toml +++ b/devices/emulations/Fauxmo/pyproject.toml @@ -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] diff --git a/devices/emulations/Fauxmo/xaal/fauxmo/binding.py b/devices/emulations/Fauxmo/xaal/fauxmo/binding.py index 22c0e86f654ca1b9a90d236b197b78dcee8e0965..daad3b96c3f5c989a3d4ebf9c2c562b9f1369485 100644 --- a/devices/emulations/Fauxmo/xaal/fauxmo/binding.py +++ b/devices/emulations/Fauxmo/xaal/fauxmo/binding.py @@ -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' diff --git a/devices/emulations/Fauxmo/xaal/fauxmo/gw.py b/devices/emulations/Fauxmo/xaal/fauxmo/gw.py index bf34bfcc0b1c298a6a02745e1d5a2064f872c498..18570ee29ddb0d35ba381b53f549e5ca883aad9a 100644 --- a/devices/emulations/Fauxmo/xaal/fauxmo/gw.py +++ b/devices/emulations/Fauxmo/xaal/fauxmo/gw.py @@ -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