From ea7df98566c13e50c9fbe3b12f9f9e2c0b148bd3 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Wed, 6 Sep 2017 08:20:47 +0200 Subject: [PATCH 1/2] Abstract device model exteded by model name (identifier). --- mirobo/device.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mirobo/device.py b/mirobo/device.py index 0eee0a520..d688d833f 100644 --- a/mirobo/device.py +++ b/mirobo/device.py @@ -2,7 +2,7 @@ import datetime import socket import logging -from typing import Any, List # noqa: F401 +from typing import Any, List, Optional # noqa: F401 from .protocol import Message @@ -25,13 +25,19 @@ def __repr__(self): self.data["token"]) @property - def netif(self): + def netif(self) -> str: return self.data["netif"] @property - def ap(self): + def ap(self) -> str: return self.data["ap"] + @property + def model(self) -> Optional[str]: + if self.data["model"] is not None: + return self.data["model"] + return None + @property def raw(self): return self.data @@ -185,6 +191,9 @@ def raw_command(self, cmd, params): def info(self): return DeviceInfo(self.send("miIO.info", [])) + def model(self): + return self.info().model + @property def _id(self) -> int: """Returns running id.""" From fd715bd7b7394ba6356098e2a9fba54abcebaeef Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Wed, 6 Sep 2017 19:38:45 +0200 Subject: [PATCH 2/2] DeviceInfo example added. Typing flaw fixed. --- mirobo/device.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/mirobo/device.py b/mirobo/device.py index d688d833f..4385dd81a 100644 --- a/mirobo/device.py +++ b/mirobo/device.py @@ -15,6 +15,26 @@ class DeviceException(Exception): class DeviceInfo: def __init__(self, data): + """ + Response of a Xiaomi Smart WiFi Plug + + {'ap': {'bssid': 'FF:FF:FF:FF:FF:FF', 'rssi': -68, 'ssid': 'network'}, + 'cfg_time': 0, + 'fw_ver': '1.2.4_16', + 'hw_ver': 'MW300', + 'life': 24, + 'mac': '28:FF:FF:FF:FF:FF', + 'mmfree': 30312, + 'model': 'chuangmi.plug.m1', + 'netif': {'gw': '192.168.xxx.x', + 'localIp': '192.168.xxx.x', + 'mask': '255.255.255.0'}, + 'ot': 'otu', + 'ott_stat': [0, 0, 0, 0], + 'otu_stat': [320, 267, 3, 0, 3, 742], + 'token': '2b00042f7481c7b056c4b410d28f33cf', + 'wifi_fw_ver': 'SD878x-14.76.36.p84-702.1.0-WM'} + """ self.data = data def __repr__(self): @@ -25,11 +45,11 @@ def __repr__(self): self.data["token"]) @property - def netif(self) -> str: + def netif(self): return self.data["netif"] @property - def ap(self) -> str: + def ap(self): return self.data["ap"] @property @@ -191,9 +211,6 @@ def raw_command(self, cmd, params): def info(self): return DeviceInfo(self.send("miIO.info", [])) - def model(self): - return self.info().model - @property def _id(self) -> int: """Returns running id."""