Fixing some bugs
[smartthings-infrastructure.git] / MotionSensor / MotionSensors.groovy
index 863903c5017090867a58f7ca2b3e5bf676986e59..c799b0e77766697fd893a67c8bebcdfe314452e5 100644 (file)
@@ -16,21 +16,30 @@ public class MotionSensors {
        private String motionLatestValue = "inactive"
 
                
-       MotionSensors(Closure sendEvent, int deviceNumbers) {
+       MotionSensors(Closure sendEvent, int deviceNumbers, boolean init) {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.motionSensors = []
 
+               if (init) {
+                       this.motion = "inactive"
+                       this.currentMotion = "inactive"
+                       this.motionLatestValue = "inactive"
+               } else {
+                       this.motion = "active"
+                       this.currentMotion = "active"
+                       this.motionLatestValue = "active"
+               }
                motionSensors.add(new MotionSensor(id, label, displayName, this.motion, this.motionLatestValue))
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["value"] != motionSensors[0].motion) {
+                       this.motionLatestValue = eventDataMap["value"]
+                       this.motion = eventDataMap["value"]
+                       this.currentMotion = eventDataMap["value"]
                        motionSensors[0].setValue(eventDataMap["value"])
-                       this.motionLatestValue = motionSensors[0].motionLatestValue
-                       this.motion = motionSensors[0].motion
-                       this.currentMotion = motionSensors[0].motion
                        sendEvent(eventDataMap)
                }
        }
@@ -48,10 +57,16 @@ public class MotionSensors {
        def find(Closure Input) {
                motionSensors.find(Input)
        }
+       def sort(Closure Input) {
+               motionSensors.sort(Input)
+       }
        def collect(Closure Input) {
                motionSensors.collect(Input)
        }
-
+       
+       def currentState(String deviceFeature) {
+               currentValue(deviceFeature)
+       }
 
        def currentValue(String deviceFeature) {
                motionSensors[0].currentValue(deviceFeature)//It is called if we have only one device
@@ -62,7 +77,7 @@ public class MotionSensors {
        }
 
        def statesSince(String info, Date dateObj) {
-               return motionSensors[0].statesSince(info, dateObj)
+               return motionSensors[0].statesSince()
        }
 
        def getAt(int ix) {