From 525c16aad19889acf3765efea90f962e181cdea8 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Tue, 6 Mar 2018 19:50:37 +0100 Subject: [PATCH] Generalize and move configure_wifi to the Device class --- miio/device.py | 9 +++++++++ miio/vacuum.py | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/miio/device.py b/miio/device.py index 49edf8ef4..436d46ef3 100644 --- a/miio/device.py +++ b/miio/device.py @@ -316,6 +316,15 @@ def update_state(self): """Return current update state.""" return UpdateState(self.send("miIO.get_ota_state", [])[0]) + def configure_wifi(self, ssid, password, uid=0, extra_params=None): + """Configure the wifi settings.""" + if extra_params is None: + extra_params = {} + params = {"ssid": ssid, "passwd": password, "uid": uid, + **extra_params} + + return self.send("miIO.config_router", params)[0] + @property def _id(self) -> int: """Increment and return the sequence id.""" diff --git a/miio/vacuum.py b/miio/vacuum.py index 22c573daf..24f0a8a7c 100644 --- a/miio/vacuum.py +++ b/miio/vacuum.py @@ -256,14 +256,14 @@ def set_timezone(self, new_zone): def configure_wifi(self, ssid, password, uid=0, timezone=None): """Configure the wifi settings.""" - params = {"ssid": ssid, "passwd": password, "uid": uid} + extra_params = {} 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 + extra_params["tz"] = timezone + extra_params["gmt_offset"] = offset_as_float - return self.send("miIO.config_router", params)[0] + return super().configure_wifi(ssid, password, uid, extra_params) def raw_command(self, cmd, params): """Send a raw command to the robot."""