Skip to content

Commit

Permalink
Add the ability to define a timezone for configure_wifi
Browse files Browse the repository at this point in the history
This will allow passing the timezone to vacuums running
newer firmware versions, as mentioned in PR #105
  • Loading branch information
rytilahti committed Oct 29, 2017
1 parent a5da827 commit 4678069
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 9 additions & 1 deletion miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 8 additions & 3 deletions miio/vacuum_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4678069

Please sign in to comment.