1 //Create a class for contact sensor
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class ContactSensors {
9 private int deviceNumbers
13 //For one device(We cannot have obj.id)-> We should have obj[0].id
14 private String id = "contactSensorID0"
15 private String label = "contactSensor0"
16 private String displayName = "contactSensor0"
17 private String contactState = "closed"
18 private String currentContact = "closed"
19 private String latestValue = "closed"
20 private String alarmState = "armed"
23 ContactSensors(Closure sendEvent, int deviceNumbers) {
24 this.sendEvent = sendEvent
25 this.deviceNumbers = deviceNumbers
28 contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.currentContact, this.alarmState, this.latestValue))
31 //Methods for closures
32 def count(Closure Input) {
38 def each(Closure Input) {
41 def find(Closure Input) {
44 def sort(Closure Input) {
47 def collect(Closure Input) {
48 contacts.collect(Input)
52 def setValue(LinkedHashMap eventDataMap) {
53 if (eventDataMap["value"] != contacts[0].contactState) {
54 this.latestValue = eventDataMap["value"]
55 this.contactState = eventDataMap["value"]
56 this.currentContact = eventDataMap["value"]
57 contacts[0].setValue(eventDataMap["value"])
58 sendEvent(eventDataMap)
63 this.alarmState = "armed"
68 this.alarmState = "not armed"
72 def currentValue(String deviceFeature) {
73 contacts[0].currentValue(deviceFeature)//It is called if we have only one device
76 def currentState(String deviceFeature) {
77 contacts[0].currentState(deviceFeature)//It is called if we have only one device
80 def latestValue(String deviceFeature) {
81 contacts[0].latestValue(deviceFeature)//It is called if we have only one device