Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    def connect(self):
        if self.cast is None:
            Chromecast.discoverDevices(None)

            self.cast = Chromecast.CAST_LIST.get(self.config['name'])

            if not self.cast:
                self.logger.debug('Host not found for %s. Discovering',
                                  self.config['name'])
                hosts = discover_chromecasts()
                for host in hosts:
                    if host[Chromecast.
                            FRIENDLY_NAME_OFFSET] == self.config['name']:
                        self.logger.debug('Host found')
                        self.cast = pychromecast._get_chromecast_from_host(
                            host, Chromecast.CAST_CONNECT_TRIES)
                        Chromecast.CAST_LIST[self.config['name']] = self.cast
                        break

        self.connected = False
        if self.cast:
            self.cast.wait()
            self.connected = self.cast.socket_client.is_connected
            if not self.connected:
                self.disconnect()
Exemplo n.º 3
0
    def add_chromecast(name):
        cc = pychromecast._get_chromecast_from_host(
            listener.services[name],
            tries=5,
            blocking=False,
        )

        chromecasts[name] = cc
        publish_chromecast()
Exemplo n.º 4
0
def chrome():
    ##    chromecasts = pychromecast.get_chromecasts(timeout=1)
    ##    for c in chromecasts:
    ##        print(c.device)
    ##        if c.device.friendly_name == "Portable TV":
    ##            print("Device Found")
    ##            mc = c.media_controller
    ##            print(c.host, c.port, c.device.uuid, c.device.model_name, c.device.friendly_name)
    ##            mc.play_media('http://192.168.2.48:8000/air.mp3', 'audio/mp3')
    ##            time.sleep(5)
    ##            c.disconnect()
    c = pychromecast._get_chromecast_from_host(
        host('192.168.2.12', 8009, 'd94f0900-ca79-f99a-2ad9-48bebdf53a27',
             'Chromecast', 'Portable TV'))
    if c.device.friendly_name == "Portable TV":
        #       print("Device Found")
        mc = c.media_controller
        #        print(c.host, c.port, c.device.uuid, c.device.model_name, c.device.friendly_name)
        mc.play_media('http://192.168.2.48:8000/C:/Users/Cameron/air.mp3',
                      'audio/mp3')
Exemplo n.º 5
0
    def internal_callback(name):
        """Called when zeroconf has discovered a new chromecast."""
        mdns = listener.services[name]
        ip_address, port, uuid, _, _ = mdns
        key = (ip_address, port, uuid)

        if key in hass.data[KNOWN_CHROMECASTS_KEY]:
            _LOGGER.debug("Discovered previous chromecast %s", mdns)
            return

        _LOGGER.debug("Discovered new chromecast %s", mdns)
        try:
            # pylint: disable=protected-access
            chromecast = pychromecast._get_chromecast_from_host(
                mdns, blocking=True)
        except pychromecast.ChromecastConnectionError:
            _LOGGER.debug("Can't set up cast with mDNS info %s. "
                          "Assuming it's not a Chromecast", mdns)
            return
        hass.data[KNOWN_CHROMECASTS_KEY][key] = chromecast
        dispatcher_send(hass, SIGNAL_CAST_DISCOVERED, chromecast)
Exemplo n.º 6
0
    def internal_callback(name):
        """Called when zeroconf has discovered a new chromecast."""
        mdns = listener.services[name]
        ip_address, port, uuid, _, _ = mdns
        key = (ip_address, port, uuid)

        if key in hass.data[KNOWN_CHROMECASTS_KEY]:
            _LOGGER.debug("Discovered previous chromecast %s", mdns)
            return

        _LOGGER.debug("Discovered new chromecast %s", mdns)
        try:
            # pylint: disable=protected-access
            chromecast = pychromecast._get_chromecast_from_host(mdns,
                                                                blocking=True)
        except pychromecast.ChromecastConnectionError:
            _LOGGER.debug(
                "Can't set up cast with mDNS info %s. "
                "Assuming it's not a Chromecast", mdns)
            return
        hass.data[KNOWN_CHROMECASTS_KEY][key] = chromecast
        dispatcher_send(hass, SIGNAL_CAST_DISCOVERED, chromecast)
Exemplo n.º 7
0
 def _create_pychromecast(self):
     chromecast = pychromecast._get_chromecast_from_host(
         (self.ip, self.port, self.udn, self.model_name, self.name))
     return chromecast