Skip to content

Commit

Permalink
Generalize and move configure_wifi to the Device class (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti authored and syssi committed Mar 7, 2018
1 parent f3f8d67 commit 8eb432c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions miio/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
8 changes: 4 additions & 4 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 8eb432c

Please sign in to comment.