Skip to content

Commit

Permalink
Add the ability to define a timezone for configure_wifi (#107)
Browse files Browse the repository at this point in the history
* 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

* add pytz to requirements
  • Loading branch information
rytilahti authored Nov 1, 2017
1 parent 193e27f commit 26b13ba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ zeroconf
pycrypto # for miio-extract-tokens
attrs
typing # for py3.4 support
pytz # for tz offset in vacuum
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
packages=["miio", "mirobo"],

python_requires='>=3.4',
install_requires=['construct', 'click', 'cryptography', 'pretty_cron', 'typing', 'zeroconf', 'pycrypto', 'attrs'],
install_requires=['construct', 'click', 'cryptography', 'pretty_cron',
'typing', 'zeroconf', 'pycrypto', 'attrs', 'pytz'],

entry_points={
'console_scripts': [
'mirobo=miio.vacuum_cli:cli',
Expand Down

0 comments on commit 26b13ba

Please sign in to comment.