public class Switch 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 currentSwitch = 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>()
// Possible values for eventsSince method
- List<StringBuilder> possibleValues = new ArrayList<StringBuilder>();
+ List<String> possibleValues = new ArrayList<String>();
- Switch(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentSwitch) {
- deviceValuesMap = deviceValueSmartThing
+ Switch(Closure sendEvent, String id, String label, String displayName, String currentSwitch) {
+ deviceValueSmartThing = deviceValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentSwitch = currentSwitch
possibleValues.add("on")
possibleValues.add("off")
// Methods to set values
def on() {
- action(currentSwitch, "on", "switch")
+ action("on", "switch")
}
def on(LinkedHashMap metaData) {
}
def off() {
- action(currentSwitch, "off", "switch")
+ action("off", "switch")
}
def off(LinkedHashMap metaData) {
off()
}
-
- def action(StringBuilder variable, String newValue, String feature) {
- if (!variable.toString().equals(newValue)) {
- String tmpID = id.toString()
- variable.replace(0, variable.length(), newValue)
- println("$feature of the light with id:$tmpID is changed to $newValue!")
- sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentSwitch() {
- return currentSwitch.toString()
- }
}