Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to define a timezone for configure_wifi #107

Merged
merged 2 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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