change functions that use query to await

This commit is contained in:
Bas Nijholt 2019-11-11 16:56:39 +01:00
parent 8f59d74e29
commit 0e0ab1dfc9
2 changed files with 4 additions and 4 deletions

View File

@ -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:

View File

@ -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(