diff --git a/mirobo/__init__.py b/mirobo/__init__.py index 830c56d95..c9de65750 100644 --- a/mirobo/__init__.py +++ b/mirobo/__init__.py @@ -15,3 +15,4 @@ from mirobo.fan import Fan from mirobo.device import Device, DeviceException from mirobo.discovery import Discovery +from mirobo.wifispeaker import WifiSpeaker diff --git a/mirobo/discovery.py b/mirobo/discovery.py index e447e25b5..1bf1772a5 100644 --- a/mirobo/discovery.py +++ b/mirobo/discovery.py @@ -4,7 +4,8 @@ import inspect import codecs from . import (Device, Vacuum, Plug, PlugV1, Strip, AirPurifier, Ceil, - PhilipsEyecare, ChuangmiIr, AirHumidifier, WaterPurifier) + PhilipsEyecare, ChuangmiIr, AirHumidifier, WaterPurifier, + WifiSpeaker) from typing import Union, Callable, Dict, Optional # noqa: F401 @@ -31,6 +32,7 @@ "philips-light-bulb": Ceil, "philips-light-ceil": Ceil, "philips-light-sread1": PhilipsEyecare, + "xiaomi-wifispeaker-v1": WifiSpeaker, # name needs to be checked "yeelink-light-": lambda x: other_package_info( x, "python-yeelight package"), "lumi-gateway-": lambda x: other_package_info( diff --git a/mirobo/wifispeaker.py b/mirobo/wifispeaker.py new file mode 100644 index 000000000..b49e02724 --- /dev/null +++ b/mirobo/wifispeaker.py @@ -0,0 +1,79 @@ +import warnings +import logging +from .device import Device + +_LOGGER = logging.getLogger(__name__) + + +class WifiSpeakerStatus: + def __init__(self, data): + self.data = data + + @property + def device_name(self) -> str: + return self.data["DeviceName"] + + @property + def channel(self) -> str: + return self.data["channel_title"] + + @property + def state(self) -> str: + # note: this can be enumized when all values are known + return self.data["current_state"] + + @property + def hardware_version(self) -> str: + return self.data["hardware_version"] + + @property + def play_mode(self): + # note: this can be enumized when all values are known + return self.data["play_mode"] + + @property + def track_artist(self) -> str: + return self.data["track_artist"] + + @property + def track_title(self) -> str: + return self.data["track_title"] + + @property + def track_duration(self) -> str: + return self.data["track_duration"] + + @property + def transport_channel(self) -> str: + # note: this can be enumized when all values are known + return self.data["transport_channel"] + + +class WifiSpeaker(Device): + def __init__(self, *args, **kwargs): + warnings.warn("Please help to complete this by providing more " + "information about possible values for `state`, " + "`play_mode` and `transport_channel`.", stacklevel=2) + super().__init__(*args, **kwargs) + + def status(self): + return WifiSpeakerStatus(self.command("get_prop", ["umi"])) + + def power(self): + # is this a toggle? + return self.send("power") + + def volume_up(self): + return self.send("vol_up") + + def volume_down(self): + return self.send("vol_down") + + def track_previous(self): + return self.send("previous_track") + + def track_next(self): + return self.send("next_track") + + def track_location(self): + return self.send("get_prop", ["rel_time"])