Skip to content

Commit

Permalink
Raise on timeout in Chromecast methods disconnect, join and wait (#842)
Browse files Browse the repository at this point in the history
* Raise on timeout in Chromecast methods disconnect, join and wait

* Fix imports
  • Loading branch information
emontnemery committed Feb 13, 2024
1 parent ffbbde6 commit 9b7c7d4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pychromecast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import fnmatch
from threading import Event
import threading
from typing import TYPE_CHECKING, Literal, overload
from typing import TYPE_CHECKING, Literal, cast, overload
from uuid import UUID

import zeroconf
Expand All @@ -29,7 +29,7 @@
from .const import CAST_TYPE_CHROMECAST, REQUEST_TIMEOUT
from .controllers.media import STREAM_TYPE_BUFFERED, MediaController # noqa: F401
from .controllers.receiver import CastStatus, CastStatusListener
from .error import NotConnected
from .error import NotConnected, RequestTimeout
from .models import CastInfo, HostServiceInfo, MDNSServiceInfo
from .response_handler import WaitResponse

Expand Down Expand Up @@ -501,7 +501,9 @@ def wait(self, timeout: float | None = None) -> None:
"""
if not self.socket_client.is_alive():
self.socket_client.start()
self.status_event.wait(timeout=timeout)
ready = self.status_event.wait(timeout=timeout)
if not ready:
raise RequestTimeout("wait", cast(float, timeout))

def disconnect(self, timeout: float | None = None) -> None:
"""
Expand All @@ -524,6 +526,8 @@ def join(self, timeout: float | None = None) -> None:
to block forever.
"""
self.socket_client.join(timeout=timeout)
if self.socket_client.is_alive():
raise TimeoutError("join", timeout)

def start(self) -> None:
"""
Expand Down

0 comments on commit 9b7c7d4

Please sign in to comment.