Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / MotionSensor / MotionSensor.groovy
index 01f1363256190d9c5411bcfc4da8b475c974a588..5cb2befd50c414142ab6338f8fe025912545eab9 100644 (file)
@@ -1,83 +1,32 @@
-//Create a class for presence sensor
+//Create a class for motion sensor
 package MotionSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class MotionSensor {
-       private String id
-       private String label
-       private String displayName
-       private String motion
-       private String currentMotion
-       private String motionLatestValue
+public class MotionSensor 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>();
 
-       MotionSensor(String id, String label, String displayName, String motion, String motionLatestValue) {
+       MotionSensor(Closure sendEvent, String id, String label, String displayName, String currentMotion) {
+               deviceValueSmartThing = deviceValuesMap
+               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() {
-               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)
-       }
-
-       
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "motion") {
-                       return motion
-               }
-       }
+               possibleValues.add("active")
+               possibleValues.add("inactive")
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "motion") {
-                       return motionLatestValue
-               }
+               deviceValuesMap.put("motion", currentMotion)
        }
 }