Adding missing methods.
[smartthings-infrastructure.git] / PresenceSensor / PresenceSensors.groovy
index 8fb9161864606b45652e74ecf7a542a828760ace..782e25cca5df70640893d94d166df0a50c2e1889 100644 (file)
@@ -11,26 +11,35 @@ public class PresenceSensors {
        private String id = "presenceSensorID0"
        private String label = "presenceSensor0"
        private String displayName = "presenceSensor0"
-       private String presenceState = "not present"
+       private String presence = "not present"
        private String currentPresence = "not present"
        private String presenceLatestValue = "not present"
 
                
-       PresenceSensors(Closure sendEvent, int deviceNumbers) {
+       PresenceSensors(Closure sendEvent, int deviceNumbers, boolean init) {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.presenceSensors = []
 
-               presenceSensors.add(new PresenceSensor(id, label, displayName, this.presenceState, this.presenceLatestValue))
+               if (init) {
+                       this.presence = "not present"
+                       this.currentPresence = "not present"
+                       this.presenceLatestValue = "not present"
+               } else {
+                       this.presence = "present"
+                       this.currentPresence = "present"
+                       this.presenceLatestValue = "present"
+               }
+               presenceSensors.add(new PresenceSensor(id, label, displayName, this.presence, this.presenceLatestValue))
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != presenceSensors[0].presenceState) {
+               if (eventDataMap["value"] != presenceSensors[0].presence) {
+                       this.presenceLatestValue = eventDataMap["value"]
+                       this.presence = eventDataMap["value"]
+                       this.currentPresence = eventDataMap["value"]
                        presenceSensors[0].setValue(eventDataMap["value"])
-                       this.presenceLatestValue = presenceSensors[0].presenceLatestValue
-                       this.presenceState = presenceSensors[0].presenceState
-                       this.currentPresence = presenceSensors[0].presenceState
                        sendEvent(eventDataMap)
                }
        }
@@ -48,10 +57,16 @@ public class PresenceSensors {
        def find(Closure Input) {
                presenceSensors.find(Input)
        }
+       def sort(Closure Input) {
+               presenceSensors.sort(Input)
+       }
        def collect(Closure Input) {
                presenceSensors.collect(Input)
        }
 
+       def currentState(String deviceFeature) {
+               presenceSensors[0].currentState(deviceFeature)  
+       }
 
        def currentValue(String deviceFeature) {
                presenceSensors[0].currentValue(deviceFeature)//It is called if we have only one device
@@ -61,6 +76,14 @@ public class PresenceSensors {
                presenceSensors[0].latestValue(deviceFeature)//It is called if we have only one device
        }
 
+       def statesSince(String info, Date dateObj) {
+               return presenceSensors[0].statesSince()
+       }
+
+       def eventsSince(Date dateObj) {
+               return presenceSensors[0].statesSince()
+       }
+
        def getAt(int ix) {
                presenceSensors[ix]
        }