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

Call callback_function on error #850

Merged
merged 1 commit into from
Feb 14, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pychromecast/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ def launch(
"%s: Can't launch app with no supporting app_id",
self.__class__.__name__,
)
if callback_function:
callback_function(False, None)
return

if self._socket_client is None:
if callback_function:
callback_function(False, None)
raise ControllerNotRegistered

self._socket_client.receiver_controller.launch_app(
Expand Down Expand Up @@ -130,6 +134,8 @@ def send_message(
Will raise a NotConnected exception if not connected.
"""
if self._socket_client is None:
if callback_function:
callback_function(False, None)
raise ControllerNotRegistered

receiver_ctrl = self._socket_client.receiver_controller
Expand Down
2 changes: 2 additions & 0 deletions pychromecast/controllers/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ def _send_command(
self.logger.warning(
"%s command requested but no session is active.", command[MESSAGE_TYPE]
)
if callback_function:
callback_function(False, None)
return

command["mediaSessionId"] = self.status.media_session_id
Expand Down
4 changes: 4 additions & 0 deletions pychromecast/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,12 +944,16 @@ def send_app_message(
) -> None:
"""Helper method to send a message to current running app."""
if namespace not in self.app_namespaces:
if callback_function:
callback_function(False, None)
raise UnsupportedNamespace(
f"Namespace {namespace} is not supported by current app. "
f"Supported are {', '.join(self.app_namespaces)}"
)

if self.destination_id is None:
if callback_function:
callback_function(False, None)
raise NotConnected(
"Attempting send a message when destination_id is not set"
)
Expand Down