Is it possible to reset preferences from a tile action method?

(Ron) #1

Is it possible to set reset preferences in code. I am able to get the value just using the preference name as a variable but I can’t seem to “set” that value in code.

I have a preferences for my modified Fibaro Motion Sensor Code and I want the “reset to defaults” button to send the zwave settings as they are configured out of the box and change the preferences back to the defaults.

For example I have a preference for lux report interval, IlumReportInt
input(“illumReportInt”, “number”, title: “Illum Report Interval (42) 0-65535 0=none (default), <5 may block temp readings, too low will waste battery”, description: “Time interval in seconds to report illum regardless of change”)

When reset is selected I would like this to reset to 0.

I can use the variable like this
log.debug “Illum Interval Preference illumReportInt=$illumReportInt”

but trying to set that value does not work

produces error
groovy.lang.MissingPropertyException: No such property: illumReportInt for class: script14283931762081368481694 @ line 183

I tried
preferences.illumReportInt=0 which I think I saw somewhere but it produces no error but also doesn’t change the value.

Is it possible to alter preferences settings from code ?

(Bruce) #2

Why don’t you just make internal (to the app) copies of the preferences you want to reset, and have your code use the copies instead of the actual preferences. Then you could reset the copies from a tile action method.

(Ron) #3

Because I want the user to see the reset when it’s done.

What I am trying to do is provide the user with a “Reset Factory Defaults” tile.

This would change all the settings back to factory defaults. That part is easy doing as you say by using a second set of values, in my case I just hard code them But when the reset is done I want those values to be reflected in the preferences page if it is opened.

So for example I mentioned Illumination Report Interval. Out of the box the value is 0 which saves batter by never reporting on a schedule, instead it reports when the illumination changes a certain amount. (Another param settings controls this amount) If the user changes this to 300 (every 5 min) and leave the preferences page. If at a later time they select “Reset Factory Defaults” I would like when they open the preferences that they see “0” and not 300. I can’t find a way to change the value back to the default so it is correctly displayed.

(codersaur) #4

I’ve got the same issue. I want to be able to update the value of device.preferences from code. So linking to another thread which discusses this: Seeking clarification on preferences{} and actual device params

FYI, you can enumerate all devices using the following code, you just don’t seem to be able to change them:

device.preferences.each { p ->
	log.debug "$device.displayName: Preference: ${p}"