From 08119add97c7ad8f152f67e7b325e67caed4b405 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 4 Dec 2019 19:21:19 +0100 Subject: [PATCH] Optimized WeMo plugin --- platypush/plugins/switch/wemo/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/platypush/plugins/switch/wemo/__init__.py b/platypush/plugins/switch/wemo/__init__.py index c8cee331..46232667 100644 --- a/platypush/plugins/switch/wemo/__init__.py +++ b/platypush/plugins/switch/wemo/__init__.py @@ -1,4 +1,5 @@ import enum +import re import textwrap from xml.dom.minidom import parseString @@ -70,6 +71,7 @@ class SwitchWemoPlugin(SwitchPlugin): for device in self._devices.values() ] + # noinspection PyShadowingNames def _exec(self, device: str, action: SwitchAction, port: int = _default_port, value=None): if device not in self._addresses: try: @@ -87,7 +89,7 @@ class SwitchWemoPlugin(SwitchPlugin): 'Content-Type': 'text/xml; charset="utf-8"', 'SOAPACTION': '\"urn:Belkin:service:basicevent:1#{}\"'.format(action.value), }, - data=textwrap.dedent( + data=re.sub('\s+', ' ', textwrap.dedent( ''' '''.format(action=action.value, state=state_name, - value=value if value is not None else '')) - ) + value=value if value is not None else '')))) dom = parseString(response.text) return dom.getElementsByTagName(state_name).item(0).firstChild.data @@ -116,7 +117,7 @@ class SwitchWemoPlugin(SwitchPlugin): 'name': name if name != addr else self.get_name(addr).output, 'on': self.get_state(addr).output, } - for (name, addr) in self._devices.items() + for (name, addr) in devices.items() ] return ret[0] if device else ret