Skip to content

Commit

Permalink
Call callback_function on error (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Feb 14, 2024
1 parent 0048d87 commit a7d3e79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
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

0 comments on commit a7d3e79

Please sign in to comment.