Commit #9: extension to the infrastructure with more devices + minor changes in extra...
[smartthings-infrastructure.git] / ContactSensor / ContactSensors.groovy
index e53d7d1f95a486c1b4a0f12241407cd605e34d6f..10c4aa61aed7270292d1c03dc77ba2a18cf80a23 100644 (file)
@@ -8,11 +8,11 @@ public class ContactSensors {
        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) {
@@ -20,9 +20,7 @@ public class ContactSensors {
                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
@@ -35,28 +33,27 @@ public class ContactSensors {
        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) {