Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to log heartbeat ping pong #969

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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