コード例 #1
0
def get_device_uuids():
    device_uuids = {}
    devices, browser = pychromecast.discover_chromecasts()
    pychromecast.stop_discovery(browser)
    for mDNS, uuid, model, name, ip, port in devices:
        device_uuids[name.casefold()] = uuid
    return device_uuids
コード例 #2
0
 def get_device(cls, name):
     uuid = cls.device_uuids.get(name.casefold())
     if uuid:
         devices, browser = pychromecast.get_listed_chromecasts(uuids=[uuid])
         pychromecast.stop_discovery(browser)
         if devices:
             return list(devices)[0]
         else:
             raise NotFoundError('Device ' + name)
     else:
         device = find_by_attr(cls.get_devices(), 'name', name, case_sensitive=False)
         if device:
             cls.device_uuids[device['name']] = device['uuid']
             return device
         else:
             raise NotFoundError('Device ' + name)
コード例 #3
0
ファイル: discovery.py プロジェクト: kimocoder/catt
def get_cast_devices(names: Optional[List[str]] = None) -> List[CastDevice]:
    """
    Discover all available devices, optionally filtering them with list of specific device names
    (which will speedup discovery, as pychromecast does this in a non-blocking manner).

    :param names: Optional list of device names.
    :type names: List[str]
    :returns: List of CastDevice wrapper objects containing cast object and additional ip/port info.
    :rtype: List[CastDevice]
    """

    if names:
        services, browser = pychromecast.discovery.discover_listed_chromecasts(
            friendly_names=names)
    else:
        services, browser = pychromecast.discovery.discover_chromecasts()
    pychromecast.stop_discovery(browser)

    devices = [
        CastDevice(pychromecast.get_chromecast_from_service(s, browser.zc),
                   s[4], s[5]) for s in services
    ]
    devices.sort(key=lambda d: d.cast.name)
    return devices
コード例 #4
0
 def stop_discovery(event):
     """Stop discovery of new chromecasts."""
     _LOGGER.debug("Stopping internal pychromecast discovery.")
     pychromecast.stop_discovery(browser)
     hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].release()
コード例 #5
0
ファイル: cast.py プロジェクト: sander76/home-assistant
 def stop_discovery(event):
     """Stop discovery of new chromecasts."""
     _LOGGER.debug("Stopping internal pychromecast discovery.")
     pychromecast.stop_discovery(browser)
     hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].release()
コード例 #6
0
        print("  {} {}".format(uuid, service))


def add_callback(uuid, name):
    print("Found mDNS service for cast device {}".format(uuid))
    list_devices()


def remove_callback(uuid, name, service):
    print("Lost mDNS service for cast device {} {}".format(uuid, 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)

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    pass

pychromecast.stop_discovery(browser)
コード例 #7
0
 def stop_discovery(event):
     """Stop discovery of new chromecasts."""
     pychromecast.stop_discovery(browser)
     hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].release()
コード例 #8
0
ファイル: cast.py プロジェクト: simpss/home-assistant
 def stop_discovery(event):
     """Stop discovery of new chromecasts."""
     pychromecast.stop_discovery(browser)
     hass.data[INTERNAL_DISCOVERY_RUNNING_KEY].release()
コード例 #9
0
	def _stop(self):
		pychromecast.stop_discovery(self.browser)
		self.runFlag = False
コード例 #10
0
 def get_devices(cls):
     devices, browser = pychromecast.get_chromecasts()
     pychromecast.stop_discovery(browser)
     return devices