ZWaveJS.NET does not support multiple drivers
I'm trying to control multiple instances of ZWave JS from the same C# program. For this, I initialize multiple instances of the ZWaveJS.NET.Driver class but as soon as I initialize a second instance, the Driver.Instance of the first instance is overwritten because Driver.Instance is static:
https://github.com/zwave-js/ZWaveJS.NET/blob/6c3db915019895bd99a28edd7370bec5866ecfdb/Visual%20Studio%20Projects/ZWaveJS.NET/ZWaveJS.NET/Driver.cs#L14
So I think we should refactor the library so that it does not use a singleton pattern for the Driver class. Do you agree ?
Ooof!
possible of course, but will need some (quite a bit) of re-work - and thought
From the top of my head
- The Controller class to have an internal
Driverreference be set tothiswithin the following code block https://github.com/zwave-js/ZWaveJS.NET/blob/6c3db915019895bd99a28edd7370bec5866ecfdb/Visual%20Studio%20Projects/ZWaveJS.NET/ZWaveJS.NET/Driver.cs#L769
Example
Controller C = JO.SelectToken("result.state.controller").ToObject<Controller>();
C._Driver = this
-
Any reference inside the controller to
Driver.Instancebe pointed at it -
Each ZWaveNode/Endpoint class will also need a reference (somehow) - They are instanciated directly from the init JSON presently (we could use the Node collection somehow)
-
Various static properties on the driver class to be made instance only.
- SchemaVersionID
- ServerCommunicationPort
- ServerErrorThrottleTime
These are used (I think) during Driver class instance creation, so will need to be optional params on the ctor's
-
Various static properties in the
serverclass be made instance only- this includes static methods
This means having a separate
Serverclass instance for eachDriverinstance
There is a lot that surrounds the static approach presently, unless I'm over thinking it π€
@marcus-j-davies , do you want me to take a shot at it, or do you want to do it?
Hi @spudwebb
I am not one to reject free labour! π Please by all means have a crack at it! π
Thanks
Is this still open or resolved? I see the latest available is '22 still (from Visual Studio NuGet)
Hi, this issue is still open, as v4 has not yet been published.
itβs fixed in the v4 branch. See the PR : https://github.com/zwave-js/ZWaveJS.NET/pull/31
Closing...
This feature is available in V4, where its release is imminent.