1 //Create a class for presence sensor
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class PresenceSensors {
9 private int deviceNumbers
10 private List presenceSensors
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "presenceSensorID0"
15 private String label = "presenceSensor0"
16 private String displayName = "presenceSensor0"
17 private String presence = "not present"
18 private String currentPresence = "not present"
19 private String presenceLatestValue = "not present"
22 PresenceSensors(Closure sendEvent, int deviceNumbers) {
23 this.sendEvent = sendEvent
24 this.deviceNumbers = deviceNumbers
25 this.presenceSensors = []
26 def init = Verify.getBoolean()
28 this.presence = "not present"
29 this.presenceLatestValue = "not present"
31 this.presence = "present"
32 this.presenceLatestValue = "present"
35 presenceSensors.add(new PresenceSensor(id, label, displayName, this.presence, this.presenceLatestValue))
39 def setValue(LinkedHashMap eventDataMap) {
40 if (eventDataMap["value"] != presenceSensors[0].presence) {
41 this.presenceLatestValue = eventDataMap["value"]
42 this.presence = eventDataMap["value"]
43 this.currentPresence = eventDataMap["value"]
44 presenceSensors[0].setValue(eventDataMap["value"])
45 sendEvent(eventDataMap)
49 //Methods for closures
50 def count(Closure Input) {
51 presenceSensors.count(Input)
54 presenceSensors.size()
56 def each(Closure Input) {
57 presenceSensors.each(Input)
59 def find(Closure Input) {
60 presenceSensors.find(Input)
62 def sort(Closure Input) {
63 presenceSensors.sort(Input)
65 def collect(Closure Input) {
66 presenceSensors.collect(Input)
70 def currentValue(String deviceFeature) {
71 presenceSensors[0].currentValue(deviceFeature)//It is called if we have only one device
74 def latestValue(String deviceFeature) {
75 presenceSensors[0].latestValue(deviceFeature)//It is called if we have only one device