New version of a driver when is loaded? is there a method which is called when new driver is loaded?

Hey
I have some data which I will like to update when a new version of a driver is installed:


version most important :slight_smile:
So is any method which is called when driver is updated?
Or at least is a different way to define the version so it will automatically display and update in device info?
Thans

I don't believe it's possible.

I usually do this type of thing in updated() which is called when the "save preferences" button is pressed. Then I just get in the habit of hitting save preferences on affected devices whenever I update a driver.

Or you could add your own command / method like:

command "driverChange"

def driverChange() {
//do your stuff here
}

Another option would be to do it from parse() but that means it runs every time parse() is called, so consider the performance impact.

If you're already doing something with state or atomicstate in parse() anyway then you could consider putting it in a state / atomicstate variable instead.

There is one way to do something every time the driver is called i.e. when an event occurs on a device that's using it and the driver is instantiated for that device. Again though you have to consider if this is worth it performance wise. Something like:

import groovy.transform.Field
@Field final String LOG_ID = generateLogId()

private String generateLogId() {
Random rand = new Random()
Integer logNo = 1000000 + rand.nextInt(9000000)
return logNo.toString()
}

LOG_ID is evaluated as soon as the driver is instantiated, which causes generateLogId() to be called. You might be able to use a similar technique to update the device data although I've never tried it myself, it's possible you might run into scope issues when trying to save the driver in the editor.

the new method I try and is working of course but I have more than 40 devices so manual all of them is too much
But I can use Preference Manager for this or even a rule. But I hoped is something on the driver level

Did you try the @Field suggestion?

Updated() is called when you hit save

Not yet. I'm not at home