No, the preference’s value cannot be modified within the driver’s code, it’s only done through the user input in the app.
You can use the function try_update_metadata, it overrides the current device profile with the one you use in the parameter.
I’ll make some tests to see what happens with the preferences if we send the same profile name…
(www.rboyapps.com - Making SmartThings Easy!)
I would also be interested in this feature, it’s something groovy can do (for both SmartApps and Device Handlers), it would be of great help to extend this feature to both SmartApps and Drivers in the new platform to effectively migrate the existing implementations. There are lots of use cases for this for both SmartApps (which I’ve already submitted requests and use cases in the past) and for drivers, for example with LAN driver that auto detect a camera feature has been enabled directly on the camera, this now needs to be reflected in the device settings. Perfect example if motion detection options. The user can select options X, but then the driver detects that the settings on the camera were updated to Y, it now needs to update the settings so that they are in sync. This is the current implementation in the groovy DTH’s.
So, after making some tests I found out that even using try_update_metadata doesn’t reset the preferences unless you use different names in the other profile, so, I’ll check this with the internal team.
Thank you for providing your feedback about this, @RBoy.