From 0e0ab1dfc99860e04da08e8bb2904425829d8794 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 11 Nov 2019 16:56:39 +0100 Subject: [PATCH] change functions that use query to await --- pyHS100/discover.py | 4 ++-- pyHS100/smartdevice.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyHS100/discover.py b/pyHS100/discover.py index f326979e..c0ca6bb7 100755 --- a/pyHS100/discover.py +++ b/pyHS100/discover.py @@ -98,7 +98,7 @@ class Discover: return devices @staticmethod - def discover_single( + async def discover_single( host: str, protocol: TPLinkSmartHomeProtocol = None ) -> Optional[SmartDevice]: """Discover a single device by the given IP address. @@ -111,7 +111,7 @@ class Discover: if protocol is None: protocol = TPLinkSmartHomeProtocol() - info = protocol.query(host, Discover.DISCOVERY_QUERY) + info = await protocol.query(host, Discover.DISCOVERY_QUERY) device_class = Discover._get_device_class(info) if device_class is not None: diff --git a/pyHS100/smartdevice.py b/pyHS100/smartdevice.py index f37c4818..299adb50 100755 --- a/pyHS100/smartdevice.py +++ b/pyHS100/smartdevice.py @@ -150,7 +150,7 @@ class SmartDevice: self.cache[target][cmd] = response.copy() self.cache[target][cmd]["last_updated"] = datetime.utcnow() - def _query_helper(self, target: str, cmd: str, arg: Optional[Dict] = None) -> Any: + async def _query_helper(self, target: str, cmd: str, arg: Optional[Dict] = None) -> Any: """Handle result unwrapping and error handling. :param target: Target system {system, time, emeter, ..} @@ -169,7 +169,7 @@ class SmartDevice: response = self._result_from_cache(target, cmd) if response is None: _LOGGER.debug("Got no result from cache, querying the device.") - response = self.protocol.query(host=self.host, request=request) + response = await self.protocol.query(host=self.host, request=request) self._insert_to_cache(target, cmd, response) except Exception as ex: raise SmartDeviceException(