Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for wifi speakers #86

Merged
merged 4 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mirobo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
from mirobo.philips_eyecare import PhilipsEyecare
from mirobo.chuangmi_ir import ChuangmiIr
from mirobo.fan import Fan
from mirobo.wifispeaker import WifiSpeaker
from mirobo.device import Device, DeviceException
from mirobo.discovery import Discovery
4 changes: 3 additions & 1 deletion mirobo/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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(
Expand Down
79 changes: 79 additions & 0 deletions mirobo/wifispeaker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import warnings
import logging
from .device import Device

_LOGGER = logging.getLogger(__name__)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logger isn't used?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not currently, but I think it's ok to leave it like that for now. This will probably need some revisions to be remotely useful, and for that there'll be debug outputs I hope.



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, amount: int = 5):
return self.send("vol_up", [amount])

def volume_down(self, amount: int = 5):
return self.send("vol_down", [amount])

def track_previous(self):
return self.send("previous_track")

def track_next(self):
return self.send("next_track")

def track_location(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer track_position here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed + added some apidocs & fixed the broken status.

return self.send("get_prop", ["rel_time"])