Avoid calling pformat unless debug logging is enabled (#217)

* Avoid calling pformat unless debug logging is enabled

* add logging test

* isort

* check for debug logging

* formatting
This commit is contained in:
J. Nick Koston
2021-09-26 09:50:58 -05:00
committed by GitHub
parent 85f17ab91c
commit 76c1264dc9
2 changed files with 39 additions and 2 deletions

View File

@@ -90,8 +90,10 @@ class TPLinkSmartHomeProtocol:
"""Execute a query on the device and wait for the response."""
assert self.writer is not None
assert self.reader is not None
debug_log = _LOGGER.isEnabledFor(logging.DEBUG)
_LOGGER.debug("> (%i) %s", len(request), request)
if debug_log:
_LOGGER.debug("> (%i) %s", len(request), request)
self.writer.write(TPLinkSmartHomeProtocol.encrypt(request))
await self.writer.drain()
@@ -101,7 +103,8 @@ class TPLinkSmartHomeProtocol:
buffer = await self.reader.readexactly(length)
response = TPLinkSmartHomeProtocol.decrypt(buffer)
json_payload = json.loads(response)
_LOGGER.debug("< (%i) %s", len(response), pf(json_payload))
if debug_log:
_LOGGER.debug("< (%i) %s", len(response), pf(json_payload))
return json_payload
async def close(self):