Check if debug is enabled once per packet (#455)

This commit is contained in:
J. Nick Koston 2023-07-02 16:55:36 -05:00 committed by GitHub
parent aa88d51a45
commit 974b8e3ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -679,8 +679,12 @@ class APIConnection:
def _process_packet(self, msg_type_proto: int, data: bytes) -> None:
"""Process a packet from the socket."""
debug = _LOGGER.isEnabledFor(logging.DEBUG)
if not (class_ := MESSAGE_TYPE_TO_PROTO.get(msg_type_proto)):
_LOGGER.debug("%s: Skipping message type %s", self.log_name, msg_type_proto)
if debug:
_LOGGER.debug(
"%s: Skipping message type %s", self.log_name, msg_type_proto
)
return
msg = class_()
@ -707,7 +711,10 @@ class APIConnection:
msg_type = type(msg)
_LOGGER.debug("%s: Got message of type %s: %s", self.log_name, msg_type, msg)
if debug:
_LOGGER.debug(
"%s: Got message of type %s: %s", self.log_name, msg_type, msg
)
if self._pong_timer:
# Any valid message from the remote cancels the pong timer