Cancelling the changes for field write.
[smartthings-infrastructure.git] / Switch / Switch.groovy
index aa3b2c52f841001c55416f8c5845bc71c2e0297d..4e28c344fd9e2849f6f5eca1decc575d9c570dc6 100644 (file)
@@ -2,6 +2,10 @@
 package Switch
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
+
 public class Switch {
        private String id
        private String label
@@ -26,6 +30,44 @@ public class Switch {
                this.switchLatestValue = switchLatestValue
        }
 
+       def eventsSince() {
+               def evtOn = [[name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
+                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtOff = [[name: "switch", value: "off", deviceId: "switchID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def init = Verify.getInt(0,4)
+               def evtToSend = []
+               if (init == 0) {//return empty set
+                       return evtToSend
+               } else if (init == 1) {//send one open event
+                       evtOn.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 2) {//send two open events
+                       evtOn.each{
+                               evtToSend.add(it)
+                       }
+                       evtOn.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 3) {//send one closed event
+                       evtOff.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 4) {//send two closed events
+                       evtOff.each{
+                               evtToSend.add(it)
+                       }
+                       evtOff.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               }
+       }
+
        //By Apps
        def setLevel(int level) {
                if (this.currentLevel != level) {
@@ -44,8 +86,6 @@ public class Switch {
                        this.currentSwitch = "on"
                        sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
                            displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-                       sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
@@ -58,8 +98,6 @@ public class Switch {
                                this.currentSwitch = "on"
                                sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-                               sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                        }
                }
        }
@@ -72,8 +110,6 @@ public class Switch {
                        this.currentSwitch = "off"
                        sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
                            displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-                       sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
@@ -86,8 +122,6 @@ public class Switch {
                                this.currentSwitch = "off"
                                sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
                                    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-                               sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                        }
                }
        }