Update speaker-mood-music.groovy
authorSeyed Amir Hossein Aqajari <amiraj.95@uci.edu>
Thu, 15 Aug 2019 22:27:41 +0000 (15:27 -0700)
committerGitHub Enterprise <noreply@github.uci.edu>
Thu, 15 Aug 2019 22:27:41 +0000 (15:27 -0700)
official/speaker-mood-music.groovy

index d7fe147..21edb43 100755 (executable)
@@ -36,53 +36,6 @@ preferences {
        }
 }
 
-private songOptions() {
-
-       // Make sure current selection is in the set
-
-       def options = new LinkedHashSet()
-       if (state.selectedSong?.station) {
-               options << state.selectedSong.station
-       }
-       else if (state.selectedSong?.description) {
-               // TODO - Remove eventually? 'description' for backward compatibility
-               options << state.selectedSong.description
-       }
-
-       // Query for recent tracks
-       def states = sonos.statesSince("trackData", new Date(0), [max:30])
-       def dataMaps = states.collect{it.jsonValue}
-       options.addAll(dataMaps.collect{it.station})
-
-       log.trace "${options.size()} songs in list"
-       options.take(20) as List
-}
-
-private saveSelectedSong() {
-       try {
-               def thisSong = song
-               log.info "Looking for $thisSong"
-               def songs = sonos.statesSince("trackData", new Date(0), [max:30]).collect{it.jsonValue}
-               log.info "Searching ${songs.size()} records"
-
-               def data = songs.find {s -> s.station == thisSong}
-               log.info "Found ${data?.station}"
-               if (data) {
-                       state.selectedSong = data
-                       log.debug "Selected song = $state.selectedSong"
-               }
-               else if (song == state.selectedSong?.station) {
-                       log.debug "Selected existing entry '$song', which is no longer in the last 20 list"
-               }
-               else {
-                       log.warn "Selected song '$song' not found"
-               }
-       }
-       catch (Throwable t) {
-               log.error t
-       }
-}
-
 // input "motion", "capability.motionSensor", title: "Motion Here", required: false, multiple: true
 // input "contact", "capability.contactSensor", title: "Contact Opens", required: false, multiple: true
 // input "contactClosed", "capability.contactSensor", title: "Contact Closes", required: false, multiple: true
@@ -165,6 +118,53 @@ def chooseTrack() {
        }
 }
 
+private songOptions() {
+
+       // Make sure current selection is in the set
+
+       def options = new LinkedHashSet()
+       if (state.selectedSong?.station) {
+               options << state.selectedSong.station
+       }
+       else if (state.selectedSong?.description) {
+               // TODO - Remove eventually? 'description' for backward compatibility
+               options << state.selectedSong.description
+       }
+
+       // Query for recent tracks
+       def states = sonos.statesSince("trackData", new Date(0), [max:30])
+       def dataMaps = states.collect{it.jsonValue}
+       options.addAll(dataMaps.collect{it.station})
+
+       log.trace "${options.size()} songs in list"
+       options.take(20) as List
+}
+
+private saveSelectedSong() {
+       try {
+               def thisSong = song
+               log.info "Looking for $thisSong"
+               def songs = sonos.statesSince("trackData", new Date(0), [max:30]).collect{it.jsonValue}
+               log.info "Searching ${songs.size()} records"
+
+               def data = songs.find {s -> s.station == thisSong}
+               log.info "Found ${data?.station}"
+               if (data) {
+                       state.selectedSong = data
+                       log.debug "Selected song = $state.selectedSong"
+               }
+               else if (song == state.selectedSong?.station) {
+                       log.debug "Selected existing entry '$song', which is no longer in the last 20 list"
+               }
+               else {
+                       log.warn "Selected song '$song' not found"
+               }
+       }
+       catch (Throwable t) {
+               log.error t
+       }
+}
+
 private anythingSet() {
        for (name in ["motion","contact","contactClosed","acceleration","mySwitch","mySwitchOff","arrivalPresence","departurePresence","smoke","water","button1","timeOfDay","triggerModes","timeOfDay"]) {
                if (settings[name]) {