Infrastructure compatible with 2 types of switches.(Normal switches and otherVsGeneri...
[smartthings-infrastructure.git] / MotionSensor / MotionSensor.groovy
index 79fbf9b5b018b71054fe72ac8de51005fd005b7d..931069b165234b9182a88fc43ac946169b4fa049 100644 (file)
@@ -2,6 +2,9 @@
 package MotionSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class MotionSensor {
        private String id
        private String label
@@ -9,8 +12,6 @@ public class MotionSensor {
        private String motion
        private String currentMotion
        private String motionLatestValue
-       private List states = []
-       private List timeOfStates = []
 
        MotionSensor(String id, String label, String displayName, String motion, String motionLatestValue) {
                this.id = id
@@ -26,18 +27,52 @@ public class MotionSensor {
                this.motionLatestValue = value
                this.motion = value
                this.currentMotion = value
-               this.states.add(value)
-               this.timeOfStates.add(System.currentTimeMillis())
        }
 
-       def statesSince(String info, Date dateObj) {
-               def List happenedStates = []
-               def sinceThen = dateObj.time
-               for (int i = 0;i < timeOfStates.size();i++) {
-                       if (timeOfStates[i]>=sinceThen)
-                               happenedStates.add(states[i])
+       def statesSince() {
+               eventsSince()
+       }
+
+       def eventsSince() {
+               def evtActive = [[name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtInactive = [[name: "motion", value: "inactive", deviceId: "motionSensorID0", 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 active event
+                       evtActive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 2) {//send two active events
+                       evtActive.each{
+                               evtToSend.add(it)
+                       }
+                       evtActive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 3) {//send one inactive event
+                       evtInactive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 4) {//send two inactive events
+                       evtInactive.each{
+                               evtToSend.add(it)
+                       }
+                       evtInactive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
                }
-               return happenedStates
+       }
+
+       def currentState(String deviceFeature) {
+               currentValue(deviceFeature)
        }