Because the entities are saved in persistent storage with their states, and the capability definitions are stored (cloned to) the entities when extended, you still need to refresh.
At line 666 (!) of your mapDevice()
function, where you are extending capabilities if given, you can use the extendCapabilities()
method to extend an array of capabilities (eliminating your loop there that does pretty much the same thing). You could then add a test to see if there is a change to the version of your Controller class or the system capabilities, for example, and refresh based on that:
// capabilities
if (capabilities) {
this.log.debug(5, "%1 [%2] adding capabilities: %3", this, id, capabilities);
e.extendCapabilities( capabilities );
// Check controller and system capabilities versions for changes
const vinfo = { ...Capabilities.getSysInfo(), controller: VERSION };
const hash = util.hash( JSON.stringify(vinfo) );
if ( e._hash !== hash ) {
e.refreshCapabilities();
e._hash = hash;
}
}
You might also consider a mechanism to have it do the check only once per run/startup of the Controller instance, the first time it looks at the entity, rather than every time this method is called with capabilities.