Page 1 of 1

Strategy for multiple device instances

Posted: Saturday 11 March 2017 21:49
by ubee
What is the best strategy to add multiple instances of devices supported by the same plugin?

Think about a plugin implementing a special type of switch device. I don't know how many switches I need from the beginning, and I want to add more switches later.

I guess one way to do this is to add more instances of the same hardware. With this approach the obvious question is if all variables in the plugin module are unique and bound to each instance of the module, or if global variables are shared between the instances.

What I look for is a way to create new Domoticz devices by incrementing the unit identifier. But how should I trigger this event? I lack a callback function for this kind of operation.

Any advice on this topic is appreciated.

Re: Strategy for multiple device instances

Posted: Saturday 11 March 2017 23:32
by Dnpwwo
@ubee,

Personally I just use more instances of the same hardware. The plugins are completely separate from each other so you don't need to do anything special, all variables are local to a particular plugin instance. I run 3 Kodi plugins and they have no visibility of each other.

Each plugin gets its own hardware ID so you can create Unit #1 in every plugin instance and Domoticz will handle it. The Devices dictionary will contain only the devices for the specific plugin instance.

Re: Strategy for multiple device instances

Posted: Sunday 12 March 2017 8:22
by ubee
@dnwpoo,

Thanks for your reply. Good to know all data is privat to each instance of the plugin and I can reuse unit=#1 in every instance. I will follow your advice.