Skip to content

Commit

Permalink
Make it possible to log heartbeat ping pong (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Oct 7, 2024
1 parent dca2d81 commit c72509d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pychromecast/controllers/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import logging
import time

from . import BaseController
Expand All @@ -28,6 +29,7 @@ def __init__(self) -> None:
super().__init__(NS_HEARTBEAT, target_platform=True)
self.last_ping = 0.0
self.last_pong = time.time()
self.logger = logging.getLogger(__name__)

def receive_message(self, _message: CastMessage, data: dict) -> bool:
"""
Expand Down
10 changes: 8 additions & 2 deletions pychromecast/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,10 @@ def _route_message(self, message: CastMessage, data: dict) -> None:
# route message to handlers
if message.namespace in self._handlers:
# debug messages
if message.namespace != NS_HEARTBEAT:
if (
message.namespace != NS_HEARTBEAT
or self.heartbeat_controller.logger.isEnabledFor(logging.DEBUG)
):
self.logger.debug(
"[%s(%s):%s] Received: %s",
self.fn or "",
Expand Down Expand Up @@ -870,7 +873,10 @@ def send_message(
be_size = pack(">I", msg.ByteSize())

# Log all messages except heartbeat
if msg.namespace != NS_HEARTBEAT:
if (
msg.namespace != NS_HEARTBEAT
or self.heartbeat_controller.logger.isEnabledFor(logging.DEBUG)
):
self.logger.debug(
"[%s(%s):%s] Sending: %s",
self.fn or "",
Expand Down

0 comments on commit c72509d

Please sign in to comment.