1 //Create a class for presence sensor
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class MotionSensors {
9 private int deviceNumbers
10 private List motionSensors
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "motionSensorID0"
15 private String label = "motionSensor0"
16 private String displayName = "motionSensor0"
17 private String motion = "inactive"
18 private String currentMotion = "inactive"
19 private String motionLatestValue = "inactive"
22 MotionSensors(Closure sendEvent, int deviceNumbers, boolean init) {
23 this.sendEvent = sendEvent
24 this.deviceNumbers = deviceNumbers
25 this.motionSensors = []
28 this.motion = "inactive"
29 this.currentMotion = "inactive"
30 this.motionLatestValue = "inactive"
32 this.motion = "active"
33 this.currentMotion = "active"
34 this.motionLatestValue = "active"
36 motionSensors.add(new MotionSensor(id, label, displayName, this.motion, this.motionLatestValue))
40 def setValue(LinkedHashMap eventDataMap) {
41 if (eventDataMap["value"] != motionSensors[0].motion) {
42 this.motionLatestValue = eventDataMap["value"]
43 this.motion = eventDataMap["value"]
44 this.currentMotion = eventDataMap["value"]
45 motionSensors[0].setValue(eventDataMap["value"])
46 sendEvent(eventDataMap)
50 //Methods for closures
51 def count(Closure Input) {
52 motionSensors.count(Input)
57 def each(Closure Input) {
58 motionSensors.each(Input)
60 def find(Closure Input) {
61 motionSensors.find(Input)
63 def sort(Closure Input) {
64 motionSensors.sort(Input)
66 def collect(Closure Input) {
67 motionSensors.collect(Input)
70 def currentState(String deviceFeature) {
71 currentValue(deviceFeature)
74 def currentValue(String deviceFeature) {
75 motionSensors[0].currentValue(deviceFeature)//It is called if we have only one device
78 def latestValue(String deviceFeature) {
79 motionSensors[0].latestValue(deviceFeature)//It is called if we have only one device
82 def statesSince(String info, Date dateObj) {
83 return motionSensors[0].statesSince()
86 def eventsSince(Date dateObj) {
87 return motionSensors[0].statesSince()