mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
change functions that use query to await
This commit is contained in:
parent
8f59d74e29
commit
0e0ab1dfc9
@ -98,7 +98,7 @@ class Discover:
|
|||||||
return devices
|
return devices
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def discover_single(
|
async def discover_single(
|
||||||
host: str, protocol: TPLinkSmartHomeProtocol = None
|
host: str, protocol: TPLinkSmartHomeProtocol = None
|
||||||
) -> Optional[SmartDevice]:
|
) -> Optional[SmartDevice]:
|
||||||
"""Discover a single device by the given IP address.
|
"""Discover a single device by the given IP address.
|
||||||
@ -111,7 +111,7 @@ class Discover:
|
|||||||
if protocol is None:
|
if protocol is None:
|
||||||
protocol = TPLinkSmartHomeProtocol()
|
protocol = TPLinkSmartHomeProtocol()
|
||||||
|
|
||||||
info = protocol.query(host, Discover.DISCOVERY_QUERY)
|
info = await protocol.query(host, Discover.DISCOVERY_QUERY)
|
||||||
|
|
||||||
device_class = Discover._get_device_class(info)
|
device_class = Discover._get_device_class(info)
|
||||||
if device_class is not None:
|
if device_class is not None:
|
||||||
|
@ -150,7 +150,7 @@ class SmartDevice:
|
|||||||
self.cache[target][cmd] = response.copy()
|
self.cache[target][cmd] = response.copy()
|
||||||
self.cache[target][cmd]["last_updated"] = datetime.utcnow()
|
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.
|
"""Handle result unwrapping and error handling.
|
||||||
|
|
||||||
:param target: Target system {system, time, emeter, ..}
|
:param target: Target system {system, time, emeter, ..}
|
||||||
@ -169,7 +169,7 @@ class SmartDevice:
|
|||||||
response = self._result_from_cache(target, cmd)
|
response = self._result_from_cache(target, cmd)
|
||||||
if response is None:
|
if response is None:
|
||||||
_LOGGER.debug("Got no result from cache, querying the device.")
|
_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)
|
self._insert_to_cache(target, cmd, response)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise SmartDeviceException(
|
raise SmartDeviceException(
|
||||||
|
Loading…
Reference in New Issue
Block a user