Runtime/Dynamic Driver Capabilities?

Is there any way at runtime or to dynamically add/remove driver capabilities? I've written a driver for the august door lock, some people have the included contact sensor others do not... It's really nice to have both capabilities listed under the same device so I don't really want two diffrent devices but I also don't like representing false information :).

No. there isn't.

Any good patterns other drivers have utilized you might recommend?

You could offer a Preference setting (bool) as to whether it has the contact sensor or not, just to draw people’s attention to it. You could have an attribute ‘hasContact’, another bool perhaps.

The approach I took when writing a driver for the august smartlock pro on another platform was to create the contact sensor as a separate child device, if enabled in the lock device settings.

2 Likes

This is what I was about to suggest. You can dynamically add and remove child devices. Those child devices implement the optional capabilities.

Thank you - that's what I am writing now. I decided not to for the door sense device since I really like the current dashboard showing open/close and lock/unlock under a single device :).

Can you add grandchild devices from the app? I didn't see an API for it - so adding a method on my child device to create children which will work but it's an extra transition.