Skip to content

Commit

Permalink
Merge 68e5ee0 into 843be92
Browse files Browse the repository at this point in the history
  • Loading branch information
dajobe committed Feb 28, 2015
2 parents 843be92 + 68e5ee0 commit 8bf551f
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
46 changes: 44 additions & 2 deletions soco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class SoCo(_SocoSingletonBase):
next -- Go to the next track.
previous -- Go back to the previous track.
switch_to_line_in -- Switch the speaker's input to line-in.
switch_to_tv -- Switch the speaker's input to TV.
switch_to_tv -- Switch the playbar speaker's input to TV.
get_current_track_info -- Get information about the currently playing
track.
get_speaker_info -- Get information about the Sonos speaker.
Expand Down Expand Up @@ -155,6 +155,9 @@ class SoCo(_SocoSingletonBase):
queue_size -- Get size of queue.
library_updating -- Whether music library update is in progress.
album_artist_display_option -- album artist display option
is_playing_tv -- Is the playbar speaker input from TV?
is_playing_radio -- Is the speaker input from radio?
is_playing_line_in -- Is the speaker input from line-in?
.. warning::
Expand Down Expand Up @@ -879,8 +882,47 @@ def switch_to_line_in(self):
('CurrentURIMetaData', '')
])

@property
def is_playing_radio(self):
""" Is the speaker playing radio?
return True or False
"""
response = self.avTransport.GetPositionInfo([
('InstanceID', 0),
('Channel', 'Master')
])
track_uri = response['TrackURI']
return re.match(r'^x-rincon-mp3radio:', track_uri) is not None

@property
def is_playing_line_in(self):
""" Is the speaker playing line-in?
return True or False
"""
response = self.avTransport.GetPositionInfo([
('InstanceID', 0),
('Channel', 'Master')
])
track_uri = response['TrackURI']
return re.match(r'^x-rincon-stream:', track_uri) is not None

@property
def is_playing_tv(self):
""" Is the playbar speaker input from TV?
return True or False
"""
response = self.avTransport.GetPositionInfo([
('InstanceID', 0),
('Channel', 'Master')
])
track_uri = response['TrackURI']
return re.match(r'^x-sonos-htastream:', track_uri) is not None

def switch_to_tv(self):
""" Switch the speaker's input to TV.
""" Switch the playbar speaker's input to TV.
Returns:
True if the Sonos speaker successfully switched to TV.
Expand Down
54 changes: 54 additions & 0 deletions unittest/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,60 @@ def test_switch_to_tv(self, moco_zgs):
('CurrentURIMetaData', '')]
)

def test_is_playing_tv(self, moco):
moco.avTransport.reset_mock()
moco.avTransport.GetPositionInfo.return_value = {
'TrackURI': 'x-sonos-htastream:RINCON_00012345678901234:spdif'
}
playing_tv = moco.is_playing_tv
assert playing_tv
moco.avTransport.GetPositionInfo.assert_called_once_with(
[('InstanceID', 0),
('Channel', 'Master')]
)

moco.avTransport.GetPositionInfo.return_value = {
'TrackURI': 'not-tv',
}
playing_tv = moco.is_playing_tv
assert not playing_tv

def test_is_playing_radio(self, moco):
moco.avTransport.reset_mock()
moco.avTransport.GetPositionInfo.return_value = {
'TrackURI': 'x-rincon-mp3radio://example.com:80/myradio'
}
playing_tv = moco.is_playing_radio
assert playing_tv
moco.avTransport.GetPositionInfo.assert_called_once_with(
[('InstanceID', 0),
('Channel', 'Master')]
)

moco.avTransport.GetPositionInfo.return_value = {
'TrackURI': 'not-radio',
}
playing_tv = moco.is_playing_radio
assert not playing_tv

def test_is_playing_line_in(self, moco):
moco.avTransport.reset_mock()
moco.avTransport.GetPositionInfo.return_value = {
'TrackURI': 'x-rincon-stream:blah-blah'
}
playing_tv = moco.is_playing_line_in
assert playing_tv
moco.avTransport.GetPositionInfo.assert_called_once_with(
[('InstanceID', 0),
('Channel', 'Master')]
)

moco.avTransport.GetPositionInfo.return_value = {
'TrackURI': 'not-line-in',
}
playing_tv = moco.is_playing_line_in
assert not playing_tv

def test_create_sonos_playlist(self, moco):
playlist_name = "cool music"
playlist_id = 1
Expand Down

0 comments on commit 8bf551f

Please sign in to comment.