getPreferences()?

Is the undocumented method getPreferences() supposed to work?

getPreferences() = [sections:[], defaults:true]

I always get the above, even with multiple Preferences defined.

Anyone knows anything about this? Or is there another way of getting a list of ALL defined Preferences? Not just Preferences with a saved value (those you can get from 'settings' or 'this.binding.variables').

Are you talking about in the driver? All of the "Preferences" you're talking about are stored as part of the map settings. For example, if your setting is for timeout it would be accessible via settings.timeout. If you want to get all of them, you would have to pull it out with something like this:

def getSettings(){
    settings.each{it->
        log.debug it
    }
}

But why would you want to do this? If you are in the driver already, you can just look at what the settings are. There is no way to pull the settings out of a device from an app or another device. So, there is no real practical application to what you are asking. There is no method to pull the settings out of a device by an app unless the driver has implemented one specifically, which is not the norm.

What other preferences are there?

Yes, drivers, sorry I wasn't clear. As I mentioned in my post, 'settings' does not contain all defined Preferences, just those that have a value saved to them.
I can't get all defined Preferences from settings.

I want to get the list of defined Preferences dynamically in code, that is why.

But when it is implemented it is possible, though this is not what this is for in this case anyway.

Those which have not had a value saved to them yet, if they have not been set by the user and/or doesn't have a default value they do not show in "settings".

My question is just to know IF there is a way to do this ("settings" does NOT fulfill the criteria) and, also, what getPreferences() is supposed to be doing...

What do you mean by "defined Prefernces"? If the setting doesn't have a value, then it isn't defined, is it?

Why? You can get the specific preference without having to get a full list of them. Since you are writing the driver, you should know which preferences are included, shouldn't you?

Yes, but that would mean that it would only work for you drivers. If you are trying to do this with your custom drivers, then just build the function in the driver. You can't write to the settings from an app.

Yes, it does. Because if a setting doesn't have a value, then you want to pull out nothing? Then give the settings a default value and they will always be defined. But if something is not defined, it doesn't exist.

They are defined in "metadata -> preferences", which is what I mean here and which should be very clear from the context.

Yes, of course I know, but that is not the point, I would then need to define that list again, even though it exists in the metadata section. If there really isn't a way to get this inside the platform, I will do it in another way, but that is not my question.

Also not my question, but yes, to a custom driver I can write to settings from an app.

Not the point, it IS defined in the metadata, just not available anywhere I've found it yet. For example, the definition from the metadata can be retrieved with "getDefinitionData()".

If anyone does know more about this, it would be great to know :slight_smile: How useful and/or practical being able to do this is, is besides the point.

I think I've already answered your question. In short, no, you can't do what you are asking.

Then remains the question, getPreferences(), is it supposed to work? It is not documented nor mentioned in the forum.
I'm still hoping someone else knows this?

Did you try it?

The only people who could answer a question about an undocumented method is hubitat staff. They are not likely to answer you unless tagged.

Yes, as stated in my first post, I get this back when calling it:

[sections:[], defaults:true]

Always the same. So the question is, is it a bug, or is this method not supposed to exist. Only the author of the code would know for sure.

@bravenel, would this be a question for you?

Really? Cause I get an unsigned method error. It doesn't return anything at all.

It needs to be called from inside "preferences". A bunch of extra methods are available there. Since updateDataValue is also available, the data can then be exported to a different context.

Best of luck.

I got getPreferences() to work, the "trick", now really obvious and I feel really stupid, was to execute it after "preferences {}" in "metadata". Really need to keep track of the different scopes. This was fun :slight_smile:

2 Likes