1 //Create a class for presence sensor
3 import Timer.SimulatedTimer
5 public class MotionSensor {
8 private String displayName
10 private String currentMotion
11 private String motionLatestValue
12 private List states = []
13 private List timeOfStates = []
15 MotionSensor(String id, String label, String displayName, String motion, String motionLatestValue) {
18 this.displayName = displayName
20 this.currentMotion = motion
21 this.motionLatestValue = motionLatestValue
24 def setValue(String value) {
25 println("the motion sensor with id:$id is triggered to $value!")
26 this.motionLatestValue = value
28 this.currentMotion = value
29 this.states.add(value)
30 this.timeOfStates.add(System.currentTimeMillis())
33 def statesSince(String info, Date dateObj) {
34 def List happenedStates = []
35 def sinceThen = dateObj.time
36 for (int i = 0;i < timeOfStates.size();i++) {
37 if (timeOfStates[i]>=sinceThen)
38 happenedStates.add(states[i])
44 def currentValue(String deviceFeature) {
45 if (deviceFeature == "motion") {
50 def latestValue(String deviceFeature) {
51 if (deviceFeature == "motion") {
52 return motionLatestValue