Update / repair settings variable

(Matty & Troy) #1

I’m new to Groovy, so forgive me if this is an elementary question.

I have a function that is “fixing” the settings variable for my needs. Some of it is working around known bugs, others are to add some information that is needed across the board.

When I update the settings variable, it is only updated inside the scope of the calling function - how do I bust out of that limitation?

I know there exists a state variable - but I’d prefer to have all my settings in one place.

(Brian Steere) #2

I don’t believe you can programmatically change the settings variable. If you want everything in one place and cleaned up, I would suggest using something like state.settings and update accordingly when installed/updated. I think you can initialize state.settings with just state.settings = settings but I haven’t tested that.

(Matty & Troy) #3

I think there should be some mechanism for this - even if only during the update / install call.

How are other people handling settings cleanup? Eg dealing with bugs that mean variables can sometimes be a map or sometimes a string etc

(Geko) #4

In my experience, settings are read-only properties from the app point of you. They can only be changed from the UI while the app being installed or configured. The only known way to persist data is using state variable as @Dianoga pointed out.

(codersaur) #5

Not anymore, it appears you can now use:

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)