GithubHelp home page GithubHelp logo

zwave-js / zwavejs.net Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 5.0 51.66 MB

A Z-Wave JS wrapper for the .NET Framework. Supporting various targets, and providing a feature rich Z-Wave API.

License: MIT License

C# 99.32% JavaScript 0.68%
zwave zwave-js csharp dotnet core wrapper zwave-js-server netcore31 netstandard20 netstandard21

zwavejs.net's Issues

Event handlers block processing of new events

When the library calls an event handler, it blocks the processing of new events received from Z-Wave JS Server until the event handler returns.
So if what is implemented in the event handler is time consuming it can cause big delays in the whole application.
Moreover if the event handler itself synchronously calls another ZWave JS .NET method which expects a response from the Z-Wave JS server it creates a deadlock.

To workaround this issue all my event handlers look like this:

private void ExclusionStartedEventHandler()
  {
      //need a Task.Run here because event processing in ZWaveJS.NET is delayed by any event handler
      Task.Run(() =>
      {
....
      });
  }

I don't mind to keep doing this, but I wonder if there is any case where we actually want this blocking behavior?

Access to homeID

When a client connects to the ZWave JS server, the first message it receives includes the homeID that identify the ZWave network.
https://github.com/zwave-js/zwave-js-server#api

Could we add access to this value in version 4?
Or is there any other way to get this value using the ZWaveJS.NET lib?

Thanks

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:

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 ?

Controller Node is filtered out of the Nodes collection

Why does the library filters out the controller node from the Controller.Nodes collection?

Nodes = Nodes.Where((N) => !N.isControllerNode).ToArray();

The ZWaveNode class includes some useful information like ZWaveNode.deviceConfig.label, ZWaveNode.deviceConfig.manufacturer, that we may want to have access to for the controller node.

Logging config not settable

Implemented V3 and it looks great!!!! I needed to rework my app to handle mapping of CMDResults to models my app required, but otherwise, working great! Thank-you and well-done!!!!!!

I did notice that the Options.logConfig property is readonly (with a private setter only), so it's not possible to adjust the logging behavior. Not sure if you intended that to be for your own use or generally available. Either way, I thought I would point it out.

Thanks again for your great work!

VirtualNode.GetDefinedValueIDs() throws a null reference exception (4.0.0 branch)

Looks like there might be a small mistake in the path for the JO.SelectToken call in the following code:

Driver.Instance.Callbacks.Add(ID, (JO) =>
 {
     CMDResult Res = new CMDResult(JO);
     if (Res.Success)
     {
         Res.SetPayload(JO.SelectToken("result.valueIds").ToObject<ValueID[]>());
     }

     Result.SetResult(Res);
 });

The JSON in the response has "valueIDs" versus the "valueIds" being used in the path.

No error or exception when websocket client fails to connect in client mode

I'm using the ZWaveJS.NET library in client mode, i.e I use some code similar to the example below to connect to an already running ZWave JS server.
If the ZWaveJS Server is not running, I would expect the StartUpError event to be raised but it isn't, and no exception is thrown either. Is there a way to detect that connection has failed?

I'm testing with the 4.0.0 branch, but I think there is the same problem with the main branch.

internal class Program
 {
     static Driver _driver;
     static int schemaVersion = 17;
     static string zWaveJSServerUrl = "ws://localhost:3000";

     static void Main(string[] args)
     {
         try
         {
             _driver = new Driver(new Uri(zWaveJSServerUrl), schemaVersion);
             _driver.DriverReady += Driver_DriverReady;
             _driver.StartUpError += Driver_StartupErrorEvent;
             _driver.Start();

             Console.WriteLine("press enter to stop");
             Console.ReadKey();
         }
         catch(Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }

     static private void Driver_StartupErrorEvent(string message)
     {
         Console.WriteLine(message);
     }

     static private void Driver_DriverReady()
     {
         Console.WriteLine("Driver ready");
     }
}

Method calls for asleep nodes never return

If, for example, the RefreshValues() or SetValue() methods are called for a node that is asleep, the method never return (unless the node wakes up)
Shouldn't there be some sort of timeout in order to guarantee that the method will return within a certain time?

Can't create a second Driver after destroying the first one

After calling driver.Destroy() I would expect to be able to create and start a new driver instance.

Instead the DriverReady event is never fired, and I can see this is because the Controller property is never set.

Not sure if something needs to be updated, so that the driver and be re-created and started again.

RefreshValues does not return any error when node is dead.

If the following code is called for a dead node
CMDResult result = await node.RefreshValues();
the result.Success value is always true

other methods like SetValue() correctly return false for result.Success with a message saying "The message cannot be sent because node 53 is dead (ZW0202)"

Looks like the problem is probably more in ZWave JS Server or node-zwave-js, but I wanted to check here first to know what you think.

Driver.Destroy() throws an exception if Driver.Controller is not initialized

If Driver.Destroy() is called for a Driver instance that has not been successfully initialized for example, it throws an exception at

Controller.Nodes = null;

because Controller is null.
it is easily fixable by checking if Controller is null

if (Controller != null)
{
    Controller.Nodes = null;
    Controller = null;
}

but I wonder what is the benefit of setting Controller.Nodes to null at all, since Controller itself is set to null on the next line?

Stack overflow exception in Websocket.Client library

I get a stack overflow crash in our program by doing this:

  1. create a ZWaveJS.NET driver and connect it to an external ZWave JS Server
  2. stop the ZWave JS server and let the ZWaveJS.NET driver goes into reconnection mode.
  3. wait about 10 minutes to trigger hundreds of reconnection attempts
  4. call driver.Destroy()

=> a StackOverflowException occurs in ClientWebSocket.Dispose()

It is 100% reproducible in our program, but I wasn't able to reproduce it with a simple console program, so I must be missing something there.

Anyway, I have traced down the problem to be related to this issue in the Websocket.Client library: Marfusios/websocket-client#124
While debugging in VS, if you "break all" while waiting in step 3 from above, you can see the hundred of recursive calls in the task used for reconnection.
A fix for this problem has been implemented in recent version of the Websocket.Client library, but unfortunately this version has dropped support for netstandard2.0 , so we cannot directly update the library from nuget unless netstandard2.0 is dropped in ZWaveJS.NET as well, which is out of question for us because our program still use .NET Framework.

So I'm not sure how to best fix this issue?
For now, I pulled the source code for Websocket.Client version 4.6.1 (the version currently used by ZwaveJS.NET) and I manually merged the fix for the recursive call problem: Marfusios/websocket-client@df2e007
I successfully tested that it fixes my stack overflow problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.