ZWaveJS.NET icon indicating copy to clipboard operation
ZWaveJS.NET copied to clipboard

ZWaveJS.NET does not support multiple drivers

Open spudwebb opened this issue 1 year ago β€’ 5 comments

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 ?

spudwebb avatar Feb 15 '24 20:02 spudwebb

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 Driver reference be set to this within 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.Instance be 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 server class be made instance only

    • this includes static methods

    This means having a separate Server class instance for each Driver instance

There is a lot that surrounds the static approach presently, unless I'm over thinking it πŸ€”

marcus-j-davies avatar Feb 15 '24 20:02 marcus-j-davies

@marcus-j-davies , do you want me to take a shot at it, or do you want to do it?

spudwebb avatar Feb 16 '24 13:02 spudwebb

Hi @spudwebb

I am not one to reject free labour! πŸ˜‰ Please by all means have a crack at it! πŸ‘

Thanks

marcus-j-davies avatar Feb 16 '24 16:02 marcus-j-davies

Is this still open or resolved? I see the latest available is '22 still (from Visual Studio NuGet)

officialh1 avatar Mar 25 '24 14:03 officialh1

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

marcus-j-davies avatar Mar 25 '24 16:03 marcus-j-davies

Closing...

This feature is available in V4, where its release is imminent.

marcus-j-davies avatar Jun 27 '24 18:06 marcus-j-davies