Update double-tap.groovy
[smartapps.git] / official / sonos-music-modes.groovy
index 29591dbb9b572db5d208059868b02a2203e9290a..1c965b4bf6de180ca3687f82e1df3dc97073cbd0 100755 (executable)
  */
 
 
-private songOptions() {
+definition(
+    name: "Sonos Music Modes",
+    namespace: "smartthings",
+    author: "SmartThings",
+    description: "Plays a different selected song or station for each mode.",
+    category: "SmartThings Internal",
+    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/sonos.png",
+    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/sonos@2x.png"
+)
+
+preferences {
+       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)
+       
+}
+
+
+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()
@@ -37,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"
@@ -73,29 +117,10 @@ private saveSelectedSongs() {
        }
        catch (Throwable t) {
                log.error t
-       }
+       }*/
+       state.selectedSong = "SomeTrack"
 }
 
-definition(
-    name: "Sonos Music Modes",
-    namespace: "smartthings",
-    author: "SmartThings",
-    description: "Plays a different selected song or station for each mode.",
-    category: "SmartThings Internal",
-    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/sonos.png",
-    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/sonos@2x.png"
-)
-
-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
-               }
-       }
-}
 
 def mainPage() {
        dynamicPage(name: "mainPage") {
@@ -106,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
                }
        }
@@ -132,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)"
@@ -168,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()
@@ -178,9 +186,9 @@ private takeAction(evt) {
 
                if (volume != null) {
                        sonos.stop()
-                       pause(500)
+                       //pause(500)
                        sonos.setLevel(volume)
-                       pause(500)
+                       //pause(500)
                }
 
                sonos.playTrack(selectedSong)