Fixing bug in Mobile Presence class
[smartthings-infrastructure.git] / AccelerationSensor / AccelerationSensor.groovy
index 78a9bed73ee91a74c48af4af5c3c46897777a28d..66cae29667a2c4526bae52af63f3562b1166ea83 100644 (file)
@@ -1,55 +1,32 @@
-//Create a class for acceleration sensor
+// Create a class for acceleration sensor
 package AccelerationSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class AccelerationSensor {
-       private String id
-       private String label
-       private String displayName
-       private String acceleration
-       private String currentAcceleration
-       private String accelerationLatestValue
-       private List states = []
-       private List timeOfStates = []
+public class AccelerationSensor extends SmartThing {
+       // id, label, and display name of the device
+       String id
+       String label
+       String displayName
+       // Maps from features to values
+       HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
+       // Possible values for eventsSince method
+       List<String> possibleValues = new ArrayList<String>();
 
-       AccelerationSensor(String id, String label, String displayName, String acceleration, String accelerationLatestValue) {
+       AccelerationSensor(Closure sendEvent, String id, String label, String displayName, String currentAcceleration) {
+               deviceValueSmartThing = deviceValuesMap
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               possibleValuesSmartThings = possibleValues
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.acceleration = acceleration
-               this.currentAcceleration = acceleration
-               this.accelerationLatestValue = accelerationLatestValue
-       }
-
-       def setValue(String value) {
-               println("the acceleration sensor with id:$id is triggered to $value!")
-               this.accelerationLatestValue = value
-               this.acceleration = value
-               this.currentAcceleration = value
-               this.states.add(value)
-               this.timeOfStates.add(System.currentTimeMillis())
-       }
-
-       def statesSince(String info, Date dateObj) {
-               def List happenedStates = []
-               def sinceThen = dateObj.time
-               for (int i = 0;i < timeOfStates.size();i++) {
-                       if (timeOfStates[i]>=sinceThen)
-                               happenedStates.add(states[i])
-               }
-               return happenedStates
-       }
-
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "acceleration") {
-                       return acceleration
-               }
-       }
+               possibleValues.add("active")
+               possibleValues.add("inactive")
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "acceleration") {
-                       return accelerationLatestValue
-               }
+               deviceValuesMap.put("acceleration", currentAcceleration)
        }
 }