-//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
- private List states = []
- private List timeOfStates = []
+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
- 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 == "motion") {
- return motion
- }
- }
+ possibleValues.add("active")
+ possibleValues.add("inactive")
- def latestValue(String deviceFeature) {
- if (deviceFeature == "motion") {
- return motionLatestValue
- }
+ deviceValuesMap.put("motion", currentMotion)
}
}