-
-
Notifications
You must be signed in to change notification settings - Fork 563
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f861278
Initial support for wifi speakers
rytilahti 65e6561
Fix import order to make tests pass
rytilahti 633bdaf
add the required parameter to volume up and volume down
rytilahti 20e5c85
Revise based on code review, add an example & some docstrings, plus f…
rytilahti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) | ||
|
||
|
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer track_position here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed + added some apidocs & fixed the broken |
||
return self.send("get_prop", ["rel_time"]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.