Skip to content

Commit

Permalink
Revise based on code review, add an example & some docstrings, plus f…
Browse files Browse the repository at this point in the history
…ix invalid send() in status()
  • Loading branch information
rytilahti committed Oct 2, 2017
1 parent 633bdaf commit 20e5c85
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions mirobo/wifispeaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@

class WifiSpeakerStatus:
def __init__(self, data):
# {"DeviceName": "Mi Internet Speaker", "channel_title\": "XXX",
# "current_state": "PLAYING", "hardware_version": "S602",
# "play_mode": "REPEAT_ALL", "track_artist": "XXX",
# "track_duration": "00:04:58", "track_title": "XXX",
# "transport_channel": "PLAYLIST"}
self.data = data

@property
def device_name(self) -> str:
"""Name of the device."""
return self.data["DeviceName"]

@property
def channel(self) -> str:
"""Name of the channel."""
return self.data["channel_title"]

@property
def state(self) -> str:
"""State of the device, e.g. PLAYING."""
# note: this can be enumized when all values are known
return self.data["current_state"]

Expand All @@ -28,23 +36,28 @@ def hardware_version(self) -> str:

@property
def play_mode(self):
"""Play mode such as REPEAT_ALL."""
# note: this can be enumized when all values are known
return self.data["play_mode"]

@property
def track_artist(self) -> str:
"""Artist of the current track."""
return self.data["track_artist"]

@property
def track_title(self) -> str:
"""Title of the current track."""
return self.data["track_title"]

@property
def track_duration(self) -> str:
"""Total duration of the current track."""
return self.data["track_duration"]

@property
def transport_channel(self) -> str:
"""Transport channel, e.g. PLAYLIST"""
# note: this can be enumized when all values are known
return self.data["transport_channel"]

Expand All @@ -57,23 +70,30 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def status(self):
return WifiSpeakerStatus(self.command("get_prop", ["umi"]))
"""Return device status."""
return WifiSpeakerStatus(self.send("get_prop", ["umi"]))

def power(self):
"""Toggle power on and off."""
# is this a toggle?
return self.send("power")

def volume_up(self, amount: int = 5):
"""Set volume up."""
return self.send("vol_up", [amount])

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

def track_previous(self):
"""Move to previous track."""
return self.send("previous_track")

def track_next(self):
"""Move to next track."""
return self.send("next_track")

def track_location(self):
def track_position(self):
"""Return current track position."""
return self.send("get_prop", ["rel_time"])

0 comments on commit 20e5c85

Please sign in to comment.