Infrastruction modification
[smartthings-infrastructure.git] / MotionSensor / MotionSensor.groovy
index 931069b165234b9182a88fc43ac946169b4fa049..85b5618f016275dba3cd8df56d9dff5fc02ae647 100644 (file)
@@ -1,90 +1,40 @@
-//Create a class for presence sensor
+//Create a class for motion sensor
 package MotionSensor
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class MotionSensor {
-       private String id
-       private String label
-       private String displayName
-       private String motion
-       private String currentMotion
-       private String motionLatestValue
-
-       MotionSensor(String id, String label, String displayName, String motion, String motionLatestValue) {
+import SmartThing.SmartThing
+
+public class MotionSensor extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with string values
+       StringBuilder currentMotion = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       // Possible values for eventsSince method
+       List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+
+       MotionSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentMotion) {
+               deviceValuesMap = deviceValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+               possibleValuesSmartThings = possibleValues
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.motion = motion
-               this.currentMotion = motion
-               this.motionLatestValue = motionLatestValue
-       }
-
-       def setValue(String value) {
-               println("the motion sensor with id:$id is triggered to $value!")
-               this.motionLatestValue = value
-               this.motion = value
-               this.currentMotion = value
-       }
-
-       def statesSince() {
-               eventsSince()
-       }
-
-       def eventsSince() {
-               def evtActive = [[name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
-               def evtInactive = [[name: "motion", value: "inactive", deviceId: "motionSensorID0", 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 currentState(String deviceFeature) {
-               currentValue(deviceFeature)
-       }
+               this.currentMotion = currentMotion
+               possibleValues.add("active")
+               possibleValues.add("inactive")
 
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "motion") {
-                       return motion
-               }
+               deviceValuesMap.put("motion", currentMotion)
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "motion") {
-                       return motionLatestValue
-               }
+       // Methods to return values
+       def getCurrentMotion() {
+               return currentMotion.toString()
        }
 }