From 98df4c9da74d321943decfb530f2a7680d43c29c Mon Sep 17 00:00:00 2001 From: jkerdreux-imt <jerome.kerdreux@imt-atlantique.fr> Date: Sun, 15 Dec 2024 13:12:38 +0100 Subject: [PATCH] Fix issue w/ latest version of Fauxmo Fauxmo 0.8 has somne issues. --- devices/emulations/Fauxmo/README.rst | 6 ++++ devices/emulations/Fauxmo/pyproject.toml | 2 +- .../emulations/Fauxmo/xaal/fauxmo/binding.py | 30 ++++++++++--------- devices/emulations/Fauxmo/xaal/fauxmo/gw.py | 2 +- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/devices/emulations/Fauxmo/README.rst b/devices/emulations/Fauxmo/README.rst index 39cb9014..160c214e 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 860c965b..98b15ea9 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 22c0e86f..daad3b96 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 bf34bfcc..18570ee2 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 -- GitLab