Sonos library to control (almost) everything from your sonos devices
Requires:
- module:'./Service'
- module:'events'
- module:'axios'
- module:'debug'
- module:'./events/listener'
Create an instance of Sonos
Sonos: , Export
Get Music Library Information
Parameters:
searchType: String
, Choice - artists, albumArtists, albums, genres, composers, tracks, playlists, share
options: Object
, Optional - default {start: 0, total: 100}
Returns: Object
, {returned: {String}, total: {String}, items:[{title:{String}, uri: {String}}]}
Get Music Library Information
Parameters:
searchType: String
, Choice - artists, albumArtists, albums, genres, composers, tracks, playlists, share
searchTerm: String
, Optional - search term to search for
requestOptions: Object
, Optional - default {start: 0, total: 100}
separator: String
, Optional - default is colon. :
or /
Returns: Object
, {returned: {String}, total: {String}, items:[{title:{String}, uri: {String}}]}
Get Sonos Playlist
Parameters:
playlistId: String
, Sonos id of the playlist
requestOptions: Object
, Optional - default {start: 0, total: 100}
Returns: Object
, {returned: {String}, total: {String}, items:[{title:{String}, uri: {String}}]}
Create a new sonos playlist
Parameters:
title: String
, Name of the playlist
Returns: Object
, { NumTracksAdded: 0, NewQueueLength: 0, NewUpdateID: 0, AssignedObjectID: 'SQ:3' }
Delete sonos playlist
Parameters:
objectId: Number
, Sonos id of the playlist
Returns: Boolean
, Playlist deleted
Add uri to sonos playlist
Parameters:
playlistId: Number
, Sonos id of the playlist
uri: String
, Uri to add to the playlist
Returns: Object
, { NumTracksAdded: 1, NewQueueLength: 2, NewUpdateID: 2 }
Remove track from playlist
Parameters:
playlistId: Number
, Sonos id of the playlist
index: String
, Index of song to remove
Returns: Object
, { QueueLengthChange: -1, NewQueueLength: 2, NewUpdateID: 2 }
Get Sonos Favorites
Returns: Object
, {returned: {String}, total: {String}, items:[{title:{String}, uri: {String}}]}
Get Current Track
Returns: Object
, All the info of the current track
Get Current Volume
Returns: Number
, The current volume
Get Current Muted
Returns: Boolean
Resumes Queue or Plays Provided URI
Parameters:
options: String | Object
, Optional - URI to a Audio Stream or Object with play options
Returns: Boolean
, Started playing?
Plays a uri directly (the queue stays the same)
Parameters:
options: String | Object
, URI to a Audio Stream or Object with play options see Helpers.GenerateMetadata
Returns: Boolean
Stop What's Playing
Returns: boolean
Get all the groups, replaces some functionality of 'getTopology()'
Become Coordinator of Standalone Group
Returns: boolean
Leave the group (shortcut to becomeCoordinatorOfStandaloneGroup)
Returns: boolean
Join an other device by name
Parameters:
otherDeviceName: String
, The name of de device you want to join, doesn't matter if that isn't the coordinator
Returns: Boolean
Pause Current Queue
Returns: Boolean
Seek in the current track
Parameters:
seconds: Number
, jump to x seconds.
Returns: Boolean
Select specific track in queue
Parameters:
trackNr: Number
, Number of track in queue (optional, indexed from 1)
Returns: Boolean
Play next in queue
Returns: Boolean
Play previous in queue
Returns: Boolean
Select Queue. Mostly required after turning on the speakers otherwise play, setPlaymode and other commands will fail.
Returns: Boolean
, success
Plays tunein based on radio station id
Parameters:
stationId: String
, tunein radio station id
Returns: Boolean
Plays Spotify radio based on artist uri
Parameters:
artistId: String
, Spotify artist id
Returns: Boolean
Add a song to the queue.
Parameters:
options: String | Object
, Uri with audio stream of object with uri
and metadata
positionInQueue: Number
, Position in queue at which to add song (optional, indexed from 1,
defaults to end of queue, 0 to explicitly set end of queue)
Returns: Object
, Some info about the last queued file.
Remove a range of tracks from the queue.
Parameters:
startIndex: number
, Where to start removing the tracks, 1 for first item!
numberOfTracks: number
, How many tracks to remove.
Flush queue
Returns: Object
Get the LED State
Returns: String
, state is a string, "On" or "Off"
Set the LED State
Parameters:
newState: String
, "On"/"Off"
Returns: Boolean
Get Zone Info
Returns: Object
Get Zone Attributes
Returns: Object
Get Information provided by /xml/device_description.xml
Returns: Object
Set Name
Parameters:
name: String
, Set Name
Returns: Object
Get the CurrentZoneName
Returns: String
Get Play Mode
Returns: String
Set Play Mode
Parameters:
playmode: String
, Set Play Mode
Returns: Object
Set Volume
Parameters:
volume: number
, 0..100
channel: string
, What channel to change, Master
is default.
Returns: Object
Adjust volume
Parameters:
volumeAdjustment: number
, The relative volume adjustment
channel: string
, The channel you want to set, Master
is default.
Configure Sleep Timer
Parameters:
sleepTimerDuration: String
, Configure Sleep Timer
Returns: Object
Set Muted
Parameters:
muted: Boolean
, Set Muted
channel: string
, What channel to change, Master
is default.
Returns: Object
Get Zones in contact with current Zone with Group Data
Deprecated: Doesn't work if you upgraded your system to Sonos v9.1
Returns: Object
Get Current Playback State
Returns: String
, the current playback state
Toggle the current playback, like the button. Currently only works for state playing
or paused
Returns: Boolean
Get Favorites Radio Stations
Parameters:
options: Object
, Optional - default {start: 0, total: 100}
Returns: Object
, {returned: {String}, total: {String}, items:[{title:{String}, uri: {String}}]}
Get Favorites Radio Shows
Parameters:
options: Object
, Optional - default {start: 0, total: 100}
Returns: Object
, {returned: {String}, total: {String}, items:[{title:{String}, uri: {String}}]}
Get Favorites Radio for a given radio type
Parameters:
favoriteRadioType: String
, Choice - stations, shows
options: Object
, Optional - default {start: 0, total: 100}
Returns: Object
, {returned: {String}, total: {String}, items:[{title:{String}, uri: {String}}]}
Get the current queue
Returns: Object
, {returned: {String}, total: {String}, items:[{title:{String}, uri: {String}}]}
Play uri and restore last state
Parameters:
options: String | Object
, URI to a Audio Stream or Object with play options see Helpers.GenerateMetadata
-
options.uri:
String
, The URI of the stream -
options.metadata:
String
, The metadata of the stream seeHelpers.GenerateMetadata
-
options.onlyWhenPlaying:
Boolean
, Only play this notification on players currently 'playing' -
options.volume:
Number
, The volume used for the notification.
Returns: Boolean
, Did the notification play? Only returns when finished reverting to old play settings.
Reorder tracks in queue.
Parameters:
startingIndex: number
, Index of the first track to be moved
numberOfTracks: number
, How many tracks do we want to move
insertBefore: number
, Index of place where the tracks should be moved to
updateId: number
, Not sure what this means, just leave it at 0
Returns: Boolean
Get SpotifyConnect info, will error when no premium account is present
Returns: Object