From e3bd22a13040314fde324a9b1adeade027138860 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sun, 23 Jul 2017 23:40:48 +0200 Subject: [PATCH 1/8] Device support for the xiaomi power strip added. --- mirobo/containers.py | 33 +++++++++++++++++++++++++++++++++ mirobo/strip.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 mirobo/strip.py diff --git a/mirobo/containers.py b/mirobo/containers.py index 737b3a21e..4fd3fde9c 100644 --- a/mirobo/containers.py +++ b/mirobo/containers.py @@ -39,6 +39,39 @@ def pretty_time(x: int) -> datetime: } +class StripStatus: + """Container for status reports from the strip.""" + def __init__(self, data: Dict[str, Any]) -> None: + self.data = data + + @property + def power(self) -> str: + return self.data["power"] + + @property + def is_on(self) -> bool: + return self.power == "on" + + @property + def temperature(self) -> float: + return self.data["temperature"] + + @property + def current(self) -> float: + return self.data["current"] + + @property + def mode(self) -> float: + return self.data["mode"] + + def __str__(self) -> str: + s = "" % \ + (self.power, self.temperature, + self.current, self.mode) + return s + + class PlugStatus: """Container for status reports from the plug.""" def __init__(self, data: Dict[str, Any]) -> None: diff --git a/mirobo/strip.py b/mirobo/strip.py new file mode 100644 index 000000000..ad698eb9d --- /dev/null +++ b/mirobo/strip.py @@ -0,0 +1,29 @@ +from .device import Device +from .containers import StripStatus + + +class Strip(Device): + """Main class representing the smart strip.""" + + def on(self): + """Power on.""" + return self.send("set_power", ["on"]) + + def off(self): + """Power off.""" + return self.send("set_power", ["off"]) + + def status(self): + """Retrieve properties.""" + properties = ['power', 'temperature', 'current', 'mode'] + values = self.send( + "get_prop", + properties + ) + return StripStatus(dict(zip(properties, values))) + + def set_power_mode(self, mode: str): + """Set mode.""" + + # green, normal + return self.send("set_power_mode", [mode]) From 0178c1bfcea3da3aa143a3d33335950d090ae5cb Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sun, 23 Jul 2017 23:51:29 +0200 Subject: [PATCH 2/8] Strip added to __init__. --- mirobo/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mirobo/__init__.py b/mirobo/__init__.py index 54acd6062..3913ac682 100644 --- a/mirobo/__init__.py +++ b/mirobo/__init__.py @@ -3,4 +3,5 @@ from mirobo.containers import VacuumStatus, ConsumableStatus, CleaningDetails, CleaningSummary, Timer from mirobo.vacuum import Vacuum, VacuumException from mirobo.plug import Plug +from mirobo.strip import Strip from mirobo.device import Device, DeviceException From 44d9db802e420ebc4d405b3a9f5c946e9c963fe9 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sun, 23 Jul 2017 23:55:21 +0200 Subject: [PATCH 3/8] Status class moved. --- mirobo/containers.py | 33 --------------------------------- mirobo/strip.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/mirobo/containers.py b/mirobo/containers.py index 4fd3fde9c..737b3a21e 100644 --- a/mirobo/containers.py +++ b/mirobo/containers.py @@ -39,39 +39,6 @@ def pretty_time(x: int) -> datetime: } -class StripStatus: - """Container for status reports from the strip.""" - def __init__(self, data: Dict[str, Any]) -> None: - self.data = data - - @property - def power(self) -> str: - return self.data["power"] - - @property - def is_on(self) -> bool: - return self.power == "on" - - @property - def temperature(self) -> float: - return self.data["temperature"] - - @property - def current(self) -> float: - return self.data["current"] - - @property - def mode(self) -> float: - return self.data["mode"] - - def __str__(self) -> str: - s = "" % \ - (self.power, self.temperature, - self.current, self.mode) - return s - - class PlugStatus: """Container for status reports from the plug.""" def __init__(self, data: Dict[str, Any]) -> None: diff --git a/mirobo/strip.py b/mirobo/strip.py index ad698eb9d..97e9b0bca 100644 --- a/mirobo/strip.py +++ b/mirobo/strip.py @@ -1,5 +1,4 @@ from .device import Device -from .containers import StripStatus class Strip(Device): @@ -27,3 +26,36 @@ def set_power_mode(self, mode: str): # green, normal return self.send("set_power_mode", [mode]) + + +class StripStatus: + """Container for status reports from the strip.""" + def __init__(self, data: Dict[str, Any]) -> None: + self.data = data + + @property + def power(self) -> str: + return self.data["power"] + + @property + def is_on(self) -> bool: + return self.power == "on" + + @property + def temperature(self) -> float: + return self.data["temperature"] + + @property + def current(self) -> float: + return self.data["current"] + + @property + def mode(self) -> float: + return self.data["mode"] + + def __str__(self) -> str: + s = "" % \ + (self.power, self.temperature, + self.current, self.mode) + return s From 610ff31df45bcd8471827bbe0be27d64cde06e1b Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sun, 23 Jul 2017 23:58:33 +0200 Subject: [PATCH 4/8] Missing import added. --- mirobo/strip.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mirobo/strip.py b/mirobo/strip.py index 97e9b0bca..fd4ba473a 100644 --- a/mirobo/strip.py +++ b/mirobo/strip.py @@ -1,4 +1,5 @@ from .device import Device +from typing import Any, Dict class Strip(Device): From 682e4d47876da4f59d23a7887a368da1980362e4 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Tue, 25 Jul 2017 21:34:46 +0200 Subject: [PATCH 5/8] Response example added. PowerMode class introduced. --- mirobo/strip.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mirobo/strip.py b/mirobo/strip.py index fd4ba473a..21cad6e0a 100644 --- a/mirobo/strip.py +++ b/mirobo/strip.py @@ -1,6 +1,6 @@ from .device import Device from typing import Any, Dict - +import enum class Strip(Device): """Main class representing the smart strip.""" @@ -22,15 +22,17 @@ def status(self): ) return StripStatus(dict(zip(properties, values))) - def set_power_mode(self, mode: str): + def set_power_mode(self, mode: PowerMode): """Set mode.""" # green, normal - return self.send("set_power_mode", [mode]) + return self.send("set_power_mode", [mode.value]) class StripStatus: """Container for status reports from the strip.""" + + # {'power': 'on', 'temperature': 48.11, 'current': 0.06, 'mode': 'green'} def __init__(self, data: Dict[str, Any]) -> None: self.data = data @@ -51,8 +53,8 @@ def current(self) -> float: return self.data["current"] @property - def mode(self) -> float: - return self.data["mode"] + def mode(self) -> PowerMode: + return PowerMode(self.data["mode"]) def __str__(self) -> str: s = " str: (self.power, self.temperature, self.current, self.mode) return s + + +class PowerMode(enum.Enum): + Eco = 'green' + Normal = 'normal' From 8f7229879991a7099ccbd68fec7af42f281c5394 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Tue, 25 Jul 2017 21:47:39 +0200 Subject: [PATCH 6/8] Missing return added. --- mirobo/strip.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mirobo/strip.py b/mirobo/strip.py index 21cad6e0a..1409e5785 100644 --- a/mirobo/strip.py +++ b/mirobo/strip.py @@ -2,6 +2,7 @@ from typing import Any, Dict import enum + class Strip(Device): """Main class representing the smart strip.""" From e8dbf26e16c29a0472e2259ea7ad36237fa87444 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Tue, 25 Jul 2017 22:22:06 +0200 Subject: [PATCH 7/8] PowerMode class moved. --- mirobo/strip.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mirobo/strip.py b/mirobo/strip.py index 1409e5785..a9feed959 100644 --- a/mirobo/strip.py +++ b/mirobo/strip.py @@ -3,6 +3,11 @@ import enum +class PowerMode(enum.Enum): + Eco = 'green' + Normal = 'normal' + + class Strip(Device): """Main class representing the smart strip.""" @@ -33,8 +38,8 @@ def set_power_mode(self, mode: PowerMode): class StripStatus: """Container for status reports from the strip.""" - # {'power': 'on', 'temperature': 48.11, 'current': 0.06, 'mode': 'green'} def __init__(self, data: Dict[str, Any]) -> None: + # {'power': 'on', 'temperature': 48.11, 'current': 0.06, 'mode': 'green'} self.data = data @property @@ -63,8 +68,3 @@ def __str__(self) -> str: (self.power, self.temperature, self.current, self.mode) return s - - -class PowerMode(enum.Enum): - Eco = 'green' - Normal = 'normal' From eecaf6e83bcc422dc45ec6fe358a5794f854e5f8 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Tue, 25 Jul 2017 22:36:21 +0200 Subject: [PATCH 8/8] Code reformatted. --- mirobo/strip.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mirobo/strip.py b/mirobo/strip.py index a9feed959..e5953a9b0 100644 --- a/mirobo/strip.py +++ b/mirobo/strip.py @@ -39,7 +39,8 @@ class StripStatus: """Container for status reports from the strip.""" def __init__(self, data: Dict[str, Any]) -> None: - # {'power': 'on', 'temperature': 48.11, 'current': 0.06, 'mode': 'green'} + # {'power': 'on', 'temperature': 48.11, + # 'current': 0.06, 'mode': 'green'} self.data = data @property