Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZWaveJS.NET does not support multiple drivers #61

Closed
spudwebb opened this issue Feb 15, 2024 · 6 comments · May be fixed by #31
Closed

ZWaveJS.NET does not support multiple drivers #61

spudwebb opened this issue Feb 15, 2024 · 6 comments · May be fixed by #31

Comments

@spudwebb
Copy link

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:

internal static volatile Driver Instance;

So I think we should refactor the library so that it does not use a singleton pattern for the Driver class. Do you agree ?

@marcus-j-davies
Copy link
Member

Ooof!

possible of course, but will need some (quite a bit) of re-work - and thought

From the top of my head

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 🤔

@spudwebb
Copy link
Author

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

@marcus-j-davies
Copy link
Member

Hi @spudwebb

I am not one to reject free labour! 😉
Please by all means have a crack at it! 👍

Thanks

@officialh1
Copy link

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

@marcus-j-davies
Copy link
Member

marcus-j-davies commented Mar 25, 2024

Hi, this issue is still open, as v4 has not yet been published.

it’s fixed in the v4 branch.
See the PR : #31

@marcus-j-davies marcus-j-davies linked a pull request May 1, 2024 that will close this issue
@marcus-j-davies
Copy link
Member

Closing...

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants