I want to add use of preferences to a custom edge driver so I can enter (via the app) a couple of device parameters to be used at initialization time. I understand the preferences conceptually from the ST documentation, but am looking for some simple examples of actual code to follow (or reuse with pride ). The examples in the existing ST drivers (e.g. Z-wave sensor) I have found so far are either too complex, or perhaps a different usage of the “preference” concept than I’m looking for.
Thanks in advance
The preference definitions in the zwave-sensor profiles are pretty much par for the course. This one looks to have a good range of different types to use as a model. ST has started moving some of their profiles to use explicit preferences, and I’d expect to see more of them go that way so they can support translations (see zigbee-contact for an example).
Use in code is as simple as using device.preferences.yourpreferenceid to access it. The ST z-wave drivers have a framework to map preferences to configuration parameters, and then check which have changed to send them to the device (on wake up if the device is sleepy), so the logic does get a bit complicated.
I was struggling a bit to understand the purpose of separate configurations and preferences files in the context of user supplied “preferences”, and your comments helped me realize they were targeting different purposes. I think my driver only has non-sleepy devices to manage (I’ll need to confirm), which should allow a much simpler subset.