mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-09 22:37:08 +00:00
Add additional debug logging
This commit is contained in:
parent
805e4b8588
commit
8e51fa7d31
@ -80,10 +80,10 @@ class TPLinkSmartHomeProtocol:
|
|||||||
assert self.writer is not None # noqa: S101
|
assert self.writer is not None # noqa: S101
|
||||||
assert self.reader is not None # noqa: S101
|
assert self.reader is not None # noqa: S101
|
||||||
debug_log = _LOGGER.isEnabledFor(logging.DEBUG)
|
debug_log = _LOGGER.isEnabledFor(logging.DEBUG)
|
||||||
|
encrypted = TPLinkSmartHomeProtocol.encrypt(request)
|
||||||
if debug_log:
|
if debug_log:
|
||||||
_LOGGER.debug("%s >> %s", self.host, request)
|
_LOGGER.debug("%s >> (%s) %s", self.host, encrypted.hex(), request)
|
||||||
self.writer.write(TPLinkSmartHomeProtocol.encrypt(request))
|
self.writer.write(encrypted)
|
||||||
await self.writer.drain()
|
await self.writer.drain()
|
||||||
|
|
||||||
packed_block_size = await self.reader.readexactly(self.BLOCK_SIZE)
|
packed_block_size = await self.reader.readexactly(self.BLOCK_SIZE)
|
||||||
@ -93,7 +93,7 @@ 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("%s << %s", self.host, pf(json_payload))
|
_LOGGER.debug("%s << (%s) %s", self.host, buffer.hex(), pf(json_payload))
|
||||||
|
|
||||||
return json_payload
|
return json_payload
|
||||||
|
|
||||||
@ -101,10 +101,15 @@ class TPLinkSmartHomeProtocol:
|
|||||||
"""Close the connection."""
|
"""Close the connection."""
|
||||||
writer = self.writer
|
writer = self.writer
|
||||||
self.reader = self.writer = None
|
self.reader = self.writer = None
|
||||||
|
debug_log = _LOGGER.isEnabledFor(logging.DEBUG)
|
||||||
if writer:
|
if writer:
|
||||||
|
if debug_log:
|
||||||
|
_LOGGER.debug("%s: closing connection", self.host)
|
||||||
writer.close()
|
writer.close()
|
||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
await writer.wait_closed()
|
await writer.wait_closed()
|
||||||
|
elif debug_log:
|
||||||
|
_LOGGER.debug("%s: connection already closed", self.host)
|
||||||
|
|
||||||
def _reset(self) -> None:
|
def _reset(self) -> None:
|
||||||
"""Clear any varibles that should not survive between loops."""
|
"""Clear any varibles that should not survive between loops."""
|
||||||
|
Loading…
Reference in New Issue
Block a user