1 //Create a class for presence sensor
3 import Timer.SimulatedTimer
5 public class MotionSensor {
8 private String displayName
10 private String currentMotion
11 private String motionLatestValue
13 MotionSensor(String id, String label, String displayName, String motion, String motionLatestValue) {
16 this.displayName = displayName
18 this.currentMotion = motion
19 this.motionLatestValue = motionLatestValue
22 def setValue(String value) {
23 println("the motion sensor with id:$id is triggered to $value!")
24 this.motionLatestValue = value
26 this.currentMotion = value
30 def evtActive = [[name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
31 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
32 def evtInactive = [[name: "motion", value: "inactive", deviceId: "motionSensorID0", descriptionText: "",
33 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
34 def init = Verify.getInt(0,4)
36 if (init == 0) {//return empty set
38 } else if (init == 1) {//send one active event
43 } else if (init == 2) {//send two active events
51 } else if (init == 3) {//send one inactive event
56 } else if (init == 4) {//send two inactive events
67 def currentState(String deviceFeature) {
68 currentValue(deviceFeature)
72 def currentValue(String deviceFeature) {
73 if (deviceFeature == "motion") {
78 def latestValue(String deviceFeature) {
79 if (deviceFeature == "motion") {
80 return motionLatestValue