Multiple config.json entries for same platform plugin
See original GitHub issueIs homebridge supposed to support multiple entries in config.json for the same platform plugin?
When using static accessories, homebridge seems to support specifying the same platform plugin multiple times in config.json. The platform constructor is invoked multiple times, with a different value for config
corresponding to each config.json entry. This works brilliantly for homebridge-hue, to specify different settings for different Hue bridges in different config.json entries.
I’m (finally 😉 refactoring homebridge-hue to use dynamic accessories instead and I’m running into an issue. The platform constructor is invoked multiple times, just as for static accessories, but only the last (most recently created) platform instance receives the accessoryRestored
event. Also, there’s no reference to the instance (or config.json entry) that orginally created the accessory. Consequently, the earlier (original) platform instance doesn’t know the accessory has been restored, tries to create it, and obviously receives an error Cannot add a bridged Accessory with the same UUID as another bridged Accessory. I catch the error, so homebridge and homebridge-hue continue to work, but the last (most recently created) platform instance doesn’t know the earlier (original) config.json settings that should still apply to the restored accessory.
Did any of you run into this issue for other plugins? How did you address it?
I suppose I could try and work around this issue by linking the accessories to the platform class rather than to the platform instance. And by somehow using the accessory context to keep track of which instance (or config.json entry) originally created the accessory. However, this seems overly complicated and error prone.
Alternatively, I could just issue an error message and exit homebridge when the platform is specified more than once in config.json. However this seems like a check homebridge should be doing.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
You don’t. Either change the plugin, so a single instance can support both modes simultaneously, or run two separate homebridge instances.
Thank you, will combine I think !
Sent with GitHawk