Fixing bug in Mobile Presence class
[smartthings-infrastructure.git] / AccelerationSensor / AccelerationSensor.groovy
index fcc1688d8ef80664a9feee982e597a700457d887..66cae29667a2c4526bae52af63f3562b1166ea83 100644 (file)
-//Create a class for acceleration sensor
+// Create a class for acceleration sensor
 package AccelerationSensor
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class AccelerationSensor {
-       private String id
-       private String label
-       private String displayName
-       private String acceleration
-       private String currentAcceleration
-       private String accelerationLatestValue
-
-       AccelerationSensor(String id, String label, String displayName, String acceleration, String accelerationLatestValue) {
+import SmartThing.SmartThing
+
+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(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
-       }
-
-       def statesSince() {
-               def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
-                                [name: "acceleration.active", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
-                                  [name: "acceleration.inactive", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def init = Verify.getInt(0,4)
-               def evtToSend = []
-               if (init == 0) {//return empty set
-                       return evtToSend
-               } else if (init == 1) {//send one active event
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 2) {//send two active events
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 3) {//send one inactive event
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 4) {//send two inactive events
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               }
-       }
-
-       def eventsSince() {
-               def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
-                                [name: "acceleration.active", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
-                                  [name: "acceleration.inactive", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
-                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def init = Verify.getInt(0,4)
-               def evtToSend = []
-               if (init == 0) {//return empty set
-                       return evtToSend
-               } else if (init == 1) {//send one active event
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 2) {//send two active events
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       evtActive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 3) {//send one inactive event
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               } else if (init == 4) {//send two inactive events
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       evtInactive.each{
-                               evtToSend.add(it)
-                       }
-                       return evtToSend
-               }
-       }
-
-       
-       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)
        }
 }