Update sonos-music-modes.groovy
[smartapps.git] / official / sonos-music-modes.groovy
index f4ecdcc..811bde4 100755 (executable)
@@ -28,19 +28,39 @@ definition(
 )
 
 preferences {
-       page(name: "mainPage", title: "Play a message on your Sonos when something happens", nextPage: "chooseTrack", uninstall: true)
-       page(name: "chooseTrack", title: "Select a song", install: true)
        page(name: "timeIntervalInput", title: "Only during a certain time") {
                section {
                        input "starting", "time", title: "Starting", required: false
                        input "ending", "time", title: "Ending", required: false
                }
        }
+       page(name: "mainPage", title: "Play a message on your Sonos when something happens", nextPage: "chooseTrack", uninstall: true)
+       page(name: "chooseTrack", title: "Select a song", install: true)
+       
 }
 
 
-private songOptions() {
+def installed() {
+       log.debug "Installed with settings: ${settings}"
+       subscribeToEvents()
+}
+
+def updated() {
+       log.debug "Updated with settings: ${settings}"
+       unsubscribe()
+       subscribeToEvents()
+}
+
+def subscribeToEvents() {
+       log.trace "subscribeToEvents()"
+       saveSelectedSongs()
+
+       subscribe(location, modeChangeHandler)
+}
+
 
+private songOptions() {
+       /*
        // Make sure current selection is in the set
 
        def options = new LinkedHashSet()
@@ -59,10 +79,12 @@ private songOptions() {
        options.addAll(dataMaps.collect{it.station})
 
        log.trace "${options.size()} songs in list"
-       options.take(20) as List
+       options.take(20) as List*/
+       state.selectedSong = "SomeTrack"
 }
 
 private saveSelectedSongs() {
+       /*
        try {
                def songs = sonos.statesSince("trackData", new Date(0), [max:30]).collect{it.jsonValue}
                log.info "Searching ${songs.size()} records"
@@ -95,7 +117,8 @@ private saveSelectedSongs() {
        }
        catch (Throwable t) {
                log.error t
-       }
+       }*/
+       state.selectedSong = "SomeTrack"
 }
 
 
@@ -108,12 +131,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"
                        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
                }
        }
@@ -134,23 +157,6 @@ def chooseTrack() {
        }
 }
 
-def installed() {
-       log.debug "Installed with settings: ${settings}"
-       subscribeToEvents()
-}
-
-def updated() {
-       log.debug "Updated with settings: ${settings}"
-       unsubscribe()
-       subscribeToEvents()
-}
-
-def subscribeToEvents() {
-       log.trace "subscribeToEvents()"
-       saveSelectedSongs()
-
-       subscribe(location, modeChangeHandler)
-}
 
 def modeChangeHandler(evt) {
        log.trace "modeChangeHandler($evt.name: $evt.value)"
@@ -170,7 +176,7 @@ def modeChangeHandler(evt) {
 private takeAction(evt) {
 
        def name = "mode_$evt.value".toString()
-       def selectedSong = state.selectedSongs."$name"
+       def selectedSong = state.selectedSongs
 
        if (selectedSong == "PAUSE") {
                sonos.stop()