Update speaker-mood-music.groovy
[smartapps.git] / official / speaker-mood-music.groovy
index abdefd39dec0f7659758e7a0853099b78b9430d2..21edb437c4529422ab6c078ebd363e21e274ac05 100755 (executable)
  *  Author: SmartThings
  *  Date: 2014-02-12
  */
-
-
-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
-       }
-}
-
 definition(
     name: "Speaker Mood Music",
     namespace: "smartthings",
@@ -120,7 +71,7 @@ def mainPage() {
                        }
                }
 
-               def hideable = anythingSet || app.installationState == "COMPLETE"
+               def hideable = anythingSet //|| app.installationState == "COMPLETE"
                def sectionTitle = anythingSet ? "Select additional triggers" : "Play music when..."
 
                section(sectionTitle, hideable: hideable, hidden: true){
@@ -144,12 +95,12 @@ def mainPage() {
                section("More options", hideable: true, hidden: true) {
                        input "volume", "number", title: "Set the volume", description: "0-100%", required: false
                        input "frequency", "decimal", title: "Minimum time between actions (defaults to every event)", description: "Minutes", required: false
-                       href "timeIntervalInput", title: "Only during a certain time", description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : "incomplete"
+                       //href "timeIntervalInput", title: "Only during a certain time", description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : "incomplete"
                        input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
                                options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
-                       if (settings.modes) {
+                       //if (settings.modes) {
                input "modes", "mode", title: "Only when mode is", multiple: true, required: false
-            }
+            //}
                        input "oncePerDay", "bool", title: "Only once per day", required: false, defaultValue: false
                }
        }
@@ -167,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]) {