1 //Create a class for contact sensor
3 import Timer.SimulatedTimer
5 public class ContactSensor {
8 private String displayName
9 private String contactState
10 private String currentContact
11 private String latestValue
12 private String alarmState
13 private List events = []
14 private List timeOfEvents = []
17 ContactSensor(String id, String label, String displayName, String contactState, String currentContact, String alarmState, String latestValue) {
20 this.displayName = displayName
21 this.contactState = contactState
22 this.currentContact = currentContact
23 this.latestValue = latestValue
24 this.alarmState = alarmState
27 def setValue(String value) {
28 println("the contact sensor with id:$id is triggered to $value!")
29 this.contactState = value
30 this.currentContact = value
31 this.latestValue = value
32 this.events.add(eventDataMap)
33 this.timeOfEvents.add(System.currentTimeMillis())
36 def eventsSince(Date dateObj) {
37 def List happenedEvents = []
38 def sinceThen = dateObj.time
39 for (int i = 0;i < timeOfEvents.size();i++) {
40 if (timeOfEvents[i]>=sinceThen)
41 happenedEvents.add(events[i])
47 println("the contact sensor with id:$id is armed!")
48 this.alarmState = "armed"
52 println("the contact sensor with id:$id is not armed!")
53 this.alarmState = "not armed"
56 def currentValue(String deviceFeature) {
57 if (deviceFeature == "contact") {
62 def currentState(String deviceFeature) {
63 if (deviceFeature == "contact") {
68 def latestValue(String deviceFeature) {
69 if (deviceFeature == "contact") {