I’d like to get an authoritative answer to the question of whether or not the defaultValue for an input is expected to work. If it is, then I’d like to know why it isn’t working as I expect it to. Perhaps my expectations are out of whack?
I have found at least two other askers (argh, new user link limit means I can only add one, search for “device type preferences input validation” for the other):
There haven’t been any useful responses to that specific question, though. I am asking because I’m seeing the same thing in my device. When I supply defaultValue parameters to the input, e.g.
input "onTime", "number", title: "No motion reporting interval", description: "Send no motion report after N minutes of no motion", defaultValue: 1, required: false
The code that references settings.onTime sees a null value unless a value has been explicitly set via the IDE or the app. This doesn’t seem correct. What I want to do is configure the device with a set of useful defaults which are defined in a logical place. I can work around it by defining the defaults elsewhere, but this seems silly.
In Android, I don’t see the default values reflected in either the UI control state or in the settings values available when updated() is called. Settings variables for boolean inputs will be false instead of null. If, at any point, I did set a value by using the UI, it does not go away easily. Uninstalling and reinstalling doesn’t clear it, and setting an empty value under device preferences in the developer tools does different things depending on the input type. To start from a clean slate, I had to install a version of a device type without any preferences and set the values to empty under the device’s preferences in the web tools before reinstalling the device type I was testing. So, I guess what I’m saying is that it takes some care to make sure you’re starting clean.