el_soconos v1.0.0 ElSoconos View Source
The gateway module for control of a Sonos system. This code is a wrapper for the excellent Python Soco library
Querying the Sonos system
el_soconos reports on the Sonos network through elixir’s Registry module, so an elixir later than version 1.4 is required.
Register for and receive these notifications like so:
{:ok, _} = Registry.register(ElSoconos, "el_soconos_update", [])
def handle_info({:el_soconos_update, data}, state) do
Map.merge(state, %{sonos: data})
end
Initiate a data scan with the following code:
ElSoconos.poll_network
The data will be returned in a map with the following keys:
{
favorites: [
%ElSoconos.Favorite{
uri: "pndrradio:32399648508186355",
title: "The Rolling Stones Radio",
meta: <various data>
}
],
groups: [
%ElSoconos.Group {
uid: "RINCON_xxxxxxxxxxxxxxx:49",
coordinator_ip: "10.0.1.64"
}
],
playlists: [
%ElSoconos.Playlist{
uri: "S://DiskStation/music/playlists/test.m3u",
title: "test.m3u"
}
],
speakers: [
%ElSoconos.Speaker{
group_coordinator_ip: "10.0.1.64"
group_uid: "RINCON_xxxxxxxxxxxxxxx:49"
ip: "10.0.1.64"
mode: "NORMAL"
name: "Office"
uid: "RINCON_xxxxxxxxxxxxxxx"
volume: 30
}
]
}
You can query for the individual objects through the ElSoconos interface:
a_grp = ElSoconos.get_group(group_uid)
a_fav = ElSoconos.get_favorite(favorite_uri)
a_spkr = ElSoconos.get_speaker(speaker_uid)
Controlling the Sonos system
Sources (either favorites or playlists) must be played through a group. Each speaker is in its own group it seems.
A single speaker cannot be used instead of a group, but the speaker struct contains a field group_uid, which can then be used to fetch the Group.
a_group = ElSoconos.get_group(a_speaker.group_uid)
ElSoconos.play(a_group, a_favorite)
ElSoconos.play(a_group, a_playlist)
ElSoconos.set_volume(a_group, 70)
ElSoconos.set_volume(a_speaker, 20)
Link to this section Summary
Functions
Add the given speaker to the given group
returns an ElSoconos.Favorite given its uri
returns an ElSoconos.Group given its uid
returns an ElSoconos.Playlist given its uri
returns an ElSoconos.Speaker given its uid
returns the current Sonos network state
Play the given Sonos favorite or playlist in the given group
Starts a scan of the Sonos system
Remove the given speaker from its group
Set the volume of the given group or speaker scale of 0..100
Stops playback in the group with the given uid
Link to this section Functions
Add the given speaker to the given group.
returns an ElSoconos.Favorite given its uri.
returns an ElSoconos.Group given its uid.
returns an ElSoconos.Playlist given its uri.
returns an ElSoconos.Speaker given its uid.
returns the current Sonos network state.
This wil be in the form:
{
favorites: [
ElSoconos.Favorite, ...
],
groups: [
ElSoconos.Group, ...
],
playlists: [
ElSoconos.Playlist, ...
],
speakers: [
ElSoconos.Speaker, ...
]
}
Play the given Sonos favorite or playlist in the given group.
Starts a scan of the Sonos system.
The data will be received thourgh the el_soconos_update registry queue.
Remove the given speaker from its group.
Set the volume of the given group or speaker scale of 0..100.
Stops playback in the group with the given uid.