Skip to content

Commit 4193012

Browse files
authored
Improve Sonos ID lookup (#496)
1 parent 6a9ecc4 commit 4193012

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

plexapi/myplex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def sonos_speaker(self, name):
228228
return next((x for x in self.sonos_speakers() if x.title.split("+")[0].strip() == name), None)
229229

230230
def sonos_speaker_by_id(self, identifier):
231-
return next((x for x in self.sonos_speakers() if x.machineIdentifier == identifier), None)
231+
return next((x for x in self.sonos_speakers() if x.machineIdentifier.startswith(identifier)), None)
232232

233233
def inviteFriend(self, user, server, sections=None, allowSync=False, allowCameraUpload=False,
234234
allowChannels=False, filterMovies=None, filterTelevision=None, filterMusic=None):

tests/payloads.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"""
1818

1919
SONOS_RESOURCES = """<MediaContainer size="3">
20-
<Player title="Speaker 1" machineIdentifier="RINCON_12345678901234567:1234567891" deviceClass="speaker" product="Sonos" platform="Sonos" platformVersion="56.0-76060" protocol="plex" protocolVersion="1" protocolCapabilities="timeline,playback,playqueues,provider-playback" lanIP="192.168.1.11"/>
21-
<Player title="Speaker 2 + 1" machineIdentifier="RINCON_12345678901234567:1234567892" deviceClass="speaker" product="Sonos" platform="Sonos" platformVersion="56.0-76060" protocol="plex" protocolVersion="1" protocolCapabilities="timeline,playback,playqueues,provider-playback" lanIP="192.168.1.12"/>
22-
<Player title="Speaker 3" machineIdentifier="RINCON_12345678901234567:1234567893" deviceClass="speaker" product="Sonos" platform="Sonos" platformVersion="56.0-76060" protocol="plex" protocolVersion="1" protocolCapabilities="timeline,playback,playqueues,provider-playback" lanIP="192.168.1.13"/>
20+
<Player title="Speaker 1" machineIdentifier="RINCON_12345678901234561:1234567891" deviceClass="speaker" product="Sonos" platform="Sonos" platformVersion="56.0-76060" protocol="plex" protocolVersion="1" protocolCapabilities="timeline,playback,playqueues,provider-playback" lanIP="192.168.1.11"/>
21+
<Player title="Speaker 2 + 1" machineIdentifier="RINCON_12345678901234562:1234567892" deviceClass="speaker" product="Sonos" platform="Sonos" platformVersion="56.0-76060" protocol="plex" protocolVersion="1" protocolCapabilities="timeline,playback,playqueues,provider-playback" lanIP="192.168.1.12"/>
22+
<Player title="Speaker 3" machineIdentifier="RINCON_12345678901234563:1234567893" deviceClass="speaker" product="Sonos" platform="Sonos" platformVersion="56.0-76060" protocol="plex" protocolVersion="1" protocolCapabilities="timeline,playback,playqueues,provider-playback" lanIP="192.168.1.13"/>
2323
</MediaContainer>
2424
"""

tests/test_sonos.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ def test_sonos_resources(mocked_account, requests_mock):
1010

1111
# Finds individual speaker by name
1212
speaker1 = mocked_account.sonos_speaker("Speaker 1")
13-
assert speaker1.machineIdentifier == "RINCON_12345678901234567:1234567891"
13+
assert speaker1.machineIdentifier == "RINCON_12345678901234561:1234567891"
1414

1515
# Finds speaker as part of group
1616
speaker1 = mocked_account.sonos_speaker("Speaker 2")
17-
assert speaker1.machineIdentifier == "RINCON_12345678901234567:1234567892"
17+
assert speaker1.machineIdentifier == "RINCON_12345678901234562:1234567892"
1818

19-
# Finds speaker by identifier
20-
speaker3 = mocked_account.sonos_speaker_by_id("RINCON_12345678901234567:1234567893")
19+
# Finds speaker by Plex identifier
20+
speaker3 = mocked_account.sonos_speaker_by_id("RINCON_12345678901234563:1234567893")
21+
assert speaker3.title == "Speaker 3"
22+
23+
# Finds speaker by Sonos identifier
24+
speaker3 = mocked_account.sonos_speaker_by_id("RINCON_12345678901234563")
2125
assert speaker3.title == "Speaker 3"
2226

2327
assert mocked_account.sonos_speaker("Speaker X") is None

0 commit comments

Comments
 (0)