Adding Locks group in run.sh
[smartthings-infrastructure.git] / MusicPlayer / MusicPlayers.groovy
index bf733db3a93bc327219d4f273b507eaf708cc6bd..bce3fc7d40612d6139e29c67317e41163df47b3a 100644 (file)
@@ -2,6 +2,8 @@
 package MusicPlayer
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
 
 public class MusicPlayers {
        private int deviceNumbers
@@ -14,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"
@@ -26,7 +28,37 @@ public class MusicPlayers {
                this.deviceNumbers = deviceNumbers
                this.musicPlayers = []
 
-               musicPlayers.add(new MusicPlayer(id, label, displayName, this.level, this.mute, this.status, this.trackNumber, this.trackData, this.trackDescription))
+               /*def initLevel = Verify.getIntFromList(10, 20, 30)
+               this.level = initLevel
+               def initMute = Verify.getBoolean()
+               if (initMute) {
+                       this.mute = "unmuted"
+               } else {
+                       this.mute = "muted"
+               }
+               def initStatus = Verify.getInt(0,2)
+               if (initStatus == 0) {
+                       this.status = "paused"
+               } else if (initStatus == 1) {
+                       this.status = "playing"
+               } else {
+                       this.status = "stopped"
+               }
+               def initTrack = Verify.getIntFromList(1, 2, 3)
+               this.trackNumber = initTrack 
+               def initData = Verify.getBoolean()
+               if (initData) {
+                       this.trackData = "someTrack"
+               } else {
+                       this.trackData = "someOtherTrack"
+               }
+               def initDesc = Verify.getBoolean()
+               if (initDesc) {
+                       this.trackDescription = "someDescriptions"
+               } else {
+                       this.trackDescription = "someOtherDescriptions"
+               }*/
+               musicPlayers.add(new MusicPlayer(sendEvent, id, label, displayName, this.level, this.mute, this.status, this.trackNumber, this.trackData, this.trackDescription))
        }
 
        //By model checker
@@ -83,30 +115,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) {
@@ -114,20 +158,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) {