X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartapps.git;a=blobdiff_plain;f=official%2Fspeaker-mood-music.groovy;h=4f30cf54f578a14b311a82360484b209e05a9ebc;hp=d7fe14732eeb7ca983af1ea669072380f22ebf31;hb=b51a1ebcdd2aad93864d307c21decb690d5ed645;hpb=e77888cb4d37fc1552bdeec70675ee138d1def73 diff --git a/official/speaker-mood-music.groovy b/official/speaker-mood-music.groovy index d7fe147..4f30cf5 100755 --- a/official/speaker-mood-music.groovy +++ b/official/speaker-mood-music.groovy @@ -36,53 +36,6 @@ preferences { } } -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 - } -} - // input "motion", "capability.motionSensor", title: "Motion Here", required: false, multiple: true // input "contact", "capability.contactSensor", title: "Contact Opens", required: false, multiple: true // input "contactClosed", "capability.contactSensor", title: "Contact Closes", required: false, multiple: true @@ -165,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]) { @@ -261,9 +261,9 @@ private takeAction(evt) { if (volume != null) { sonos.stop() - pause(500) + //pause(500) sonos.setLevel(volume) - pause(500) + //pause(500) } sonos.playTrack(state.selectedSong) @@ -297,7 +297,7 @@ private oncePerDayOk(Long lastTime) { // TODO - centralize somehow private getAllOk() { - modeOk && daysOk && timeOk + modeOk//&& daysOk && timeOk } private getModeOk() {