From 2e3039bd19cb4a1448b29cc41b81c4124fff937f Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Mon, 14 Aug 2017 08:16:55 +0200 Subject: [PATCH] Device support for the chuangmi plug v1 added (#33) * Device support for the chuangmi plug v1 strip added. * Status class moved. * Missing import added. --- mirobo/__init__.py | 1 + mirobo/plug_v1.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 mirobo/plug_v1.py diff --git a/mirobo/__init__.py b/mirobo/__init__.py index c5b2da2d4..bc3f460c4 100644 --- a/mirobo/__init__.py +++ b/mirobo/__init__.py @@ -3,6 +3,7 @@ from mirobo.vacuumcontainers import VacuumStatus, ConsumableStatus, CleaningDetails, CleaningSummary, Timer from mirobo.vacuum import Vacuum, VacuumException from mirobo.plug import Plug +from mirobo.plug_v1 import PlugV1 from mirobo.airpurifier import AirPurifier from mirobo.strip import Strip from mirobo.device import Device, DeviceException diff --git a/mirobo/plug_v1.py b/mirobo/plug_v1.py new file mode 100644 index 000000000..96bb00514 --- /dev/null +++ b/mirobo/plug_v1.py @@ -0,0 +1,55 @@ +from .device import Device +from typing import Any, Dict + + +class PlugV1(Device): + """Main class representing the chuangmi plug v1.""" + + def on(self): + """Power on.""" + return self.send("set_on", []) + + def off(self): + """Power off.""" + return self.send("set_off", []) + + def usb_on(self): + """Power on.""" + return self.send("set_usb_on", []) + + def usb_off(self): + """Power off.""" + return self.send("set_usb_off", []) + + def status(self): + """Retrieve properties.""" + properties = ['on', 'usb_on'] + values = self.send( + "get_prop", + properties + ) + return PlugV1Status(dict(zip(properties, values))) + + +class PlugV1Status: + """Container for status reports from the plug.""" + def __init__(self, data: Dict[str, Any]) -> None: + self.data = data + + @property + def power(self) -> bool: + return self.data["on"] + + @property + def is_on(self) -> bool: + return self.power + + @property + def usb_power(self) -> bool: + return self.data["usb_on"] + + def __str__(self) -> str: + s = "" % \ + (self.power, + self.usb_power) + return s