package SwitchLevel
import SmartThing.SmartThing
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
public class SwitchLevel extends SmartThing {
// id, label, and display name of the device
- StringBuilder id = new StringBuilder()
- StringBuilder label = new StringBuilder()
- StringBuilder displayName = new StringBuilder()
- // Features with numberical values
- MutableInteger currentLevel = new MutableInteger()
+ String id
+ String label
+ String displayName
// Maps from features to values
- HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
+ HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
- SwitchLevel(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentLevel) {
- deviceIntValuesMap = deviceIntValueSmartThing
+ SwitchLevel(Closure sendEvent, String id, String label, String displayName, Integer currentLevel) {
+ deviceIntValueSmartThing = deviceIntValuesMap
idSmartThing = id
labelSmartThing = label
displayNameSmartThing = displayName
this.id = id
this.label = label
this.displayName = displayName
- this.currentLevel = currentLevel
deviceIntValuesMap.put("level", currentLevel)
}
}
def setLevel(int newValue) {
- if (!currentLevel.getValue().equals(newValue)) {
- String tmpID = id.toString()
- variable.setValue(newValue)
- println("the switch with id:$tmpID is setted to level $level!")
- sendEvent([name: "level", value: newValue, deviceId: tmpID, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- // Methods to return values
- def getCurrentLevel() {
- return currentLevel.getValue()
+ action(newValue, "level")
}
}