How to use the catt.error.CastError function in catt

To help you get started, we’ve selected a few catt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github skorokithakis / catt / catt / controllers.py View on Github external
cast = get_chromecast_with_ip(device, DEFAULT_PORT)
        if not cast:
            msg = "No device found at {}".format(device)
            raise CastError(msg)
        cc_info = CCInfo(cast.host, cast.port, None, None, cast.cast_type)
    else:
        cache = Cache()
        cc_info = cache.get_data(device)

        if cc_info:
            cast = get_chromecast_with_ip(cc_info.ip, cc_info.port)
        if not cast:
            cast = get_chromecast(device)
            if not cast:
                msg = 'Specified device "{}" not found'.format(device) if device else "No devices found"
                raise CastError(msg)
            cc_info = CCInfo(cast.host, cast.port, cast.device.manufacturer, cast.model_name, cast.cast_type)
            cache.set_data(cast.name, cc_info)

    cast.wait()
    return (cast, cc_info)
github skorokithakis / catt / catt / api.py View on Github external
def _create_cast(self) -> None:
        self._cast = get_chromecast_with_ip(self.ip_addr) if self.ip_addr else get_chromecast(self.name)
        if not self._cast:
            raise CastError("Device could not be found")
        self._cast.wait()

        self.name = self._cast.name
        self.ip_addr = self._cast.host
        self.uuid = self._cast.uuid
github skorokithakis / catt / catt / controllers.py View on Github external
def prep_control(self):
        """Make sure chromecast is not inactive or idle."""

        self._check_inactive()
        self._update_status()
        if self._is_idle:
            raise CastError("Nothing is currently playing")
github skorokithakis / catt / catt / controllers.py View on Github external
def _check_inactive(self):
        if self._cast.app_id == BACKDROP_APP_ID or not self._cast.app_id:
            raise CastError("Chromecast is inactive")
github skorokithakis / catt / catt / controllers.py View on Github external
def seek(self, seconds: int) -> None:
        if self._is_seekable:
            self._cast.media_controller.seek(seconds)
        else:
            raise CastError("Stream is not seekable")
github skorokithakis / catt / catt / cli.py View on Github external
def info(settings, json_output):
    try:
        cst = setup_cast(settings["device"], prep="info")
    except CastError:
        if json_output:
            info = {}
        else:
            raise
    else:
        info = cst.info

    if json_output:
        echo_json(info)
    else:
        for (key, value) in info.items():
            click.echo("{}: {}".format(key, value))
github skorokithakis / catt / catt / controllers.py View on Github external
def wait_for(self, states: list, invert: bool = False, fail: bool = False, timeout: Optional[int] = None) -> bool:
        media_listener = MediaStatusListener(
            self._cast.media_controller.status.player_state, states, invert=invert, fail=fail
        )
        self._cast.media_controller.register_status_listener(media_listener)

        try:
            return media_listener.wait_for_states(timeout=timeout)
        except pychromecast.error.UnsupportedNamespace:
            raise CastError("Chromecast app operation was interrupted")