Skip to content

Commit

Permalink
WiFi Repeater: Wifi roaming and signal strange indicator added (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored Mar 31, 2018
1 parent 1e789fa commit 2d44ede
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
4 changes: 3 additions & 1 deletion miio/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import codecs
from . import (Device, Vacuum, ChuangmiPlug, PowerStrip, AirPurifier, Ceil,
PhilipsBulb, PhilipsEyecare, ChuangmiIr, AirHumidifier,
WaterPurifier, WifiSpeaker, Yeelight)
WaterPurifier, WifiSpeaker, WifiRepeater, Yeelight)
from .chuangmi_plug import (MODEL_CHUANGMI_PLUG_V1, MODEL_CHUANGMI_PLUG_V3,
MODEL_CHUANGMI_PLUG_M1)

Expand Down Expand Up @@ -48,6 +48,8 @@
"philips-light-zyceiling": Ceil,
"philips-light-sread1": PhilipsEyecare, # name needs to be checked
"xiaomi-wifispeaker-v1": WifiSpeaker, # name needs to be checked
"xiaomi-repeater-v1": WifiRepeater, # name needs to be checked
"xiaomi-repeater-v3": WifiRepeater, # name needs to be checked
"yeelink-light-": Yeelight,
"lumi-gateway-": lambda x: other_package_info(
x, "https://github.com/Danielhiversen/PyXiaomiGateway")
Expand Down
19 changes: 14 additions & 5 deletions miio/tests/test_wifirepeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def configuration(self):
def info(self):
return self.device.info()

def wifi_roaming(self):
return self.device.wifi_roaming()

def rssi_accesspoint(self):
return self.device.rssi_accesspoint()

def test_status(self):
self.device._reset_state()

Expand All @@ -110,10 +116,10 @@ def test_status(self):

def test_set_wifi_roaming(self):
self.device.set_wifi_roaming(True)
assert self.info().raw['desc']['wifi_explorer'] == 1
assert self.wifi_roaming() is True

self.device.set_wifi_roaming(False)
assert self.info().raw['desc']['wifi_explorer'] == 0
assert self.wifi_roaming() is False

def test_configuration(self):
self.device._reset_state()
Expand All @@ -132,14 +138,17 @@ def configuration():
'ssid': 'SSID2',
'password': 'PASSWORD2',
'hidden': True,
'wifi_explorer': False
}

self.device.set_configuration(
dummy_configuration['ssid'],
dummy_configuration['password'],
dummy_configuration['hidden'],
dummy_configuration['wifi_explorer'])
dummy_configuration['hidden'])
assert configuration().ssid == dummy_configuration['ssid']
assert configuration().password == dummy_configuration['password']
assert configuration().ssid_hidden is dummy_configuration['hidden']

def test_rssi_accesspoint(self):
self.device._reset_state()

assert self.rssi_accesspoint() is self.device.start_device_info['ap']['rssi']
19 changes: 15 additions & 4 deletions miio/wifirepeater.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import logging
from .device import Device
from .device import Device, DeviceException

_LOGGER = logging.getLogger(__name__)


class WifiRepeaterException(DeviceException):
pass


class WifiRepeaterStatus:
def __init__(self, data):
"""
Expand Down Expand Up @@ -86,12 +90,19 @@ def set_wifi_roaming(self, wifi_roaming: bool):
'wifi_explorer': int(wifi_roaming)
}])

def set_configuration(self, ssid: str, password: str, hidden: bool = False,
wifi_roaming: bool = False):
def set_configuration(self, ssid: str, password: str, hidden: bool = False):
"""Update the configuration of the accesspoint."""
return self.send("miIO.switch_wifi_ssid", [{
'ssid': ssid,
'pwd': password,
'hidden': int(hidden),
'wifi_explorer': int(wifi_roaming)
'wifi_explorer': 0
}])

def wifi_roaming(self) -> bool:
"""Return the roaming setting."""
return self.info().raw['desc']['wifi_explorer'] == 1

def rssi_accesspoint(self) -> int:
"""Received signal strength indicator of the accesspoint."""
return self.info().accesspoint['rssi']

0 comments on commit 2d44ede

Please sign in to comment.