-//Create a class for presence sensor
+// Create a class for presence sensor
package PresenceSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
-public class PresenceSensor {
- private String id
- private String label
- private String displayName
- private String presence
- private String currentPresence
- private String presenceLatestValue
+public class PresenceSensor extends SmartThing {
+ // id, label, and display name of the device
+ StringBuilder id = new StringBuilder()
+ StringBuilder label = new StringBuilder()
+ StringBuilder displayName = new StringBuilder()
+ // Features with string values
+ StringBuilder currentPresence = new StringBuilder()
+ // Maps from features to values
+ HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ // Possible values for eventsSince method
+ List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
- PresenceSensor(String id, String label, String displayName, String presence, String presenceLatestValue) {
+ PresenceSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentPresence) {
+ deviceValuesMap = deviceValueSmartThing
+ idSmartThing = id
+ labelSmartThing = label
+ displayNameSmartThing = displayName
+ sendEventSmartThings = sendEvent
+ possibleValuesSmartThings = possibleValues
+
+ // Initialization
this.id = id
this.label = label
this.displayName = displayName
- this.presence = presence
- this.currentPresence = presence
- this.presenceLatestValue = presenceLatestValue
- }
-
- def setValue(String value) {
- println("the presence sensor with id:$id is triggered to $value!")
- this.presenceLatestValue = value
- this.presence = value
- this.currentPresence = value
- }
+ this.currentPresence = currentPresence
+ possibleValues.add("present")
+ possibleValues.add("not present")
-
- def currentValue(String deviceFeature) {
- if (deviceFeature == "presence") {
- return presence
- }
+ deviceValuesMap.put("presence", currentPresence)
}
- def latestValue(String deviceFeature) {
- if (deviceFeature == "presence") {
- return presenceLatestValue
- }
+ // Methods to return values
+ def getCurrentPresence() {
+ return currentPresence.toString()
}
}