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 diff --git a/mirobo/strip.py b/mirobo/strip.py new file mode 100644 index 000000000..e5953a9b0 --- /dev/null +++ b/mirobo/strip.py @@ -0,0 +1,71 @@ +from .device import Device +from typing import Any, Dict +import enum + + +class PowerMode(enum.Enum): + Eco = 'green' + Normal = 'normal' + + +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: PowerMode): + """Set mode.""" + + # green, normal + return self.send("set_power_mode", [mode.value]) + + +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'} + 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) -> PowerMode: + return PowerMode(self.data["mode"]) + + def __str__(self) -> str: + s = "" % \ + (self.power, self.temperature, + self.current, self.mode) + return s