Update sonos-music-modes.groovy
[smartapps.git] / official / sonos-music-modes.groovy
index fa8da4a..811bde4 100755 (executable)
@@ -40,6 +40,25 @@ preferences {
 }
 
 
+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
@@ -112,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
                }
        }
@@ -138,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)"
@@ -174,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()