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) {
23 this.sendEvent = sendEvent
24 this.deviceNumbers = deviceNumbers
25 this.motionSensors = []
27 /*def init = Verify.getBoolean()
29 this.motion = "inactive"
30 this.motionLatestValue = "inactive"
32 this.motion = "active"
33 this.motionLatestValue = "active"
35 motionSensors.add(new MotionSensor(id, label, displayName, this.motion, this.motionLatestValue))
39 def setValue(LinkedHashMap eventDataMap) {
40 if (eventDataMap["value"] != motionSensors[0].motion) {
41 this.motionLatestValue = eventDataMap["value"]
42 this.motion = eventDataMap["value"]
43 this.currentMotion = eventDataMap["value"]
44 motionSensors[0].setValue(eventDataMap["value"])
45 sendEvent(eventDataMap)
49 //Methods for closures
50 def count(Closure Input) {
51 motionSensors.count(Input)
56 def each(Closure Input) {
57 motionSensors.each(Input)
59 def find(Closure Input) {
60 motionSensors.find(Input)
62 def sort(Closure Input) {
63 motionSensors.sort(Input)
65 def collect(Closure Input) {
66 motionSensors.collect(Input)
70 def currentValue(String deviceFeature) {
71 motionSensors[0].currentValue(deviceFeature)//It is called if we have only one device
74 def latestValue(String deviceFeature) {
75 motionSensors[0].latestValue(deviceFeature)//It is called if we have only one device
78 def statesSince(String info, Date dateObj) {
79 return motionSensors[0].statesSince(info, dateObj)