//Create a class for contact sensor
package ContactSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
-public class ContactSensors {
- private int deviceNumbers
- private List contacts
- def sendEvent
+public class ContactSensors extends SmartThings {
+ List contacts = new ArrayList()
- //For one device(We cannot have obj.id)-> We should have obj[0].id
- private String id = "contactSensorID0"
- private String label = "contactSensor0"
- private String displayName = "contactSensor0"
- private String contactState = "closed"
- private String latestValue = "closed"
+ ContactSensors(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ contacts = smartThings
+ // Initialization
+ String id = "contactID0"
+ String label = "contact"
+ String displayName = "contactSensor"
+ String currentContact
- ContactSensors(Closure sendEvent, int deviceNumbers) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.contacts = []
+ if (init)
+ currentContact = "closed"
+ else
+ currentContact = "open"
- contacts.add(new ContactSensor(id, label, displayName, this.contactState, this.latestValue))
- }
-
- //Methods for closures
- def count(Closure Input) {
- contacts.count(Input)
- }
- def size() {
- contacts.size()
- }
- 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[0].setValue(eventDataMap["value"])
- this.latestValue = contacts[0].latestValue
- this.contactState = contacts[0].contactState
- sendEvent(eventDataMap)
- }
-
- def currentValue(String deviceFeature) {
- contacts[0].currentValue(deviceFeature)//It is called if we have only one device
- }
-
- def latestValue(String deviceFeature) {
- contacts[0].latestValue(deviceFeature)//It is called if we have only one device
- }
-
- def getAt(int ix) {
- contacts[ix]
+ contacts.add(new ContactSensor(sendEvent, id, label, displayName, currentContact))
}
}