defaultValue in preferences inputs?

(Michael MacDonald) #1

Hi all.

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.

preferences {
	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.

(Jacob Richard) #2

Are you seeing this on an actual Android / iPhone device, or in the simulator?

I ask because it seems to be hit or miss in the simulator – If i uninstall/reinstall and/or reset the location a few times, I do see the defaultValue show up appropriately.

Along the same lines, I see the defaultValue in my Android device using your exact line of code, once I have published it and installed.

I would suspect this is one (of many) bugs with the simulator, but I could be wrong.

(Michael MacDonald) #3

I’m seeing this with IOS. If I go through the device addition process but don’t explicitly set values, then when configure() is called the various settings’ values are null.

(Mike M.) #4

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.