Sonos Resuming Different Tracks


I am playing about with a Sonos integration and for example, using the default Smart Apps there are options to resume current track after the event (e.g. play a message)

However, I’m finding that rather than resuming the track, it will start playing a recent radio station instead.

I also noticed that if I look at the options for playing a specific track; that said radio station was on the top of the list, opposed to what I last played.

So I suspect there is some kind of bug whereby the Sonos playTrackandResume method is not actually getting the last track; but rather what is displayed in the list of available tracks

This is the code for what it uses to resume a track

sonos.playTrackAndResume(state.sound.uri, state.sound.duration, volume)

This is the code for what I think it’s using to get the last tracks:

def songs = sonos.statesSince(“trackData”, new Date(0), [max:30]).collect{it.jsonValue}

Is there a confirmed bug around this or am I just missing something??

Also, looking at the Device Handler code for Sonos and trying the Simulator using my real device this command appears to be used to get currentTrack

def currentTrack = device.currentState(“trackData”)?.jsonValue

When I try to debug log the output of this I get NULL; but whilst I watch the log in general operations I saw output of things like track name that was playing; which seems to originate for example from:

// Track data
def trackUri = xml1.InstanceID.CurrentTrackURI.’@val’.text()
def transportUri = xml1.InstanceID.AVTransportURI.’@val’.text()
def enqueuedUri = xml1.InstanceID.EnqueuedTransportURI.’@val’.text()
def trackNumber = xml1.InstanceID.CurrentTrack.’@val’.text()

if (trackUri.contains("//")) {
log.trace “Skipping event generation for sound file $trackUri”
else {
def trackMeta = xml1.InstanceID.CurrentTrackMetaData.’@val’.text()
def transportMeta = xml1.InstanceID.AVTransportURIMetaData.’@val’.text()
def enqueuedMeta = xml1.InstanceID.EnqueuedTransportURIMetaData.’@val’.text()

if (trackMeta || transportMeta) {
def isRadioStation = enqueuedUri.startsWith(“x-sonosapi-stream:”)

  // Use enqueued metadata, if available, otherwise transport metadata, for station ID
  def metaData = enqueuedMeta ? enqueuedMeta :  transportMeta
  def stationMetaXml = metaData ? parseXml(metaData) : null
  // Use the track metadata for song ID unless it's a radio station

def trackXml = (trackMeta && !isRadioStation) || !stationMetaXml ? parseXml(trackMeta) : stationMetaXml

  // Song properties
  def currentName = trackXml.item.title.text()
  def currentArtist = trackXml.item.creator.text()
  def currentAlbum  = trackXml.item.album.text()
  def currentTrackDescription = currentName
  def descriptionText = "$device.displayName is playing $currentTrackDescription"
  if (currentArtist) {
  	currentTrackDescription += " - $currentArtist"
  	descriptionText += " by $currentArtist"

Is the Handler not calling the correct objects?