diff -Nru pychromecast-7.1.1/debian/changelog pychromecast-6.0.1/debian/changelog --- pychromecast-7.1.1/debian/changelog 2020-07-11 16:45:04.000000000 +0000 +++ pychromecast-6.0.1/debian/changelog 2020-10-29 10:54:23.000000000 +0000 @@ -1,3 +1,9 @@ +pychromecast (6.0.1-1~groovy) groovy; urgency=medium + + * Downgrade to 6.0.1 + + -- Logix Thu, 29 Oct 2020 12:53:22 +0000 + pychromecast (7.1.1-1) unstable; urgency=medium * Team upload. diff -Nru pychromecast-7.1.1/debian/control pychromecast-6.0.1/debian/control --- pychromecast-7.1.1/debian/control 2020-07-11 16:45:04.000000000 +0000 +++ pychromecast-6.0.1/debian/control 2020-10-29 10:46:11.000000000 +0000 @@ -9,7 +9,7 @@ python3-setuptools, python3-protobuf, python3-requests, - python3-zeroconf (>= 0.25.1~) + python3-zeroconf Standards-Version: 4.5.0 Homepage: https://github.com/home-assistant-libs/pychromecast Vcs-Browser: https://salsa.debian.org/python-team/modules/pychromecast diff -Nru pychromecast-7.1.1/examples/custom_loop.py pychromecast-6.0.1/examples/custom_loop.py --- pychromecast-7.1.1/examples/custom_loop.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/custom_loop.py 2020-06-28 07:58:09.000000000 +0000 @@ -30,9 +30,9 @@ chromecast.connect() nonlocal cast cast = chromecast - pychromecast.discovery.stop_discovery(browser) + stop_discovery() - browser = pychromecast.get_chromecasts(blocking=False, callback=callback) + stop_discovery = pychromecast.get_chromecasts(blocking=False, callback=callback) while True: if cast: diff -Nru pychromecast-7.1.1/examples/dashcast_example.py pychromecast-6.0.1/examples/dashcast_example.py --- pychromecast-7.1.1/examples/dashcast_example.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/dashcast_example.py 2020-06-28 07:58:09.000000000 +0000 @@ -25,7 +25,7 @@ if args.show_debug: logging.basicConfig(level=logging.DEBUG) -chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) +chromecasts = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) if not chromecasts: print('No chromecast with name "{}" discovered'.format(args.cast)) sys.exit(1) @@ -68,6 +68,3 @@ # If debugging, sleep after running so we can see any error messages. if args.show_debug: time.sleep(10) - -# Shut down discovery -pychromecast.discovery.stop_discovery(browser) diff -Nru pychromecast-7.1.1/examples/discovery_example2.py pychromecast-6.0.1/examples/discovery_example2.py --- pychromecast-7.1.1/examples/discovery_example2.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/discovery_example2.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -""" -Example that shows how to list available chromecasts. -""" -import argparse -import logging -import time - -import pychromecast -import zeroconf - -parser = argparse.ArgumentParser(description="Example on how to receive updates on discovered chromecasts.") -parser.add_argument("--show-debug", help="Enable debug log", action="store_true") -args = parser.parse_args() - -if args.show_debug: - logging.basicConfig(level=logging.DEBUG) - -devices, browser = pychromecast.discovery.discover_chromecasts() -# Shut down discovery -pychromecast.stop_discovery(browser) - -print(f"Discovered {len(devices)} device(s):") -for device in devices: - print(f" {device}") - diff -Nru pychromecast-7.1.1/examples/discovery_example3.py pychromecast-6.0.1/examples/discovery_example3.py --- pychromecast-7.1.1/examples/discovery_example3.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/discovery_example3.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ -""" -Example that shows how to list chromecasts matching on name or uuid. -""" -import argparse -import logging -import sys -import time -from uuid import UUID - -import pychromecast -import zeroconf - -parser = argparse.ArgumentParser(description="Example on how to receive updates on discovered chromecasts.") -parser.add_argument("--show-debug", help="Enable debug log", action="store_true") -parser.add_argument( - "--cast", help='Name of wanted cast device")', default=None -) -parser.add_argument( - "--uuid", help='UUID of wanted cast device', default=None -) -args = parser.parse_args() - -if args.show_debug: - logging.basicConfig(level=logging.DEBUG) -if args.cast is None and args.uuid is None : - print("Need to supply `cast` or `uuid`") - sys.exit(1) - -friendly_names = [] -if args.cast: - friendly_names.append(args.cast) - -uuids = [] -if args.uuid: - uuids.append(UUID(args.uuid)) - -devices, browser = pychromecast.discovery.discover_listed_chromecasts(friendly_names=friendly_names, uuids=uuids) -#devices, browser = pychromecast.get_listed_chromecasts(friendly_names=friendly_names, uuids=uuids) -# Shut down discovery -pychromecast.stop_discovery(browser) - -print(f"Discovered {len(devices)} device(s):") -for device in devices: - print(f" {device}") - diff -Nru pychromecast-7.1.1/examples/discovery_example.py pychromecast-6.0.1/examples/discovery_example.py --- pychromecast-7.1.1/examples/discovery_example.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/discovery_example.py 2020-06-28 07:58:09.000000000 +0000 @@ -6,7 +6,6 @@ import time import pychromecast -import zeroconf parser = argparse.ArgumentParser(description="Example on how to receive updates on discovered chromecasts.") parser.add_argument("--show-debug", help="Enable debug log", action="store_true") @@ -16,25 +15,20 @@ logging.basicConfig(level=logging.DEBUG) def list_devices(): - print("Currently known cast devices:") - for uuid, service in listener.services.items(): - print(" {} {}".format(uuid, service)) + print("Currently known cast devices:") + for name, service in listener.services.items(): + print(" {} {}".format(name, service)) -def add_callback(uuid, name): - print("Found mDNS service for cast device {}".format(uuid)) +def add_callback(name): + print("Found cast device {}".format(name)) list_devices() -def remove_callback(uuid, name, service): - print("Lost mDNS service for cast device {} {}".format(uuid, service)) +def remove_callback(name, service): + print("Lost cast device {} {}".format(name, service)) list_devices() -def update_callback(uuid, name): - print("Updated mDNS service for cast device {}".format(uuid)) - list_devices() - -listener = pychromecast.CastListener(add_callback, remove_callback, update_callback) -zconf = zeroconf.Zeroconf() -browser = pychromecast.discovery.start_discovery(listener, zconf) +listener = pychromecast.CastListener(add_callback, remove_callback) +browser = pychromecast.discovery.start_discovery(listener) try: while True: diff -Nru pychromecast-7.1.1/examples/list_chromecasts.py pychromecast-6.0.1/examples/list_chromecasts.py --- pychromecast-7.1.1/examples/list_chromecasts.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/list_chromecasts.py 2020-06-28 07:58:09.000000000 +0000 @@ -13,9 +13,7 @@ if args.show_debug: logging.basicConfig(level=logging.DEBUG) -casts, browser = pychromecast.get_chromecasts() -# Shut down discovery as we don't care about updates -pychromecast.discovery.stop_discovery(browser) +casts = pychromecast.get_chromecasts() if len(casts) == 0: print("No Devices Found") exit() @@ -23,7 +21,7 @@ print("Found cast devices:") for cast in casts: print( - ' "{}" on mDNS service {} with UUID:{}'.format( - cast.name, cast._services, cast.uuid + ' "{}" on {}:{} with UUID:{}'.format( + cast.name, cast.host, cast.port, cast.uuid ) ) diff -Nru pychromecast-7.1.1/examples/media_example2.py pychromecast-6.0.1/examples/media_example2.py --- pychromecast-7.1.1/examples/media_example2.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/media_example2.py 2020-06-28 07:58:09.000000000 +0000 @@ -38,7 +38,7 @@ datefmt = "%Y-%m-%d %H:%M:%S" logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG) -chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) +chromecasts = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) if not chromecasts: print('No chromecast with name "{}" discovered'.format(args.cast)) sys.exit(1) @@ -96,6 +96,3 @@ time.sleep(1) except KeyboardInterrupt: break - -# Shut down discovery -pychromecast.discovery.stop_discovery(browser) diff -Nru pychromecast-7.1.1/examples/media_example.py pychromecast-6.0.1/examples/media_example.py --- pychromecast-7.1.1/examples/media_example.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/media_example.py 2020-06-28 07:58:09.000000000 +0000 @@ -31,7 +31,7 @@ if args.show_debug: logging.basicConfig(level=logging.DEBUG) -chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) +chromecasts = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) if not chromecasts: print('No chromecast with name "{}" discovered'.format(args.cast)) sys.exit(1) @@ -49,23 +49,13 @@ # Wait for player_state PLAYING player_state = None t = 30 -#while player_state != "PLAYING" and t > 0: -has_played = False -while True: +while player_state != "PLAYING" and t > 0: try: if player_state != cast.media_controller.status.player_state: player_state = cast.media_controller.status.player_state print("Player state:", player_state) - if player_state == "PLAYING": - has_played = True - if cast.socket_client.is_connected and has_played and player_state != "PLAYING": - has_played = False - cast.media_controller.play_media(args.url, "audio/mp3") time.sleep(0.1) t = t - 0.1 except KeyboardInterrupt: break - -# Shut down discovery -pychromecast.discovery.stop_discovery(browser) diff -Nru pychromecast-7.1.1/examples/multizone_example.py pychromecast-6.0.1/examples/multizone_example.py --- pychromecast-7.1.1/examples/multizone_example.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/multizone_example.py 2020-06-28 07:58:09.000000000 +0000 @@ -48,7 +48,7 @@ print("Members: {}".format(mz.members)) -chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) +chromecasts = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) if not chromecasts: print('No chromecast with name "{}" discovered'.format(args.cast)) sys.exit(1) @@ -64,10 +64,4 @@ cast.wait() while True: - try: - time.sleep(1) - except KeyboardInterrupt: - break - -# Shut down discovery -pychromecast.discovery.stop_discovery(browser) + time.sleep(1) diff -Nru pychromecast-7.1.1/examples/simple_listener_example.py pychromecast-6.0.1/examples/simple_listener_example.py --- pychromecast-7.1.1/examples/simple_listener_example.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/simple_listener_example.py 2020-06-28 07:58:09.000000000 +0000 @@ -46,7 +46,7 @@ if args.show_debug: logging.basicConfig(level=logging.DEBUG) -chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) +chromecasts = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) if not chromecasts: print('No chromecast with name "{}" discovered'.format(args.cast)) sys.exit(1) @@ -62,6 +62,3 @@ chromecast.media_controller.register_status_listener(listenerMedia) input("Listening for Chromecast events...\n\n") - -# Shut down discovery -pychromecast.discovery.stop_discovery(browser) diff -Nru pychromecast-7.1.1/examples/spotify_example.py pychromecast-6.0.1/examples/spotify_example.py --- pychromecast-7.1.1/examples/spotify_example.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/spotify_example.py 2020-06-28 07:58:09.000000000 +0000 @@ -40,7 +40,7 @@ # Uncomment to enable http.client debug log # http_client.HTTPConnection.debuglevel = 1 -chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) +chromecasts = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) cast = None for _cast in chromecasts: if _cast.name == args.cast: @@ -55,6 +55,30 @@ print("cast {}".format(cast)) +class ConnListener: + def __init__(self, mz): + self._mz = mz + + def new_connection_status(self, connection_status): + """Handle reception of a new ConnectionStatus.""" + if connection_status.status == "CONNECTED": + self._mz.update_members() + + +class MzListener: + def __init__(self): + self.got_members = False + + def multizone_member_added(self, uuid): + pass + + def multizone_member_removed(self, uuid): + pass + + def multizone_status_received(self): + self.got_members = True + + # Wait for connection to the chromecast cast.wait() @@ -102,6 +126,3 @@ client.start_playback(device_id=spotify_device_id, uris=args.uri) else: client.start_playback(device_id=spotify_device_id, context_uri=args.uri[0]) - -# Shut down discovery -pychromecast.discovery.stop_discovery(browser) diff -Nru pychromecast-7.1.1/examples/supla_example.py pychromecast-6.0.1/examples/supla_example.py --- pychromecast-7.1.1/examples/supla_example.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/supla_example.py 2020-06-28 07:58:09.000000000 +0000 @@ -27,15 +27,9 @@ logging.basicConfig(level=logging.DEBUG) -chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[CAST_NAME]) -if not chromecasts: - print('No chromecast with name "{}" discovered'.format(CAST_NAME)) - sys.exit(1) - -cast = chromecasts[0] -# Start socket client's worker thread and wait for initial status update +chromecasts = pychromecast.get_chromecasts() +cast = next(cc for cc in chromecasts if cc.device.friendly_name.lower() == CAST_NAME.lower()) cast.wait() - supla = SuplaController() cast.register_handler(supla) supla.launch() diff -Nru pychromecast-7.1.1/examples/yleareena_example.py pychromecast-6.0.1/examples/yleareena_example.py --- pychromecast-7.1.1/examples/yleareena_example.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/yleareena_example.py 2020-06-28 07:58:09.000000000 +0000 @@ -3,14 +3,12 @@ """ -import argparse -import logging -import sys -from time import sleep - import pychromecast +import argparse from pychromecast.controllers.yleareena import YleAreenaController +from time import sleep +import logging logger = logging.getLogger(__name__) @@ -61,16 +59,12 @@ return info.media_id.split('-')[-1] -chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) -if not chromecasts: - print('No chromecast with name "{}" discovered'.format(args.cast)) - sys.exit(1) -cast = chromecasts[0] -# Start socket client's worker thread and wait for initial status update +chromecasts = pychromecast.get_chromecasts() +cast = next(cc for cc in chromecasts if cc.device.friendly_name == args.cast) +print(cast) cast.wait() - yt = YleAreenaController() cast.register_handler(yt) yt.play_areena_media(entry_id=get_kaltura_id(args.program), audio_language=args.audio_language, text_language=args.text_language) -sleep(10) +sleep(10) \ No newline at end of file diff -Nru pychromecast-7.1.1/examples/youtube_example.py pychromecast-6.0.1/examples/youtube_example.py --- pychromecast-7.1.1/examples/youtube_example.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/examples/youtube_example.py 2020-06-28 07:58:09.000000000 +0000 @@ -34,7 +34,7 @@ if args.show_debug: logging.basicConfig(level=logging.DEBUG) -chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) +chromecasts = pychromecast.get_listed_chromecasts(friendly_names=[args.cast]) if not chromecasts: print('No chromecast with name "{}" discovered'.format(args.cast)) sys.exit(1) @@ -46,6 +46,3 @@ yt = YouTubeController() cast.register_handler(yt) yt.play_video(VIDEO_ID) - -# Shut down discovery -pychromecast.discovery.stop_discovery(browser) diff -Nru pychromecast-7.1.1/pychromecast/controllers/plex.py pychromecast-6.0.1/pychromecast/controllers/plex.py --- pychromecast-7.1.1/pychromecast/controllers/plex.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/pychromecast/controllers/plex.py 2020-06-28 07:58:09.000000000 +0000 @@ -53,7 +53,6 @@ autoplay=True, currentTime=0, playQueueID=None, - version="1.10.1.4602", **kwargs ): # noqa: 501 pylint: disable=invalid-name, too-many-arguments, too-many-locals, protected-access, redefined-builtin """Create the message that chromecast requires. Use pass of plexapi media object or @@ -81,7 +80,6 @@ username (None): user name of the person that start the playback. autoplay (bool): Auto play after the video is done. currentTime (int): Set playback from this time. default 0 - version (str): pms version. Default 1.10.1.4602 **kwargs: To allow overrides, this will be merged with the rest of the msg. Returns: @@ -128,7 +126,7 @@ "transcoderVideo": transcoderVideo, "transcoderVideoRemuxOnly": transcoderVideoRemuxOnly, "transcoderAudio": transcoderAudio, - "version": version, + "version": "1.4.3.3433", "myPlexSubscription": myPlexSubscription, "isVerifiedHostname": isVerifiedHostname, "protocol": protocol, @@ -532,16 +530,3 @@ subtitle (str): could be index, language or languageCode. """ self._change_track(subtitle) - - def play_media(self, media=None, **kwargs): - """Start playback on the chromecast - - Args: - media (None, optional): Can also be :class:`~plexapi.base.Playable - if its not, you need to fill out all the kwargs. - **kwargs: See media_to_chromecast_command docs string. `version` is by default set to the - version of the PMS reported by the API. - """ # noqa - args = {"version": self.pms.version} - args.update(kwargs) - super().play_media(media, **args) diff -Nru pychromecast-7.1.1/pychromecast/discovery.py pychromecast-6.0.1/pychromecast/discovery.py --- pychromecast-7.1.1/pychromecast/discovery.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/pychromecast/discovery.py 2020-06-28 07:58:09.000000000 +0000 @@ -34,26 +34,14 @@ def remove_service(self, zconf, typ, name): """ Remove a service from the collection. """ _LOGGER.debug("remove_service %s, %s", typ, name) - service = None - service_removed = False - uuid = None - for uuid, services_for_uuid in self.services.items(): - if name in services_for_uuid[0]: - service = services_for_uuid - services_for_uuid[0].remove(name) - if len(services_for_uuid[0]) == 0: - self.services.pop(uuid) - service_removed = True - break + service = self.services.pop(name, None) if not service: _LOGGER.debug("remove_service unknown %s, %s", typ, name) return - if self.remove_callback and service_removed: - self.remove_callback(uuid, name, service) - if self.update_callback and not service_removed: - self.update_callback(uuid, name) + if self.remove_callback: + self.remove_callback(name, service) def update_service(self, zconf, typ, name): """ Update a service in the collection. """ @@ -97,29 +85,16 @@ uuid = get_value("id") friendly_name = get_value("fn") - if not uuid: - _LOGGER.debug("add_service failed to get uuid for %s, %s", typ, name) - return - uuid = UUID(uuid) + if uuid: + uuid = UUID(uuid) - services_for_uuid = self.services.setdefault( - uuid, ({name}, uuid, model_name, friendly_name) - ) - services_for_uuid[0].add(name) - self.services[uuid] = ( - services_for_uuid[0], - services_for_uuid[1], - model_name, - friendly_name, - host, - service.port, - ) + self.services[name] = (host, service.port, uuid, model_name, friendly_name) if callback: - callback(uuid, name) + callback(name) -def start_discovery(listener, zeroconf_instance): +def start_discovery(listener, zeroconf_instance=None): """ Start discovering chromecasts on the network. @@ -138,7 +113,7 @@ instance is passed, a new instance will be created. """ return zeroconf.ServiceBrowser( - zeroconf_instance, "_googlecast._tcp.local.", listener, + zeroconf_instance or zeroconf.Zeroconf(), "_googlecast._tcp.local.", listener, ) @@ -153,76 +128,24 @@ def discover_chromecasts(max_devices=None, timeout=DISCOVER_TIMEOUT): - """ - Discover chromecasts on the network. - - Returns a tuple of: - A list of chromecast services, or an empty list if no matching chromecasts were - found. - A service browser to keep the Chromecast mDNS data updated. When updates - are (no longer) needed, pass the broswer object to - pychromecast.discovery.stop_discover(). - """ - # pylint: disable=unused-argument - def callback(uuid, name): - """Called when zeroconf has discovered a new chromecast.""" - if max_devices is not None and listener.count >= max_devices: - discover_complete.set() - - discover_complete = Event() - listener = CastListener(callback) - zconf = zeroconf.Zeroconf() - browser = start_discovery(listener, zconf) - - # Wait for the timeout or the maximum number of devices - discover_complete.wait(timeout) - - return (listener.devices, browser) - - -def discover_listed_chromecasts( - friendly_names=None, uuids=None, discovery_timeout=DISCOVER_TIMEOUT, -): - """ - Searches the network for chromecast devices matching a list of friendly - names or a list of UUIDs. - - Returns a tuple of: - A list of chromecast services matching the criteria, - or an empty list if no matching chromecasts were found. - A service browser to keep the Chromecast mDNS data updated. When updates - are (no longer) needed, pass the broswer object to - pychromecast.discovery.stop_discover(). - - :param friendly_names: A list of wanted friendly names - :param uuids: A list of wanted uuids - :param discovery_timeout: A floating point number specifying the time to wait - devices matching the criteria have been found. - """ - - cc_list = {} - - def callback(uuid, name): # pylint: disable=unused-argument - service = listener.services[uuid] - friendly_name = service[3] - if uuids and uuid in uuids: - cc_list[uuid] = listener.services[uuid] - uuids.remove(uuid) - if friendly_names and friendly_name in friendly_names: - cc_list[uuid] = listener.services[uuid] - friendly_names.remove(friendly_name) - if not friendly_names and not uuids: - discover_complete.set() - - discover_complete = Event() - - listener = CastListener(callback) - zconf = zeroconf.Zeroconf() - browser = start_discovery(listener, zconf) - - # Wait for the timeout or found all wanted devices - discover_complete.wait(discovery_timeout) - return (cc_list.values(), browser) + """ Discover chromecasts on the network. """ + try: + # pylint: disable=unused-argument + def callback(name): + """Called when zeroconf has discovered a new chromecast.""" + if max_devices is not None and listener.count >= max_devices: + discover_complete.set() + + discover_complete = Event() + listener = CastListener(callback) + browser = start_discovery(listener) + + # Wait for the timeout or the maximum number of devices + discover_complete.wait(timeout) + + return listener.devices + finally: + stop_discovery(browser) def get_info_from_service(service, zconf): diff -Nru pychromecast-7.1.1/pychromecast/__init__.py pychromecast-6.0.1/pychromecast/__init__.py --- pychromecast-7.1.1/pychromecast/__init__.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/pychromecast/__init__.py 2020-06-28 07:58:09.000000000 +0000 @@ -7,13 +7,10 @@ # pylint: disable=wildcard-import import threading - -import zeroconf - from .config import * # noqa from .error import * # noqa from . import socket_client -from .discovery import ( # noqa +from .discovery import ( DISCOVER_TIMEOUT, CastListener, discover_chromecasts, @@ -64,14 +61,12 @@ _get_chromecast_from_host = get_chromecast_from_host # pylint: disable=invalid-name -def get_chromecast_from_service( - services, zconf, tries=None, retry_wait=None, timeout=None -): +def get_chromecast_from_service(services, tries=None, retry_wait=None, timeout=None): """Creates a Chromecast object from a zeroconf service.""" # Build device status from the mDNS service name info, this # information is the primary source and the remaining will be # fetched later on. - services, uuid, model_name, friendly_name, _, _ = services + services, zconf, uuid, model_name, friendly_name = services _LOGGER.debug("_get_chromecast_from_service %s", services) cast_type = CAST_TYPES.get(model_name.lower(), CAST_TYPE_CHROMECAST) manufacturer = CAST_MANUFACTURERS.get(model_name.lower(), "Google Inc.") @@ -111,15 +106,8 @@ Searches the network for chromecast devices matching a list of friendly names or a list of UUIDs. - Returns a tuple of: - A list of Chromecast objects matching the criteria, - or an empty list if no matching chromecasts were found. - A service browser to keep the Chromecast mDNS data updated. When updates - are (no longer) needed, pass the broswer object to - pychromecast.discovery.stop_discover(). - - To only discover chromcast devices wihtout connecting to them, use - discover_listed_chromecasts instead. + Returns a list of discovered chromecast devices matching the criteria, + or an empty list if no matching chromecasts were found. :param friendly_names: A list of wanted friendly names :param uuids: A list of wanted uuids @@ -130,45 +118,31 @@ devices matching the criteria have been found. """ - cc_list = {} - - def callback(uuid, name): # pylint: disable=unused-argument - _LOGGER.debug("Found chromecast %s", uuid) + cc_list = set() - def get_chromecast_from_uuid(uuid): - return get_chromecast_from_service( - listener.services[uuid], - zconf=zconf, - tries=tries, - retry_wait=retry_wait, - timeout=timeout, - ) - - service = listener.services[uuid] - friendly_name = service[3] - try: - if uuids and uuid in uuids: - if uuid not in cc_list: - cc_list[uuid] = get_chromecast_from_uuid(uuid) - uuids.remove(uuid) - if friendly_names and friendly_name in friendly_names: - if uuid not in cc_list: - cc_list[uuid] = get_chromecast_from_uuid(uuid) - friendly_names.remove(friendly_name) - if not friendly_names and not uuids: - discover_complete.set() - except ChromecastConnectionError: # noqa - pass + def callback(chromecast): + _LOGGER.debug("Found chromecast %s", chromecast) + if uuids and chromecast.uuid in uuids: + cc_list.add(chromecast) + uuids.remove(chromecast.uuid) + elif friendly_names and chromecast.name in friendly_names: + cc_list.add(chromecast) + friendly_names.remove(chromecast.name) + if not friendly_names and not uuids: + discover_complete.set() discover_complete = Event() - - listener = CastListener(callback) - zconf = zeroconf.Zeroconf() - browser = start_discovery(listener, zconf) - + internal_stop = get_chromecasts( + tries=tries, + retry_wait=retry_wait, + timeout=timeout, + callback=callback, + blocking=False, + ) # Wait for the timeout or found all wanted devices discover_complete.wait(discovery_timeout) - return (cc_list.values(), browser) + internal_stop() + return list(cc_list) # pylint: disable=too-many-locals @@ -176,18 +150,10 @@ tries=None, retry_wait=None, timeout=None, blocking=True, callback=None ): """ - Searches the network for chromecast devices and creates a Chromecast object + Searches the network for chromecast devices and creates a Chromecast instance for each discovered device. - Returns a tuple of: - A list of Chromecast objects, or an empty list if no matching chromecasts were - found. - A service browser to keep the Chromecast mDNS data updated. When updates - are (no longer) needed, pass the broswer object to - pychromecast.discovery.stop_discover(). - - To only discover chromcast devices wihtout connecting to them, use - discover_chromecasts instead. + May return an empty list if no chromecasts were found. Parameters tries, timeout, retry_wait and blocking_app_launch controls the behavior of the created Chromecast instances. @@ -207,34 +173,29 @@ """ if blocking: # Thread blocking chromecast discovery - services, browser = discover_chromecasts() + hosts = discover_chromecasts() cc_list = [] - for service in services: + for host in hosts: try: cc_list.append( - get_chromecast_from_service( - service, - browser.zc, - tries=tries, - retry_wait=retry_wait, - timeout=timeout, + get_chromecast_from_host( + host, tries=tries, retry_wait=retry_wait, timeout=timeout ) ) except ChromecastConnectionError: # noqa pass - return (cc_list, browser) + return cc_list # Callback based chromecast discovery if not callable(callback): raise ValueError("Nonblocking discovery requires a callback function.") - def internal_callback(uuid, name): # pylint: disable=unused-argument + def internal_callback(name): """Called when zeroconf has discovered a new chromecast.""" try: callback( - get_chromecast_from_service( - listener.services[uuid], - zconf=zconf, + get_chromecast_from_host( + listener.services[name], tries=tries, retry_wait=retry_wait, timeout=timeout, @@ -243,10 +204,13 @@ except ChromecastConnectionError: # noqa pass + def internal_stop(): + """Stops discovery of new chromecasts.""" + stop_discovery(browser) + listener = CastListener(internal_callback) - zconf = zeroconf.Zeroconf() - browser = start_discovery(listener, zconf) - return browser + browser = start_discovery(listener) + return internal_stop # pylint: disable=too-many-instance-attributes, too-many-public-methods @@ -283,7 +247,7 @@ timeout = kwargs.pop("timeout", None) retry_wait = kwargs.pop("retry_wait", None) services = kwargs.pop("services", None) - zconf = kwargs.pop("zconf", None) + zconf = kwargs.pop("zconf", True) self.logger = logging.getLogger(__name__) diff -Nru pychromecast-7.1.1/pychromecast/socket_client.py pychromecast-6.0.1/pychromecast/socket_client.py --- pychromecast-7.1.1/pychromecast/socket_client.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/pychromecast/socket_client.py 2020-06-28 07:58:09.000000000 +0000 @@ -525,21 +525,12 @@ self.heartbeat_controller.reset() self._force_recon = False - self.logger.debug("Thread started...") - try: - while not self.stop.is_set(): - if self.run_once(timeout=POLL_TIME_BLOCKING) == 1: - break - except Exception: # pylint: disable=broad-except - self.logger.exception( - ("[%s(%s):%s] Unhandled exception in worker thread"), - self.fn or "", - self.host, - self.port, - ) - raise + logging.debug("Thread started...") + while not self.stop.is_set(): + + if self.run_once(timeout=POLL_TIME_BLOCKING) == 1: + break - self.logger.debug("Thread done...") # Clean up self._cleanup() @@ -794,23 +785,11 @@ chunks.append(chunk) bytes_recd += len(chunk) except socket.timeout: - self.logger.debug( - "[%s(%s):%s] timeout in : _read_bytes_from_socket", - self.fn or "", - self.host, - self.port, - ) continue except ssl.SSLError as exc: # Support older ssl implementations which does not raise # socket.timeout on timeouts if _is_ssl_timeout(exc): - self.logger.debug( - "[%s(%s):%s] ssl timeout in : _read_bytes_from_socket", - self.fn or "", - self.host, - self.port, - ) continue raise return b"".join(chunks) diff -Nru pychromecast-7.1.1/README.rst pychromecast-6.0.1/README.rst --- pychromecast-7.1.1/README.rst 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/README.rst 2020-06-28 07:58:09.000000000 +0000 @@ -34,17 +34,11 @@ >> import time >> import pychromecast - >> # List chromecasts on the network, but don't connect - >> services, browser = pychromecast.discovery.discover_chromecasts() - >> # Shut down discovery - >> pychromecast.discovery.stop_discovery(browser) - - >> # Discover and connect to chromecasts named Living Room - >> chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=["Living Room"]) + >> chromecasts = pychromecast.get_chromecasts() >> [cc.device.friendly_name for cc in chromecasts] - ['Living Room'] + ['Dev', 'Living Room', 'Den', 'Bedroom'] - >> cast = chromecasts[0] + >> cast = next(cc for cc in chromecasts if cc.device.friendly_name == "Living Room") >> # Start worker thread and wait for cast device to be ready >> cast.wait() >> print(cast.device) @@ -63,9 +57,6 @@ >> time.sleep(5) >> mc.play() - >> # Shut down discovery - >> pychromecast.discovery.stop_discovery(browser) - Adding support for extra namespaces ----------------------------------- diff -Nru pychromecast-7.1.1/requirements-test.txt pychromecast-6.0.1/requirements-test.txt --- pychromecast-7.1.1/requirements-test.txt 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/requirements-test.txt 2020-06-28 07:58:09.000000000 +0000 @@ -1,3 +1,3 @@ -flake8==3.8.3 +flake8==3.7.9 pylint==2.4.4 black==19.10b0 diff -Nru pychromecast-7.1.1/setup.py pychromecast-6.0.1/setup.py --- pychromecast-7.1.1/setup.py 2020-07-03 15:22:29.000000000 +0000 +++ pychromecast-6.0.1/setup.py 2020-06-28 07:58:09.000000000 +0000 @@ -5,7 +5,7 @@ setup( name="PyChromecast", - version="7.1.1", + version="6.0.0", license="MIT", url="https://github.com/balloob/pychromecast", author="Paulus Schoutsen",