Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / MusicPlayer / MusicPlayers.groovy
index 847dd1cd86cc65666177668766bdeddef05ae32d..3e5f4f31ecedf28be72c0fffe6604ca2ab23c459 100644 (file)
@@ -16,7 +16,7 @@ public class MusicPlayers {
        private String displayName = "musicPlayer0"
        private int level = 20
        private String mute = "unmuted"
-       private String status = "pause"
+       private String status = "paused"
        private int trackNumber = 1
        private String trackData = "someTrack"
        private String trackDescription = "someDescriptions"
@@ -57,6 +57,21 @@ public class MusicPlayers {
                        this.trackDescription = "someOtherDescriptions"
                }
 
+               def initLevel = Verify.getIntFromList(10, 20, 30)
+               this.level = initLevel
+               def initMute = Verify.getBoolean()
+               if (initMute) {
+                       this.mute = "unmuted"
+               } else {
+                       this.mute = "mute"
+               }
+               def initStatus = Verify.getBoolean()
+               if (initStatus) {
+                       this.status = "paused"
+               } else {
+                       this.status = "playing"
+               }
+
                musicPlayers.add(new MusicPlayer(id, label, displayName, this.level, this.mute, this.status, this.trackNumber, this.trackData, this.trackDescription))
        }
 
@@ -114,30 +129,42 @@ public class MusicPlayers {
 
        //methods
        def mute() {
-               musicPlayers[0].mute()
-               this.mute = "muted"
+               if (mute != "muted") {
+                       musicPlayers[0].mute()
+                       this.mute = "muted"
+               }
        }
        def nextTrack() {
                musicPlayers[0].nextTrack()
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
                this.trackNumber = musicPlayers[0].trackNumber
        }
        def pause() {
-               musicPlayers[0].pause()
-               this.status = "paused"
+               if (status != "paused") {
+                       musicPlayers[0].pause()
+                       this.status = "paused"
+               }
        }
        def play() {
-               musicPlayers[0].play()
-               this.status = "playing"
+               if (status != "playing") {
+                       musicPlayers[0].play()
+                       this.status = "playing"
+               }
        }
        def playTrack(String trackToPlay) {
                musicPlayers[0].playTrack(trackToPlay)
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
                this.trackNumber = musicPlayers[0].trackNumber
        }
        def previousTrack() {
                musicPlayers[0].previousTrack()
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
                this.trackNumber = musicPlayers[0].trackNumber
        }
        def restoreTrack(String trackToRestore) {
@@ -145,20 +172,28 @@ public class MusicPlayers {
        }
        def resumeTrack(String trackToResume) {
                musicPlayers[0].resumeTrack(trackToResume)
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
        }
        def setLevel(int level) {
-               musicPlayers[0].setLevel(level)
-               this.level = level
+               if (level != this.level) {              
+                       musicPlayers[0].setLevel(level)
+                       this.level = level
+               }
        }
        def setTrack(String trackToSet) {
                musicPlayers[0].setTrack(trackToSet)
-               this.status = "playing"
+               if (status != "playing") {
+                       this.status = "playing"
+               }
                this.trackNumber = musicPlayers[0].trackNumber
        }
        def stop() {
-               musicPlayers[0].stop()
-               this.status = "stopped"
+               if (status != "stopped") {
+                       musicPlayers[0].stop()
+                       this.status = "stopped"
+               }
        }
 
        def currentValue(String deviceFeature) {