当前位置: 首页>>代码示例>>Python>>正文


Python pychromecast.get_chromecasts方法代码示例

本文整理汇总了Python中pychromecast.get_chromecasts方法的典型用法代码示例。如果您正苦于以下问题:Python pychromecast.get_chromecasts方法的具体用法?Python pychromecast.get_chromecasts怎么用?Python pychromecast.get_chromecasts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pychromecast的用法示例。


在下文中一共展示了pychromecast.get_chromecasts方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def update(self):
        import pychromecast
        # from cast/media_player.py but is missing cast_type
        # KNOWN_CHROMECAST_INFO_KEY = 'cast_known_chromecasts'
        # _LOGGER.info('KNOWN_CHROMECAST_INFO_KEY: %s', self.hass.data[KNOWN_CHROMECAST_INFO_KEY])

        self._chromecast_devices = pychromecast.get_chromecasts()
        _LOGGER.debug('Found chromecast devices: %s', self._chromecast_devices)
        chromecasts = []
        for cast in self._chromecast_devices:
            device = {
                'name': cast.name,
                'cast_type': cast.cast_type,
                'model_name': cast.model_name,
                'uuid': str(cast.uuid),
                'manufacturer': cast.device.manufacturer
            }
            chromecasts.append(device)
        self._attributes['devices_json'] = json.dumps(chromecasts, ensure_ascii=False)
        self._attributes['devices'] = chromecasts
        self._attributes['last_update'] = dt.now().isoformat('T')
        self._state = STATE_OK 
开发者ID:fondberg,项目名称:spotcast,代码行数:24,代码来源:sensor.py

示例2: _connect_chromecast

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def _connect_chromecast(self, available_devices=None):
        ''' Attempt to (re)connect to cast device named in `__init__`. '''

        self.cast = None

        if not available_devices:
            available_devices = pychromecast.get_chromecasts(tries=1)

        matching_devices = [
            c for c in available_devices
            if c.device.friendly_name == self.cast_name
        ]

        if not matching_devices:
            click.echo('Could not connect to device "%s"' % self.cast_name)
            return

        if len(matching_devices) > 1:
            click.echo('WARNING: Multiple devices available. Choosing first.')

        self.cast = matching_devices[0]

        # Wait for the device to be available
        self.cast.wait()
        click.echo('Using chromecast: %s' % self.cast.device.friendly_name) 
开发者ID:erik,项目名称:lastcast,代码行数:27,代码来源:__init__.py

示例3: run

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def run(self):
        if not self.args["rhost"] and not self.args["name"]:
            print_info("Show options, it's necessary to configure onename or rhost")
            return
        if str(self.args["timeout"]) == "None":
            self.args["timeout"] = 6
        try:
            chromecasts = pychromecast.get_chromecasts(timeout=self.args["timeout"])
            cast = next(cc for cc in chromecasts if (cc.device.friendly_name == self.args["name"] or cc.host == self.args["rhost"]))
            cast.wait()
            print_info("Device found, sending video")
        except:
            print_error("Device no found")
            return

        yt = YouTubeController()
        cast.register_handler(yt)
        yt.play_video(self.args["video"])
        print_ok("Done!") 
开发者ID:ElevenPaths,项目名称:HomePWN,代码行数:21,代码来源:send-video-youtube-v2.py

示例4: get_chromecasts

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def get_chromecasts() -> List[pychromecast.Chromecast]:
    devices = pychromecast.get_chromecasts()
    devices.sort(key=lambda cc: cc.name)
    return devices 
开发者ID:skorokithakis,项目名称:catt,代码行数:6,代码来源:controllers.py

示例5: get_chromecast

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def get_chromecast(device_name: Optional[str]) -> Optional[pychromecast.Chromecast]:
    devices = get_chromecasts()
    if not devices:
        return None

    if device_name:
        try:
            return next(cc for cc in devices if cc.name == device_name)
        except StopIteration:
            return None
    else:
        return devices[0] 
开发者ID:skorokithakis,项目名称:catt,代码行数:14,代码来源:controllers.py

示例6: __init__

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def __init__(self):
        vhash = hashlib.sha1(__version__.encode()).hexdigest()[:8]
        cache_path = Path(tempfile.gettempdir(), "catt_{}_cache".format(vhash), "chromecast_hosts")
        super(Cache, self).__init__(cache_path)
        self._create_store_dir()

        if not self.store_path.is_file():
            devices = get_chromecasts()
            cache_data = {
                d.name: CCInfo(d.host, d.port, d.device.manufacturer, d.model_name, d.cast_type).all_info
                for d in devices
            }
            self._write_store(cache_data) 
开发者ID:skorokithakis,项目名称:catt,代码行数:15,代码来源:controllers.py

