public class Alarm 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 currentAlarm = new StringBuilder()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+ HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
- Alarm(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentAlarm) {
- deviceValuesMap = deviceValueSmartThing
+ Alarm(Closure sendEvent, String id, String label, String displayName, String currentAlarm) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentAlarm = currentAlarm
deviceValuesMap.put("alarm", currentAlarm)
}
// Methods to set values
def both() {
- action("both")
+ action("both", "alarm")
}
def on() {
- action("both")
+ action("both", "alarm")
}
def off() {
- action("off")
+ action("off", "alarm")
}
def siren() {
- action("siren")
+ action("siren", "alarm")
}
def strobe() {
- action("strobe")
- }
-
- def action(String newValue) {
- if (!currentAlarm.equals(newValue)) {
- String tmpID = id.toString()
- currentAlarm.replace(0, currentAlarm.length(), newValue)
- println("the alarm with id:$tmpID is changed to $newValue!")
- sendEvent([name: "alarm", value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentAlarm() {
- return currentAlarm.toString()
+ action("strobe", "alarm")
}
}