//Create a class for presence sensor package MotionSensor import Timer.SimulatedTimer 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 = [] MotionSensor(String id, String label, String displayName, String motion, String motionLatestValue) { this.id = id this.label = label this.displayName = displayName this.motion = motion this.currentMotion = motion this.motionLatestValue = motionLatestValue } def setValue(String value) { this.motionLatestValue = motion println("the motion sensor with id:$id is triggered to $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 } } def latestValue(String deviceFeature) { if (deviceFeature == "motion") { return motionLatestValue } } }