def sendEvent
//For one device(We cannot have obj.id)-> We should have obj[0].id
- private int id = 10
- private String label = "contactSensor"
- private String displayName = "contactSensor"
+ private String id = "contactSensorID0"
+ private String label = "contactSensor0"
+ private String displayName = "contactSensor0"
private String contactState = "closed"
- private String contactLatestValue = "closed"
+ private String latestValue = "closed"
ContactSensors(Closure sendEvent, int deviceNumbers) {
this.deviceNumbers = deviceNumbers
this.contacts = []
- for (int i = 0;i < deviceNumbers;i++) {
- contacts.add(new ContactSensor(i+10, label+i.toString(), displayName+i.toString(), this.contactState, this.contactLatestValue))
- }
+ contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.latestValue))
}
//Methods for closures
def each(Closure Input) {
contacts.each(Input)
}
+ def find(Closure Input) {
+ contacts.find(Input)
+ }
+ def collect(Closure Input) {
+ contacts.collect(Input)
+ }
//By Model Checker
def setValue(LinkedHashMap eventDataMap) {
- contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
- if (deviceNumbers == 1)
- this.contactLatestValue = contacts[eventDataMap["deviceId"]].contactLatestValue
- this.contactState = contacts[eventDataMap["deviceId"]].contactState
+ contacts[0].setValue(eventDataMap["value"])
+ this.latestValue = contacts[0].latestValue
+ this.contactState = contacts[0].contactState
sendEvent(eventDataMap)
}
def currentValue(String deviceFeature) {
- if (deviceNumbers == 1)
- contacts[0].currentValue(deviceFeature)//It is called if we have only one device
- else
- contacts*.currentValue(deviceFeature)
+ contacts[0].currentValue(deviceFeature)//It is called if we have only one device
}
def latestValue(String deviceFeature) {
- if (deviceNumbers == 1)
- contacts[0].latestValue(deviceFeature)//It is called if we have only one device
- else
- contacts*.latestValue(deviceFeature)
+ contacts[0].latestValue(deviceFeature)//It is called if we have only one device
}
def getAt(int ix) {