1 //Create a class for presence sensor
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class MotionSensor {
11 private String displayName
13 private String currentMotion
14 private String motionLatestValue
16 MotionSensor(String id, String label, String displayName, String motion, String motionLatestValue) {
19 this.displayName = displayName
21 this.currentMotion = motion
22 this.motionLatestValue = motionLatestValue
25 def setValue(String value) {
26 println("the motion sensor with id:$id is triggered to $value!")
27 this.motionLatestValue = value
29 this.currentMotion = value
37 def evtActive = [[name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
38 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
39 def evtInactive = [[name: "motion", value: "inactive", deviceId: "motionSensorID0", descriptionText: "",
40 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
41 def init = Verify.getInt(0,4)
43 if (init == 0) {//return empty set
45 } else if (init == 1) {//send one active event
50 } else if (init == 2) {//send two active events
58 } else if (init == 3) {//send one inactive event
63 } else if (init == 4) {//send two inactive events
74 def currentState(String deviceFeature) {
75 currentValue(deviceFeature)
79 def currentValue(String deviceFeature) {
80 if (deviceFeature == "motion") {
85 def latestValue(String deviceFeature) {
86 if (deviceFeature == "motion") {
87 return motionLatestValue