*/
-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()
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"
}
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") {
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
}
}
}
}
-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)"
private takeAction(evt) {
def name = "mode_$evt.value".toString()
- def selectedSong = state.selectedSongs."$name"
+ def selectedSong = state.selectedSongs
if (selectedSong == "PAUSE") {
sonos.stop()
if (volume != null) {
sonos.stop()
- pause(500)
+ //pause(500)
sonos.setLevel(volume)
- pause(500)
+ //pause(500)
}
sonos.playTrack(selectedSong)