X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=MusicPlayer%2FMusicPlayer.groovy;h=b21dbf9035f0520ae503ae0df79594de790a2c19;hb=dd478f2cc3f2096c7deaa628f2f754228246c01c;hp=675f47a6a8faeb4855f800731e5a401f9b2c5cc0;hpb=d00fd74ad7e497d6849c284c6ba69db2d3ec8e65;p=smartthings-infrastructure.git diff --git a/MusicPlayer/MusicPlayer.groovy b/MusicPlayer/MusicPlayer.groovy index 675f47a..b21dbf9 100644 --- a/MusicPlayer/MusicPlayer.groovy +++ b/MusicPlayer/MusicPlayer.groovy @@ -13,8 +13,10 @@ public class MusicPlayer { private int trackNumber private String trackData private String trackDescription + def sendEvent - MusicPlayer(String id, String label, String displayName, int level, String mute, String status, int trackNumber, String trackData, String trackDescription) { + MusicPlayer(Closure sendEvent, String id, String label, String displayName, int level, String mute, String status, int trackNumber, String trackData, String trackDescription) { + this.sendEvent = sendEvent this.id = id this.label = label this.displayName = displayName @@ -47,21 +49,49 @@ public class MusicPlayer { } //methods + def on(LinkedHashMap metaData) { + on() + } + def on() { + if (status != "on") { + println("the music player with id:$id is on!") + this.status = "on" + sendEvent([name: "status", value: "on", deviceId: this.id, descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) + } + } + def off(LinkedHashMap metaData) { + off() + } + def off() { + if (status != "off") { + println("the music player with id:$id is off!") + this.status = "off" + sendEvent([name: "status", value: "off", deviceId: this.id, descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) + } + } + def mute(LinkedHashMap metaData) { + mute() + } def mute() { if (mute != "muted") { println("the music player with id:$id is muted!") this.mute = "muted" - sendEvent([name: "mute", value: "mute", deviceId: this.id, descriptionText: "", + sendEvent([name: "mute", value: "muted", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } + def nextTrack(LinkedHashMap metaData) { + nextTrack() + } def nextTrack() { trackNumber = trackNumber+1 def trackPlaying = trackData println("the $trackPlaying is selected!") - if (status != "playing") { - this.status = "playing" - sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "", + if (status != "play") { + this.status = "play" + sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "", @@ -69,28 +99,37 @@ public class MusicPlayer { sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } + def pause(LinkedHashMap metaData) { + pause() + } def pause() { - if (status != "paused") { + if (status != "pause") { println("the music player with id:$id is paused!") - this.status = "paused" - sendEvent([name: "status", value: "paused", deviceId: this.id, descriptionText: "", + this.status = "pause" + sendEvent([name: "status", value: "pause", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } + def play(LinkedHashMap metaData) { + play() + } def play() { - if (status != "playing") { + if (status != "play") { println("the music player with id:$id is starting to play!") - this.status = "playing" - sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "", + this.status = "play" + sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } + def playTrack(LinkedHashMap metaData) { + playTrack() + } def playTrack(String trackToPlay) { def trackPlaying = trackData println("the $trackPlaying is selected to play!") - if (status != "playing") { - this.status = "playing" - sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "", + if (status != "play") { + this.status = "play" + sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "", @@ -98,6 +137,9 @@ public class MusicPlayer { sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } + def previousTrack(LinkedHashMap metaData) { + previousTrack() + } def previousTrack() { if (trackNumber != 1) trackNumber = trackNumber-1 @@ -116,15 +158,21 @@ public class MusicPlayer { /*def restoreTrack(String trackToRestore) { musicPlayers*.restoreTrack(trackToRestore) }*/ + def resumeTrack(LinkedHashMap metaData) { + resumeTrack() + } def resumeTrack(String trackToResume) { def trackPlaying = trackData println("the $trackPlaying is resumed!") - if (status != "playing") { - this.status = "playing" - sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "", + if (status != "play") { + this.status = "play" + sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } + def setLevel(LinkedHashMap metaData) { + setLevel() + } def setLevel(int level) { if (level != this.level) { this.level = level @@ -133,12 +181,15 @@ public class MusicPlayer { displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } + def setTrack(LinkedHashMap metaData) { + setTrack() + } def setTrack(String trackToSet) { def trackPlaying = trackData println("the $trackPlaying is set!") - if (status != "playing") { - this.status = "playing" - sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "", + if (status != "play") { + this.status = "play" + sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "", @@ -146,17 +197,37 @@ public class MusicPlayer { sendEvent([name: "trackData", value: "someTrack", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } + def stop(LinkedHashMap metaData) { + stop() + } def stop() { - if (status != "stopped") { - println("the music player with id:$id is stopped!") - this.status = "stopped" - sendEvent([name: "status", value: "stopped", deviceId: this.id, descriptionText: "", + if (status != "stop") { + println("the music player with id:$id is stop!") + this.status = "stop" + sendEvent([name: "status", value: "stop", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } + def playText(LinkedHashMap metaData) { + playText() + } + def playText(String text) { + println("the music player with id:$id is playing the text:$text!") + if (status != "play") { + this.status = "play" + sendEvent([name: "status", value: "play", deviceId: this.id, descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) + } + } def currentValue(String deviceFeature) { - if (deviceFeature == "musicPlayer") { + if (deviceFeature == "playpause") { + return status + } + } + + def latestValue(String deviceFeature) { + if (deviceFeature == "playpause") { return status } }