示例7: getChromecastDevice

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def getChromecastDevice(self, device_name):
        import pychromecast

        # Get cast from discovered devices of cast platform
        known_devices = self.hass.data.get(KNOWN_CHROMECAST_INFO_KEY, [])
        cast_info = next((x for x in known_devices if x.friendly_name == device_name), None)
        _LOGGER.debug("cast info: %s", cast_info)

        if cast_info:
            return pychromecast._get_chromecast_from_host(
                (
                    cast_info.host,
                    cast_info.port,
                    cast_info.uuid,
                    cast_info.model_name,
                    cast_info.friendly_name,
                )
            )
        _LOGGER.error(
            "Could not find device %s from hass.data, falling back to pychromecast scan",
            device_name,
        )

        # Discover devices manually
        chromecasts = pychromecast.get_chromecasts()
        for _cast in chromecasts:
            if _cast.name == device_name:
                _LOGGER.debug("Fallback, found cast device: %s", _cast)
                return _cast

        raise HomeAssistantError("Could not find device with name {}".format(device_name)) 
开发者ID:fondberg,项目名称:spotcast,代码行数:33,代码来源:__init__.py

示例8: _internal_create_connection

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def _internal_create_connection(self, device_name):
        try:
            self.mqtt_properties.write_connection_status(CONNECTION_STATUS_WAITING_FOR_DEVICE)
            devices = get_chromecasts(tries=5)

            for device in devices:
                if device.device.friendly_name == device_name:
                    self.device = device
                    break

            if self.device is None:
                self.logger.error("was not able to find chromecast %s" % self.device_name)
                raise ConnectionUnavailableException()

            self.device.wait()
            self.device.register_status_listener(self)
            self.device.media_controller.register_status_listener(self)
            self.device.register_launch_error_listener(self)
            self.device.register_connection_listener(self)

            self.device_connected = True  # alibi action
            self.logger.info("connected to chromecast %s" % self.device_name)
        except PyChromecastError:
            self.logger.exception("had connection error while finding chromecast %s" % self.device_name)

            self.device_connected = False 
开发者ID:nohum,项目名称:chromecast-mqtt-connector,代码行数:28,代码来源:adapter.py

示例9: find

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def find(config: Config) -> typing.List[Device]:
        return [
            ChromecastDevice(device)
            for device in pychromecast.get_chromecasts(
                timeout=config.chromecast_scan_timeout)
        ] 
开发者ID:andrew-ld,项目名称:smart-tv-telegram,代码行数:8,代码来源:chromecast_device.py

示例10: get_chromecast

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def get_chromecast(self, chromecast=None, n_tries=2):
        import pychromecast
        if isinstance(chromecast, pychromecast.Chromecast):
            return chromecast

        if not chromecast:
            if not self.chromecast:
                raise RuntimeError('No Chromecast specified nor default Chromecast configured')
            chromecast = self.chromecast

        if chromecast not in self.chromecasts:
            casts = {}
            while n_tries > 0:
                n_tries -= 1
                casts.update({
                    cast.device.friendly_name: cast
                    for cast in pychromecast.get_chromecasts()
                })

                if chromecast in casts:
                    self.chromecasts.update(casts)
                    break

            if chromecast not in self.chromecasts:
                raise RuntimeError('Device {} not found'.format(chromecast))

        cast = self.chromecasts[chromecast]
        cast.wait()
        return cast 
开发者ID:BlackLight,项目名称:platypush,代码行数:31,代码来源:chromecast.py

示例11: run

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def run(self):
        print_info("Searching devices")
        chromecasts = pychromecast.get_chromecasts(timeout=self.args["timeout"])
        if chromecasts:
            for cast in [cc for cc in chromecasts]:
                print_info(f"{cast.device.friendly_name} ({cast.device.cast_type} - {cast.device.manufacturer}) => {cast.host}")
        else:
            print_info("No devices found") 
开发者ID:ElevenPaths,项目名称:HomePWN,代码行数:10,代码来源:discovery.py

示例12: load_casts

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def load_casts(self, device=None):
    chromecasts = pychromecast.get_chromecasts()
    def f():
      self.cast_store.clear()
      self.cast_store.append([None, "Select a cast device..."])
      self.cast_store.append([-1, 'Add a non-local Chromecast...'])
      for cc in chromecasts:
        friendly_name = cc.device.friendly_name
        if cc.cast_type!='cast':
          friendly_name = '%s (%s)' % (friendly_name, cc.cast_type)
        self.cast_store.append([cc, friendly_name])
      if device:
        found = False
        for i, cc in enumerate(chromecasts):
          if device == cc.device.friendly_name:
            self.cast_combo.set_active(i+1)
            found = True
        if not found:
          self.cast_combo.set_active(0)
          dialog = Gtk.MessageDialog(self.win, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "Chromecast Not Found")
          dialog.format_secondary_text("The Chromecast '%s' wasn't found." % device)
          dialog.run()
          dialog.destroy()
      else:
        self.cast_combo.set_active(2 if len(chromecasts) == 1 else 0)
    GLib.idle_add(f) 
