//Create a class for contact sensor
package ContactSensor
+import Timer.SimulatedTimer
-public class Contacting{
+public class Contacting {
private int deviceNumbers
private List contacts
def sendEvent
+
+ //For one device(We cannot have obj.id)-> We should have obj[0].id
+ private int id = 0
+ private String displayName = "contact0"
+ private String contactState = "closed"
+ private String contactLatestValue = "closed"
+
Contacting(Closure sendEvent, int deviceNumbers) {
this.sendEvent = sendEvent
this.deviceNumbers = deviceNumbers
this.contacts = []
+
+
if (deviceNumbers == 1) {
- contacts = [new Contacts(0, "contact0", "closed", "closed")]
+ contacts = [new Contacts(this.id, this.displayName, this.contactState, this.contactLatestValue)]
} else if (deviceNumbers == 2) {
contacts = [new Contacts(0, "contact0", "closed", "closed"), new Contacts(1, "contact1", "closed", "closed")]
} else if (deviceNumbers == 3) {
//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
sendEvent(eventDataMap)
}