Is there any way to dynamically fill a preferences field from code?
In my SmartApp, I am expanding on @brianwilson’s ThingSpeak code, but making the interface a little more user-friendly by automatically creating a channel on the user’s behalf.
My approach is to give the user an option to use an existing channel or create a new one. That means that I have options in my settings for “Channel ID” and “Channel Key”, but if those are empty, I create a new channel. I would like to fill in those fields once I create a channel and then use those values for my actual POSTs.
Does anybody know how to do this? Are preferences uni-directional?
Here’s my solution.
I use a dynamic page and set the description as a state variable (to my knowledge, “Default” is only available for device handlers)
app.updateSetting(inputName, [type: type, value: value])
app.updateSetting(inputName, value)
// or for DTHs:
device.updateSetting(inputName, [type: type, value: value])
device.updateSetting(inputName, value)
However, while the above code seems to be able to change settings with existing non-null values, it does not appear to be able to add values to settings that are currently empty. So half-way there at least…
I wouldn’t expect a ton of responses regarding this, though it’s huge. Unless you’ve tried writing some pretty complex apps/handlers most wouldn’t even understand the implications here…