diff --git a/mirobo/device.py b/mirobo/device.py index 72e9e8c80..a8f44021f 100644 --- a/mirobo/device.py +++ b/mirobo/device.py @@ -13,6 +13,29 @@ class DeviceException(Exception): pass +class DeviceInfo: + def __init__(self, data): + self.data = data + + def __repr__(self): + return "%s v%s (%s) @ %s - token: %s" % (self.data["model"], + self.data["fw_ver"], + self.data["mac"], + self.netif["localIp"], + self.data["token"]) + @property + def netif(self): + return self.data["netif"] + + @property + def ap(self): + return self.data["ap"] + + @property + def raw(self): + return self.data + + class Device: def __init__(self, ip: str, token: str, start_id: int=0, debug: int=0) -> None: @@ -144,6 +167,9 @@ def send(self, command: str, parameters: Any=None, retry_count=3) -> Any: return self.send(command, parameters, retry_count-1) raise DeviceException from ex + def info(self): + return DeviceInfo(self.send("miIO.info", [])) + @property def _id(self) -> int: """Returns running id.""" diff --git a/mirobo/vacuum.py b/mirobo/vacuum.py index 5adc4168e..8831d138e 100644 --- a/mirobo/vacuum.py +++ b/mirobo/vacuum.py @@ -3,8 +3,8 @@ import time from typing import List -from .containers import (VacuumStatus, ConsumableStatus, - CleaningSummary, CleaningDetails, Timer) +from .vacuumcontainers import (VacuumStatus, ConsumableStatus, + CleaningSummary, CleaningDetails, Timer) from .device import Device, DeviceException _LOGGER = logging.getLogger(__name__) @@ -86,6 +86,10 @@ def status(self) -> VacuumStatus: """Return status of the vacuum.""" return VacuumStatus(self.send("get_status")[0]) + def enable_log_upload(self): + raise NotImplementedError("unknown parameters") + return self.send("enable_log_upload") + def log_upload_status(self): # {"result": [{"log_upload_status": 7}], "id": 1} return self.send("get_log_upload_status") @@ -94,6 +98,11 @@ def consumable_status(self) -> ConsumableStatus: """Return information about consumables.""" return ConsumableStatus(self.send("get_consumable")[0]) + def consumable_reset(self): + """Reset consumable information.""" + raise NotImplementedError() + self.send("reset_consumable", ["unknown"]) + def map(self): """Return map token.""" # returns ['retry'] without internet @@ -129,6 +138,7 @@ def set_timer(self, details): # how to create timers/change values? # ['ts', 'on'] to enable raise NotImplementedError() + return self.send("set_timer", [["ts",["cron_line",["start_clean",""]]]]) return self.send("upd_timer", ["ts", "on"]) def dnd_status(self): @@ -156,6 +166,22 @@ def fan_speed(self): """Return fan speed.""" return self.send("get_custom_mode")[0] + def sound_info(self): + """Get voice settings.""" + return self.send("get_current_sound") + + def serial_number(self): + """Get serial number.""" + return self.send("get_serial_number")[0]["serial_number"] + + def timezone(self): + """Get the timezone.""" + return self.send("get_timezone")[0] + + def set_timezone(self, new_zone): + """Set the timezone.""" + return self.send("set_timezone", [new_zone])[0] == 'ok' + def raw_command(self, cmd, params): """Send a raw command to the robot.""" return self.send(cmd, params) diff --git a/mirobo/vacuum_cli.py b/mirobo/vacuum_cli.py index f2e1062d2..6414fa20e 100644 --- a/mirobo/vacuum_cli.py +++ b/mirobo/vacuum_cli.py @@ -6,6 +6,7 @@ import sys import json import ipaddress +from pprint import pformat as pf from typing import Any if sys.version_info < (3, 4): @@ -40,6 +41,7 @@ def validate_token(ctx, param, value): @click.option('-d', '--debug', default=False, count=True) @click.option('--id-file', type=click.Path(dir_okay=False, writable=True), default='/tmp/python-mirobo.seq') +@click.version_option() @click.pass_context def cli(ctx, ip: str, token: str, debug: int, id_file: str): """A tool to command Xiaomi Vacuum robot.""" @@ -320,6 +322,15 @@ def map(vac: mirobo.Vacuum): click.echo(vac.map()) +@cli.command() +@pass_dev +def info(vac: mirobo.Vacuum): + """Returns info""" + res = vac.info() + + click.echo(res) + _LOGGER.debug("Full response: %s" % pf(res.raw)) + @cli.command() @pass_dev def cleaning_history(vac: mirobo.Vacuum): @@ -341,6 +352,29 @@ def cleaning_history(vac: mirobo.Vacuum): click.echo() +@cli.command() +@pass_dev +def sound(vac: mirobo.Vacuum): + """Query sound settings.""" + click.echo(vac.sound_info()) + +@cli.command() +@pass_dev +def serial_number(vac: mirobo.Vacuum): + """Query serial number.""" + click.echo("Serial#: %s" % vac.serial_number()) + +@cli.command() +@click.argument('tz', required=False) +@pass_dev +def timezone(vac: mirobo.Vacuum, tz=None): + """Query or set the timezone.""" + if tz is not None: + click.echo("Setting timezone to: %s" % tz) + click.echo(vac.set_timezone(tz)) + else: + click.echo("Timezone: %s" % vac.timezone()) + @cli.command() @click.argument('cmd', required=True) @click.argument('parameters', required=False)