Method called when switching drivers - Is there one?

Is there a method that gets called if/when a user switches drivers -- i.e., something like the installed() method, but called when the "Save" button is pressed after changing the driver for a device? It would be handy if there was (I can't find anything documented, but am asking because there's a lot of developer information which seems to be captured in people's experience rather than the documents). I'm looking for something to perform driver initialization / setup following a driver change. Right now, I do a check at boot using the initialize() method which is workable, though if a driver-switch-time method existed, I would use that instead.

Doesn't installed() do that? Could be wrong, haven't thought about this in a while.

EDIT: Obviously it doesn't as you already mentioned it in your OP. Sorry about that.

I think it only activates immediately following pairing when the driver is selected based on its fingerprint. Not 100% certain.

It doesn't seem to, just tried it.

Does updated() get called when you click Save? I know it does if you changed a User Prefence/Setting. Not sure about when the driver Type is changed, though.

1 Like

there isn't an event for this, there probably should be, but there isn't right now....

Thanks for the clarity. Much appreciated. If such a thing ever does get implemented, consider that if you edit a custom driver, then save the edits, that should be treated as a driver change.

1 Like

I'd second this. The example I would like to see catered for (which in effect is the same as described above), is when a driver is updated through HPM, which is the same as having gone into the driver code and making a change manually. Having a standard method called in the code when this occurs would allow for code to be triggered that manages the transition to the updated driver, such as creating new attributes, running other methods to re-establish the device state, etc. This removes the need for some developers to instruct users to "run this command" after an update is applied, giving the developer the control of what is executed when a change is applied, reducing the likelihood of issues due to users forgetting or not knowing the process to follow (like I did recently :slight_smile: ).

1 Like

Download the Hubitat app