Esempio n. 1
0
    def getChromecastDevice(self, device_name: str) -> None:
        # Get cast from discovered devices of cast platform
        known_devices = get_cast_devices(self.hass)

        _LOGGER.debug("Chromecast devices: %s", known_devices)
        cast_info = next(
            (
                castinfo
                for castinfo in known_devices
                if castinfo.friendly_name == device_name
            ),
            None,
        )
        _LOGGER.debug("cast info: %s", cast_info)
        if cast_info:
            return pychromecast.get_chromecast_from_cast_info(
                cast_info.cast_info, ChromeCastZeroconf.get_zeroconf()
            )
        _LOGGER.error(
            "Could not find device %s from hass.data",
            device_name,
        )
        raise HomeAssistantError(
            "Could not find device with name {}".format(device_name)
        )
Esempio n. 2
0
    async def async_cast_discovered(self,
                                    discover: ChromecastInfo,
                                    likely_already_started=False):
        _LOGGER.debug("Discovered {}".format(discover.host))
        if discover.is_audio_group:
            return

        if not likely_already_started:
            # eureka_info might not return something, if the device just started up
            await asyncio.sleep(10)

        self._hass.data[DOMAIN].setdefault(discover.uuid, {})
        if await self._hass.data[CLIENT].update_info(discover.host,
                                                     discover.uuid):
            info = self._hass.data[DOMAIN][discover.uuid]["info"]
            if info["device_info"][
                    "cloud_device_id"] not in self._active_devices and await self.supported(
                        discover):
                chromecast = await self._hass.async_add_executor_job(
                    pychromecast.get_chromecast_from_service,
                    (
                        discover.services,
                        discover.uuid,
                        discover.model_name,
                        discover.friendly_name,
                        None,
                        None,
                    ),
                    ChromeCastZeroconf.get_zeroconf(),
                )
                chromecast.register_connection_listener(self)
                self._active_devices[info["device_info"][
                    "cloud_device_id"]] = await self.setup(discover)
Esempio n. 3
0
    def getChromecastDevice(self, device_name):
        import pychromecast

        # Get cast from discovered devices of cast platform
        known_devices = list(self.discovered_casts.values())
        _LOGGER.debug("Chromecast devices: %s", known_devices)

        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:
            zconf = ChromeCastZeroconf.get_zeroconf()
            return pychromecast.get_chromecast_from_cast_info(cast_info, zconf)
        _LOGGER.error(
            "Could not find device %s from hass.data",
            device_name,
        )

        raise HomeAssistantError(
            "Could not find device with name {}".format(device_name))
    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, [])

        _LOGGER.debug("Chromecast devices: %s", known_devices)
        try:
            # HA below 0.113
            cast_info = next((x for x in known_devices if x.friendly_name == device_name), None)
        except:
            cast_info = next(
                (
                    known_devices[x]
                    for x in known_devices
                    if known_devices[x].friendly_name == device_name
                ),
                None,
            )

        _LOGGER.debug("cast info: %s", cast_info)

        if cast_info:
            return pychromecast.get_chromecast_from_service(
                  (
                     cast_info.services,
                     cast_info.uuid,
                     cast_info.model_name,
                     cast_info.friendly_name,
                     None,
                     None,
                 ),
                 ChromeCastZeroconf.get_zeroconf()) 
        _LOGGER.error(
            "Could not find device %s from hass.data",
            device_name,
        )

        raise HomeAssistantError("Could not find device with name {}".format(device_name))