开发者ID:keredson,项目名称:gnomecast,代码行数:28,代码来源:gnomecast.py

示例13: main

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def main(config, wizard, verbose):
    if verbose:
        logger.setLevel('DEBUG')
    else:
        # pychromecast is by default pretty noisy about caught exceptions
        logging.getLogger('pychromecast').setLevel('CRITICAL')

    if wizard:
        return config_wizard()

    paths = [config] if config else ['./lastcast.toml', '~/.lastcast.toml']

    for path in paths:
        path = os.path.expanduser(path)
        if os.path.exists(path):
            config = load_config(path)
            break
    else:
        click.echo('Config file not found!\n\nUse --wizard to create a config')
        sys.exit(1)

    cast_config = config.get('chromecast', {})
    device_names = cast_config.get('devices', [])

    # `name` is the legacy parameter name, supporting it for now.
    if not device_names and 'name' in cast_config:
        device_names = [cast_config['name']]

    if not device_names:
        click.echo('Need to specify either `devices` or `name` in '
                   '`[chromecast]` config block!')
        sys.exit(1)

    available = pychromecast.get_chromecasts()
    listeners, missing = connect_to_devices(config, device_names, available)

    retry_missing = cast_config.get('retry_missing', False)
    if cast_config.get('ignore_missing', False) and missing:
        click.echo('Continuing without missing devices: %s' % ', '.join(missing))
        missing = []

    if missing and not retry_missing:
        click.echo('Failed to connect to %s. Exiting' % ', '.join(missing))
        click.echo('Available devices: %s' % ', '.join([
            d.device.friendly_name for d in available
        ]))
        sys.exit(1)

    for i in itertools.count():
        for listener in listeners:
            listener.poll()

        # If we have any devices missing, periodically try to connect to them
        if retry_missing and missing and i % RECONNECT_INTERVAL == 0:
            click.echo('Retrying missing devices: %s' % ', '.join(missing))
            available = pychromecast.get_chromecasts(tries=1)

            new_devices, missing = connect_to_devices(config, missing, available)
            listeners.extend(new_devices)

        time.sleep(POLL_INTERVAL) 
开发者ID:erik,项目名称:lastcast,代码行数:63,代码来源:__init__.py

示例14: get_chromecasts

# 需要导入模块: import pychromecast [as 别名]
# 或者: from pychromecast import get_chromecasts [as 别名]
def get_chromecasts(self, tries=2, retry_wait=10, timeout=60,
                        blocking=True, callback=None):
        """
        Get the list of Chromecast devices

        :param tries: Number of retries (default: 2)
        :type tries: int

        :param retry_wait: Number of seconds between retries (default: 10 seconds)
        :type retry_wait: int

        :param timeout: Timeout before failing the call (default: 60 seconds)
        :type timeout: int

        :param blocking: If true, then the function will block until all the Chromecast
            devices have been scanned. If false, then the provided callback function will be
            invoked when a new device is discovered
        :type blocking: bool

        :param callback: If blocking is false, then you can provide a callback function that
            will be invoked when a new device is discovered
        :type callback: func
        """

        import pychromecast
        self.chromecasts.update({
            cast.device.friendly_name: cast
            for cast in pychromecast.get_chromecasts(tries=tries, retry_wait=retry_wait,
                                                     timeout=timeout, blocking=blocking,
                                                     callback=callback)
        })

        for name, cast in self.chromecasts.items():
            self._update_listeners(name, cast)

        return [{
            'type': cc.cast_type,
            'name': cc.name,
            'manufacturer': cc.device.manufacturer,
            'model_name': cc.model_name,
            'uuid': str(cc.device.uuid),
            'address': cc.host,
            'port': cc.port,

            'status': ({
                'app': {
                    'id': cc.app_id,
                    'name': cc.app_display_name,
                },

                'media': self.status(cc.name).output,
                'is_active_input': cc.status.is_active_input,
                'is_stand_by': cc.status.is_stand_by,
                'is_idle': cc.is_idle,
                'namespaces': cc.status.namespaces,
                'volume': round(100*cc.status.volume_level, 2),
                'muted': cc.status.volume_muted,
            } if cc.status else {}),
        } for cc in self.chromecasts.values()] 
开发者ID:BlackLight,项目名称:platypush,代码行数:61,代码来源:chromecast.py


注:本文中的pychromecast.get_chromecasts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。