Okay, so I'm having a hard time getting enum inputs to work properly.
If I set an enum input using its dropdown list then it works as expected, but when I use device.updateSetting() then the new value I set is present in the settings map, but it's not displayed in the gui after refreshing the page. I am able to set other input types just fine, like number, string, bool. What the heck am I missing here? I'm running on v2.2.8.152.
Here's a test driver that I'm using with a virtual device for testing. When the device page is first loaded, all inputs should show the default of "1", and the boolean input is enabled. Click Configure which will set all inputs to a value of "5", and the boolean to false, then refresh the page. What I'm seeing is that only the enum inputs don't show the set value, and instead they all show the default value of 1. The settings map shows all of the correct values, which you can see if you click Refresh.
If you manually select a value of say 2 in an enum and update the prefs then this value is shown in both the gui and the settings map. However, if you click Reset to remove all of the settings, then refresh the page, this value of 2 is still present in the gui, when it should go back to the default value. And likewise, after the Reset the settings map is empty, but the gui still shows the prior settings?
So in summary, I'm seeing two issues for just the enum inputs:
1} device.updateSetting() updates the settings map, but not the gui.
2} device.removeSetting() updates the settings map, but not the gui.
[code was updated to add another input test]
metadata {
definition (name: "Test Inputs", namespace: "test", author: "test", importUrl: "") {
capability "Configuration"
capability "Refresh"
command "reset"
}
preferences {
input name: "enumStrL", type: "enum", title: "enumStrL", defaultValue: 1, options:["1","2","3","4","5","6"]
input name: "enumInt", type: "enum", title: "enumInt", defaultValue: 1, options:[1:"1",2:"2",3:"3",4:"4",5:"5",6:"6"]
input name: "enumStr", type: "enum", title: "enumStr", defaultValue: 1, options:["1":"1","2":"2","3":"3","4":"4","5":"5","6":"6"]
input name: "enumIntM", type: "enum", title: "enumIntM", defaultValue: 1, options:[[1:"1"],[2:"2"],[3:"3"],[4:"4"],[5:"5"],[6:"6"]]
input name: "enumStrM", type: "enum", title: "enumStrM", defaultValue: 1, options:[["1":"1"],["2":"2"],["3":"3"],["4":"4"],["5":"5"],["6":"6"]]
input name: "number", type: "number", title: "number", defaultValue: 1
input name: "string", type: "string", title: "string", defaultValue: 1
input name: "bool", type: "bool", title: "bool", defaultValue: true
}
}
void configure() {
logInfo "Configure"
device.updateSetting("enumStrL", [value: "5", type: "enum"])
device.updateSetting("enumInt", [value: "5", type: "enum"])
device.updateSetting("enumStr", [value: "5", type: "enum"])
device.updateSetting("enumIntM", [value: "5", type: "enum"])
device.updateSetting("enumStrM", [value: "5", type: "enum"])
device.updateSetting("number", [value: "5", type: "number"])
device.updateSetting("string", [value: "5", type: "string"])
device.updateSetting("bool", [value: "false", type: "bool"])
runIn(1, "refresh")
}
void reset() {
logInfo "Reset"
settings.each { name, data ->
logInfo "Removing $name = ${settings[name]}"
device.removeSetting(name)
}
}
void updated() {
logInfo "Updated"
runIn(1, "refresh")
}
void refresh() {
logInfo "Refresh"
logInfo "settings: $settings"
}
void logInfo(String msg) {
log.info "${device.displayName}: ${msg}"
}