import Timer.SimulatedTimer
public class ContactSensor {
- private int id
+ private String id
private String label
private String displayName
private String contactState
- private String contactLatestValue
+ private String currentContact
+ private String latestValue
+ private String alarmState
+ private List events = []
+ private List timeOfEvents = []
+
- ContactSensor(int id, String label, String displayName, String contactState, String contactLatestValue) {
+ ContactSensor(String id, String label, String displayName, String contactState, String currentContact, String alarmState, String latestValue) {
this.id = id
this.label = label
this.displayName = displayName
this.contactState = contactState
- this.contactLatestValue = contactLatestValue
+ this.currentContact = currentContact
+ this.latestValue = latestValue
+ this.alarmState = alarmState
}
def setValue(String value) {
- this.contactLatestValue = contactState
println("the contact sensor with id:$id is triggered to $value!")
this.contactState = value
+ this.currentContact = value
+ this.latestValue = value
+ //this.events.add(eventDataMap)
+ //this.timeOfEvents.add(System.currentTimeMillis())
+ }
+
+ /*def eventsSince(Date dateObj) {
+ def List happenedEvents = []
+ def sinceThen = dateObj.time
+ for (int i = 0;i < timeOfEvents.size();i++) {
+ if (timeOfEvents[i]>=sinceThen)
+ happenedEvents.add(events[i])
+ }
+ return happenedEvents
+ }*/
+
+ def on() {
+ println("the contact sensor with id:$id is armed!")
+ this.alarmState = "armed"
+ }
+
+ def off() {
+ println("the contact sensor with id:$id is not armed!")
+ this.alarmState = "not armed"
}
def currentValue(String deviceFeature) {
}
}
+ def currentState(String deviceFeature) {
+ if (deviceFeature == "contact") {
+ return contactState
+ }
+ }
+
def latestValue(String deviceFeature) {
if (deviceFeature == "contact") {
- return contactLatestValue
+ return latestValue
}
}
}