Skip to content

Commit

Permalink
Abstract device model exteded by model name (identifier) (#64)
Browse files Browse the repository at this point in the history
* Abstract device model exteded by model name (identifier).

* DeviceInfo example added.
Typing flaw fixed.
  • Loading branch information
syssi authored and rytilahti committed Sep 6, 2017
1 parent 8d9e30c commit 3cd4b30
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions mirobo/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ class DeviceException(Exception):
class DeviceInfo:
"""Presentation of miIO device information."""
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):
Expand All @@ -36,6 +56,12 @@ def accesspoint(self):
"""Return information about connected wlan accesspoint."""
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 raw data returned by the device."""
Expand Down

0 comments on commit 3cd4b30

Please sign in to comment.