def install_sound(vac: miio.Vacuum, url: str, md5sum: str, sid: int):
    """Install a sound."""
    click.echo("Installing from %s (md5: %s) for id %s" % (url, md5sum, sid))
    click.echo(vac.install_sound(url, md5sum, sid))

    progress = vac.sound_install_progress()
    while progress.is_installing:
        print(progress)
        progress = vac.sound_install_progress()
        time.sleep(0.1)

    if progress.progress == 100 and progress.error == 0:
        click.echo("Installation of sid '%s' complete!" % progress.sid)
    else:
        click.echo("Error during installation: %s" % progress.error)
Beispiel #2
0
def install_sound(vac: miio.Vacuum, url: str, md5sum: str, sid: int, ip: str):
    """Install a sound.

    When passing a local file this will create a self-hosting server
     for the given file and the md5sum will be calculated automatically.

    For URLs you have to specify the md5sum manually.

    `--ip` can be used to override automatically detected IP address for
     the device to contact for the update.
    """
    click.echo("Installing from %s (md5: %s) for id %s" % (url, md5sum, sid))

    local_url = None
    server = None
    if url.startswith("http"):
        if md5sum is None:
            click.echo("You need to pass md5 when using URL for updating.")
            return
        local_url = url
    else:
        server = OneShotServer(url)
        local_url = server.url(ip)
        md5sum = server.md5

        t = threading.Thread(target=server.serve_once)
        t.start()
        click.echo("Hosting file at %s" % local_url)

    click.echo(vac.install_sound(local_url, md5sum, sid))

    progress = vac.sound_install_progress()
    while progress.is_installing:
        progress = vac.sound_install_progress()
        click.echo("%s (%s %%)" % (progress.state.name, progress.progress))
        time.sleep(1)

    progress = vac.sound_install_progress()

    if progress.is_errored:
        click.echo("Error during installation: %s" % progress.error)
    else:
        click.echo("Installation of sid '%s' complete!" % sid)

    if server is not None:
        t.join()
Beispiel #3
0
def sound(vac: miio.Vacuum, volume: int, test_mode: bool):
    """Query and change sound settings."""
    if volume is not None:
        click.echo("Setting sound volume to %s" % volume)
        vac.set_sound_volume(volume)
    if test_mode:
        vac.test_sound_volume()
    click.echo("Current sound: %s" % vac.sound_info())
    click.echo("Current volume: %s" % vac.sound_volume())
    click.echo("Install progress: %s" % vac.sound_install_progress())
Beispiel #4
0
def install_sound(vac: miio.Vacuum, url: str, md5sum: str, sid: int):
    """Install a sound."""
    click.echo("Installing from %s (md5: %s) for id %s" % (url, md5sum, sid))

    local_url = None
    server = None
    if url.startswith("http"):
        if md5sum is None:
            click.echo("You need to pass md5 when using URL for updating.")
            return
        local_url = url
    else:
        server = OneShotServer(url)
        local_url = server.url()
        md5sum = server.md5

        t = threading.Thread(target=server.serve_once)
        t.start()
        click.echo("Hosting file at %s" % local_url)

    click.echo(vac.install_sound(local_url, md5sum, sid))

    progress = vac.sound_install_progress()
    while progress.is_installing:
        progress = vac.sound_install_progress()
        print("%s (%s %%)" % (progress.state.name, progress.progress))
        time.sleep(1)

    progress = vac.sound_install_progress()

    if progress.is_errored:
        click.echo("Error during installation: %s" % progress.error)
    else:
        click.echo("Installation of sid '%s' complete!" % sid)

    if server is not None:
        t.join()