diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..cdae3264 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Compiled python modules. +__pycache__/ + +# Setuptools distribution folder. +/dist/ + +# Python egg metadata, regenerated from source files by setuptools. +/*.egg-info +/*.egg + +/build diff --git a/pyHS100/pyHS100.py b/pyHS100/pyHS100.py index 8336e9c5..d215b10e 100644 --- a/pyHS100/pyHS100.py +++ b/pyHS100/pyHS100.py @@ -291,8 +291,19 @@ class SmartDevice(object): :rtype: dict """ info = self.sys_info - return {"latitude": info["latitude"], - "longitude": info["longitude"]} + loc = {"latitude": None, + "longitude": None} + + if "latitude" in info and "longitude" in info: + loc["latitude"] = info["latitude"] + loc["longitude"] = info["longitude"] + elif "latitude_i" in info and "longitude_i" in info: + loc["latitude"] = info["latitude_i"] + loc["longitude"] = info["longitude_i"] + else: + _LOGGER.warning("Unsupported device location.") + + return loc @property def rssi(self): diff --git a/pyHS100/tests/fakes.py b/pyHS100/tests/fakes.py index 29ec353a..f2f28be1 100644 --- a/pyHS100/tests/fakes.py +++ b/pyHS100/tests/fakes.py @@ -45,6 +45,28 @@ emeter_units_support = {"get_realtime": get_realtime_units, "get_monthstat": get_monthstat_units, "get_daystat": get_daystat_units,} +sysinfo_hs105 = {'system': {'get_sysinfo': + {'sw_ver': '1.0.6 Build 160722 Rel.081616', + 'hw_ver': '1.0', 'type': 'IOT.SMARTPLUGSWITCH', + 'model': 'HS105(US)', + 'mac': '50:C7:BF:xx:xx:xx', + 'dev_name': 'Smart Wi-Fi Plug Mini', + 'alias': 'TP-LINK_Smart Plug_CF0B', + 'relay_state': 0, + 'on_time': 0, + 'active_mode': 'none', + 'feature': 'TIM', + 'updating': 0, + 'icon_hash': '', + 'rssi': 33, + 'led_off': 0, + 'longitude_i': -12.2, + 'latitude_i': 12.2, + 'hwId': '60FF6B258734EA6880E186F8C96DDC61', + 'fwId': '00000000000000000000000000000000', + 'deviceId': '800654F32938FCBA8F7327887A38647617', + 'oemId': 'FFF22CFF774A0B89F7624BFC6F50D5DE'}}} + sysinfo_hs110 = {'system': {'get_sysinfo': {'active_mode': 'schedule', 'alias': 'Mobile Plug', diff --git a/pyHS100/tests/test_pyHS100.py b/pyHS100/tests/test_pyHS100.py index 28986c96..87314d27 100644 --- a/pyHS100/tests/test_pyHS100.py +++ b/pyHS100/tests/test_pyHS100.py @@ -5,7 +5,7 @@ import datetime import re from .. import SmartPlug, SmartPlugException -from .fakes import FakeTransportProtocol, sysinfo_hs110 +from .fakes import FakeTransportProtocol, sysinfo_hs110, sysinfo_hs105 PLUG_IP = '192.168.250.186' SKIP_STATE_TESTS = False @@ -221,6 +221,11 @@ class TestSmartPlug(TestCase): def test_location(self): self.sysinfo_schema(self.plug.location) + def test_location_i(self): + plug_i = SmartPlug(PLUG_IP, + protocol=FakeTransportProtocol(sysinfo_hs105)) + self.sysinfo_schema(plug_i.location) + def test_rssi(self): self.sysinfo_schema({'rssi': self.plug.rssi}) # wrapping for vol