Changes in config file will not always be applied
Closed this issue · 8 comments
If i change the config file, changed settings will not (always?) applied (homebridge was restarted). Removing .persistant and .accessories folder helps, but will also break already integrated clients.
If the accessory is cached, changes will not show up. Just removd the accessory from config and it will be renoved after the next homebridge start. Then you can add it again with your changes. The other accessories should not be touched
I help myself with renaming device temporarily.. ;) But it would be much better if the plugin (or is it part of homebridge itself) detect changes in config file, isn't it!?
Can i disable the caching of accessories somehow?
No because it should not be neccessary in normal use. Maybe you should consider running a seperate instance of hombridge for or developing?
Sure at the moment it's just development. But changing some URL or the minTemperature / maxTemperature values would be a normal usecase in "production use" and should not result in reconfiguring ALL clients. So, again: is there a way to force reloading the config file or a specific accessory?
Do you think this part of code would be a good (the best?) place to detect changes? I was thinking about introducing a hash over each accessory config to detect changes....
// Remove extra accessories in cache
for (var name in this.accessories) {
var accessory = this.accessories[name];
if (!accessory.reachable) this.removeAccessory(accessory);
}
OK, i found a good way to handle that in method DomotigaPlatform.prototype.addAccessory. So i changed
var accessory = this.accessories[data.name];
into
if ( this.disableCache ===true && this.accessories[data.name] )
{
// always remove old accessories
this.removeAccessory(this.accessories[data.name],true);
}
var accessory;
and
DomotigaPlatform.prototype.removeAccessory = function (accessory, isConfigChange) {
if (accessory) {
var name = accessory.context.name;
if ( isConfigChange ) {
this.log("Removing accessory for re-configuring: " + name);
} else {
this.log.warn("Removing accessory: " + name + ". No longer reachable or configured.");
}
this.api.unregisterPlatformAccessories("homebridge-domotiga", "DomotiGa", [accessory]);
delete this.accessories[name];
}
}
and introduced a optional configuration option. I guess this ok for me. Issue can be closed for now.
Sorry, quiet busy at the moment. Good workaround, close that now.
And finally: I find and implemented a much better solution by introducing some hash value for the relevant config parts. Detects changes reliable and nobody needs to rename the accessory (back and forth). Will be part of the upcoming pull request by the way.