From 4678069ab43b3d36a27640483e78dd3824db4157 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sun, 29 Oct 2017 16:58:12 +0100 Subject: [PATCH] Add the ability to define a timezone for configure_wifi This will allow passing the timezone to vacuums running newer firmware versions, as mentioned in PR #105 --- miio/vacuum.py | 10 +++++++++- miio/vacuum_cli.py | 11 ++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/miio/vacuum.py b/miio/vacuum.py index 8abafd9ef..7742b453e 100644 --- a/miio/vacuum.py +++ b/miio/vacuum.py @@ -3,6 +3,8 @@ import time from typing import List import enum +import datetime +import pytz from .vacuumcontainers import (VacuumStatus, ConsumableStatus, DNDStatus, CleaningSummary, CleaningDetails, Timer) @@ -202,9 +204,15 @@ def set_timezone(self, new_zone): """Set the timezone.""" return self.send("set_timezone", [new_zone])[0] == 'ok' - def configure_wifi(self, ssid, password, uid=0): + def configure_wifi(self, ssid, password, uid=0, timezone=None): """Configure the wifi settings.""" params = {"ssid": ssid, "passwd": password, "uid": uid} + if timezone is not None: + now = datetime.datetime.now(pytz.timezone(timezone)) + offset_as_float = now.utcoffset().total_seconds() / 60 / 60 + params["tz"] = timezone + params["gmt_offset"] = offset_as_float + return self.send("miIO.config_router", params)[0] def raw_command(self, cmd, params): diff --git a/miio/vacuum_cli.py b/miio/vacuum_cli.py index d73515192..5f0966d52 100644 --- a/miio/vacuum_cli.py +++ b/miio/vacuum_cli.py @@ -421,11 +421,16 @@ def timezone(vac: miio.Vacuum, tz=None): @click.argument('ssid', required=True) @click.argument('password', required=True) @click.argument('uid', type=int, required=False) +@click.option('--timezone', type=str, required=False, default=None) @pass_dev -def configure_wifi(vac: miio.Vacuum, ssid: str, password: str, uid: int): - """Configure the wifi settings.""" +def configure_wifi(vac: miio.Vacuum, ssid: str, password: str, + uid: int, timezone: str): + """Configure the wifi settings. + + Note that some newer firmwares may expect you to define the timezone + by using --timezone.""" click.echo("Configuring wifi to SSID: %s" % ssid) - click.echo(vac.configure_wifi(ssid, password, uid)) + click.echo(vac.configure_wifi(ssid, password, uid, timezone)) @cli.command()