Skip to content

Commit

Permalink
Remove support for custom loop (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Feb 13, 2024
1 parent 846069c commit 96978c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 156 deletions.
113 changes: 0 additions & 113 deletions examples/custom_loop.py

This file was deleted.

16 changes: 3 additions & 13 deletions pychromecast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,26 +503,16 @@ def wait(self, timeout: float | None = None) -> None:
self.socket_client.start()
self.status_event.wait(timeout=timeout)

def connect(self) -> None:
"""Connect to the chromecast.
Must only be called if the worker thread will not be started.
"""
self.socket_client.connect()

def disconnect(self, timeout: float | None = None, blocking: bool = False) -> None:
def disconnect(self, timeout: float | None = None) -> None:
"""
Disconnects the chromecast and waits for it to terminate.
:param timeout: A floating point number specifying a timeout for the
operation in seconds (or fractions thereof). Or None
to block forever.
:param blocking: If True it will block until the disconnection is
complete, otherwise it will return immediately.
to block forever. Set to 0 to not block.
"""
self.socket_client.disconnect()
if blocking:
self.join(timeout=timeout)
self.join(timeout=timeout)

def join(self, timeout: float | None = None) -> None:
"""
Expand Down
33 changes: 3 additions & 30 deletions pychromecast/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,23 +441,6 @@ def mdns_backoff(
)
raise ChromecastConnectionError("Failed to connect")

def connect(self) -> None:
"""Connect socket connection to Chromecast device.
Must only be called if the worker thread will not be started.
"""
try:
self.initialize_connection()
except ChromecastConnectionError:
self._report_connection_status(
ConnectionStatus(
CONNECTION_STATUS_DISCONNECTED,
NetworkAddress(self.host, self.port),
None,
)
)
return

def disconnect(self) -> None:
"""Disconnect socket connection to Chromecast device"""
self.stop.set()
Expand Down Expand Up @@ -544,7 +527,7 @@ def run(self) -> None:
self.logger.debug("Thread started...")
while not self.stop.is_set():
try:
if self.run_once(timeout=POLL_TIME_BLOCKING) == 1:
if self._run_once(timeout=POLL_TIME_BLOCKING) == 1:
break
except Exception: # pylint: disable=broad-except
self._force_recon = True
Expand All @@ -559,11 +542,8 @@ def run(self) -> None:
# Clean up
self._cleanup()

def run_once(self, timeout: float = POLL_TIME_NON_BLOCKING) -> int:
"""
Use run_once() in your own main loop after you
receive something on the socket (get_socket()).
"""
def _run_once(self, timeout: float = POLL_TIME_NON_BLOCKING) -> int:
"""Receive from the socket and handle data."""
# pylint: disable=too-many-branches, too-many-statements, too-many-return-statements

try:
Expand Down Expand Up @@ -659,13 +639,6 @@ def run_once(self, timeout: float = POLL_TIME_NON_BLOCKING) -> int:

return 0

def get_socket(self) -> socket.socket | ssl.SSLSocket | None:
"""
Returns the socket of the connection to use it in you own
main loop.
"""
return self.socket

def _check_connection(self) -> bool:
"""
Checks if the connection is active, and if not reconnect
Expand Down

0 comments on commit 96978c2

Please sign in to comment.