mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-27 09:06:24 +00:00
Add host information to protocol debug logs (#219)
This commit is contained in:
parent
76c1264dc9
commit
3cf549e32e
@ -93,7 +93,7 @@ class TPLinkSmartHomeProtocol:
|
|||||||
debug_log = _LOGGER.isEnabledFor(logging.DEBUG)
|
debug_log = _LOGGER.isEnabledFor(logging.DEBUG)
|
||||||
|
|
||||||
if debug_log:
|
if debug_log:
|
||||||
_LOGGER.debug("> (%i) %s", len(request), request)
|
_LOGGER.debug("%s >> %s", self.host, request)
|
||||||
self.writer.write(TPLinkSmartHomeProtocol.encrypt(request))
|
self.writer.write(TPLinkSmartHomeProtocol.encrypt(request))
|
||||||
await self.writer.drain()
|
await self.writer.drain()
|
||||||
|
|
||||||
@ -104,7 +104,8 @@ class TPLinkSmartHomeProtocol:
|
|||||||
response = TPLinkSmartHomeProtocol.decrypt(buffer)
|
response = TPLinkSmartHomeProtocol.decrypt(buffer)
|
||||||
json_payload = json.loads(response)
|
json_payload = json.loads(response)
|
||||||
if debug_log:
|
if debug_log:
|
||||||
_LOGGER.debug("< (%i) %s", len(response), pf(json_payload))
|
_LOGGER.debug("%s << %s", self.host, pf(json_payload))
|
||||||
|
|
||||||
return json_payload
|
return json_payload
|
||||||
|
|
||||||
async def close(self):
|
async def close(self):
|
||||||
@ -129,7 +130,7 @@ class TPLinkSmartHomeProtocol:
|
|||||||
if not await self._connect(timeout):
|
if not await self._connect(timeout):
|
||||||
await self.close()
|
await self.close()
|
||||||
if retry >= retry_count:
|
if retry >= retry_count:
|
||||||
_LOGGER.debug("Giving up after %s retries", retry)
|
_LOGGER.debug("Giving up on %s after %s retries", self.host, retry)
|
||||||
raise SmartDeviceException(
|
raise SmartDeviceException(
|
||||||
f"Unable to connect to the device: {self.host}"
|
f"Unable to connect to the device: {self.host}"
|
||||||
)
|
)
|
||||||
@ -144,12 +145,14 @@ class TPLinkSmartHomeProtocol:
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
await self.close()
|
await self.close()
|
||||||
if retry >= retry_count:
|
if retry >= retry_count:
|
||||||
_LOGGER.debug("Giving up after %s retries", retry)
|
_LOGGER.debug("Giving up on %s after %s retries", self.host, retry)
|
||||||
raise SmartDeviceException(
|
raise SmartDeviceException(
|
||||||
f"Unable to query the device: {ex}"
|
f"Unable to query the device {self.host}: {ex}"
|
||||||
) from ex
|
) from ex
|
||||||
|
|
||||||
_LOGGER.debug("Unable to query the device, retrying: %s", ex)
|
_LOGGER.debug(
|
||||||
|
"Unable to query the device %s, retrying: %s", self.host, ex
|
||||||
|
)
|
||||||
|
|
||||||
# make mypy happy, this should never be reached..
|
# make mypy happy, this should never be reached..
|
||||||
await self.close()
|
await self.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user