How to use the pychromecast.PyChromecast function in PyChromecast

To help you get started, we’ve selected a few PyChromecast 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 home-assistant / home-assistant / homeassistant / components / chromecast.py View on Github external
return False

    if ha.CONF_HOSTS in config[DOMAIN]:
        hosts = config[DOMAIN][ha.CONF_HOSTS].split(",")

    # If no hosts given, scan for chromecasts
    else:
        logger.info("Scanning for Chromecasts")
        hosts = pychromecast.discover_chromecasts()

    casts = {}

    for host in hosts:
        try:
            cast = pychromecast.PyChromecast(host)

            entity_id = util.ensure_unique_string(
                ENTITY_ID_FORMAT.format(
                    util.slugify(cast.device.friendly_name)),
                list(casts.keys()))

            casts[entity_id] = cast

        except pychromecast.ChromecastConnectionError:
            pass

    if not casts:
        logger.error("Could not find Chromecasts")
        return False

    def update_chromecast_state(entity_id, chromecast):
github jaapz / cast / cast.py View on Github external
def main():
    """ Read the options given on the command line and do the required actions.

    This method is used in the entry_point `cast`.
    """
    opts = docopt(__doc__, version="cast 0.1")

    cast = pychromecast.PyChromecast(CHROMECAST_HOST)
    ramp = cast.get_protocol(pychromecast.PROTOCOL_RAMP)

    # Wait for ramp connection to be initted.
    time.sleep(SLEEP_TIME)

    if opts['next'] is True:
        ramp.next()
    elif opts['pause'] is True:
        ramp.pause()
    elif opts['play'] is True:
        ramp.play()
    elif opts['status'] is True:
        # TODO: make this into a user readable text
        print cast.app
    elif opts['volume'] is True:
        _volume_command(ramp, opts[''])
github BishopFox / rickmote / rickmote.py View on Github external
def PlayVideo(self):
        cast = pc.PyChromecast()
        print cast.device

        # Make sure an app is running that supports RAMP protocol
        if not cast.app or pc.PROTOCOL_RAMP not in cast.app.service_protocols:
            pc.play_youtube_video(YOUTUBE_SUFFIX, cast.host)
            cast.refresh()

        ramp = cast.get_protocol(pc.PROTOCOL_RAMP)

        # It can take some time to setup websocket connection
        # if we just switched to a new channel
        while not ramp:
            time.sleep(1)
            ramp = cast.get_protocol(pc.PROTOCOL_RAMP)

        # Give ramp some time to init