Skip to content

Commit

Permalink
v1.1.0 (#7)
Browse files Browse the repository at this point in the history
* LGTM

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Remove, Replace Methods

* Update CHANGELOG.md

* Update CHANGELOG.md
  • Loading branch information
marcus-j-davies committed Dec 28, 2021
1 parent 43764f1 commit eab71a7
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 18 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## v1.1.0

- Versions
- ZWave JS Driver Version: 8.9.1
- ZWave JS Server Version: 1.14.0 (Schema Version 14)

- New Features
- Added **RemoveFailedNode** method
- Added **ReplaceFailedNode** method
- Added **inclusion aborted** event handler
- Added ability to override the schema on which to connect to a zwave-js-server instance.
This allows backwards compatibility with older server versions.

- Fixes
- Webclient instance is now correctly disposed, after downloading the PSI.
- Fixed platform detection logic
- Fixed throwing exception on server process exit.

## v1.0.0

- Versions
Expand Down
2 changes: 1 addition & 1 deletion PSI/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.1.0",
"name": "server",
"bin": "./server.js",
"dependencies": {
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ZWaveJS.NET


![Nuget](https://img.shields.io/static/v1?label=license&message=MIT&color=green)
![Nuget](https://img.shields.io/nuget/v/zwavejs.net)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/zwave-js/ZWaveJS.NET.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/zwave-js/ZWaveJS.NET/context:javascript)


ZWaveJS.NET is a class library developed in .NET Core 3.1, that exposes the zwave-js Driver in .NET, opening up the ability to use its runtime directly in .NET applications.

The library closely follows the structure of the zwave-js API.
Expand All @@ -18,7 +24,7 @@ Driver.Controller.Nodes.Get(4).GetEndpoint(2).InvokeCCAPI(int CommandClass, stri
The library can operate in 2 ways: Client or Self Hosted.

**Client**
The library will connect to an already running instance of [zwave-js-server](https://github.com/zwave-js/zwave-js-server). (Schema Version >= 14)
The library will connect to an already running instance of [zwave-js-server](https://github.com/zwave-js/zwave-js-server).

**Self Hosted**
The library will host its own zwave-js instance.
Expand Down Expand Up @@ -65,8 +71,8 @@ All releases will be published to nuget, so search for **ZWaveJS.NET** and insta
- [x] Heal Network
- [x] Heal Network Progress Event Subscription
- [x] Heal Node
- [ ] Remove Failed Node
- [ ] Replace Failed Node
- [x] Remove Failed Node
- [x] Replace Failed Node
- [ ] Smart Start

- [ ] Node
Expand Down
62 changes: 62 additions & 0 deletions Visual Studio Project/ZWaveJS.NET/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ internal Controller()

}


public delegate void InclusionAbortedEvent();
public event InclusionAbortedEvent InclusionAborted;
internal void Trigger_InclusionAborted()
{
InclusionAborted?.Invoke();
}

public delegate void HealNetworkProgressEvent(Dictionary<string,string> Progress);
public event HealNetworkProgressEvent HealNetworkProgress;
internal void Trigger_HealNetworkProgress(Dictionary<string, string> Progress)
Expand Down Expand Up @@ -81,6 +89,60 @@ internal void Trigger_NodeAdded(ZWaveNode Node)
NodeAdded?.Invoke(Node);
}

public Task<bool> ReplaceFailedNode(int NodeID, Enums.InclusionStrategy Strategy)
{
if (Strategy == Enums.InclusionStrategy.Default || Strategy == Enums.InclusionStrategy.Security_S2)
{
if (GrantSecurityClasses == null || ValidateDSK == null)
{
throw new InvalidOperationException("Events: Controller.GrantSecurityClasses and Controller.ValidateDSK need to be subscribed to.");
}
}

Guid ID = Guid.NewGuid();
TaskCompletionSource<bool> Result = new TaskCompletionSource<bool>();
Driver.Callbacks.Add(ID, (JO) =>
{
Result.SetResult(JO.Value<bool>("success"));
});

Dictionary<string, object> Options = new Dictionary<string, object>();
Options.Add("strategy", (int)Strategy);

Dictionary<string, object> Request = new Dictionary<string, object>();
Request.Add("messageId", ID);
Request.Add("command", Enums.Commands.ReplaceFailedNode);
Request.Add("nodeId", NodeID);
Request.Add("options", Options);

string RequestPL = Newtonsoft.Json.JsonConvert.SerializeObject(Request);
Driver.Client.Send(RequestPL);

return Result.Task;
}

public Task<bool> RemoveFailedNode(int NodeID)
{
Guid ID = Guid.NewGuid();
TaskCompletionSource<bool> Result = new TaskCompletionSource<bool>();

Driver.Callbacks.Add(ID, (JO) =>
{
Result.SetResult(true);
});

Dictionary<string, object> Request = new Dictionary<string, object>();

Request.Add("messageId", ID);
Request.Add("command", Enums.Commands.RemoveFailedNode);
Request.Add("nodeId", NodeID);

string RequestPL = Newtonsoft.Json.JsonConvert.SerializeObject(Request);
Driver.Client.Send(RequestPL);

return Result.Task;
}

public Task<bool> HealNode(int NodeID)
{
Guid ID = Guid.NewGuid();
Expand Down
18 changes: 14 additions & 4 deletions Visual Studio Project/ZWaveJS.NET/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Driver
internal static WebsocketClient Client;
internal static Dictionary<Guid, Action<JObject>> Callbacks;
private Dictionary<string, Action<JObject>> EventMap;
private const int SchemaVersionID = 14;
private static int SchemaVersionID = 14;
internal static CustomBooleanJsonConverter BoolConverter;

internal static bool Inited = false;
Expand Down Expand Up @@ -125,6 +125,11 @@ private void MapNodeEvents()

private void MapControllerEvents()
{
EventMap.Add("inclusion aborted", (JO) =>
{
this.Controller.Trigger_InclusionAborted();
});

EventMap.Add("inclusion started", (JO) =>
{
bool Secure = JO.SelectToken("event.secure").Value<bool>();
Expand Down Expand Up @@ -215,8 +220,13 @@ private void MapEvents()
}

// Client Mode
public Driver(Uri Server)
public Driver(Uri Server, int SchemaVersion = 0)
{
if(SchemaVersion > 0)
{
SchemaVersionID = SchemaVersion;
}

Callbacks = new Dictionary<Guid, Action<JObject>>();
MapEvents();
BoolConverter = new CustomBooleanJsonConverter();
Expand Down Expand Up @@ -244,9 +254,9 @@ public Driver(string SerialPort, ZWaveOptions Options)

Client.MessageReceived.Subscribe(ProcessMessage);
}
catch (Exception err)
catch
{
throw err;
throw;
}
}

Expand Down
2 changes: 2 additions & 0 deletions Visual Studio Project/ZWaveJS.NET/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ internal class Commands
public const string SetName = "node.set_name";
public const string SetLocation = "node.set_location";
public const string KeepNodeAwake = "node.set_keep_awake";
public const string RemoveFailedNode = "controller.remove_failed_node";
public const string ReplaceFailedNode = "controller.replace_failed_node";
}

public enum SecurityClass
Expand Down
18 changes: 9 additions & 9 deletions Visual Studio Project/ZWaveJS.NET/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ internal static Enums.Platform RunningPlatform()
switch (Environment.OSVersion.Platform)
{
case PlatformID.Unix:
if (Directory.Exists("/Applications")
& Directory.Exists("/System")
& Directory.Exists("/Users")
& Directory.Exists("/Volumes"))
if (Directory.Exists("/Applications") && Directory.Exists("/System") && Directory.Exists("/Users"))
return Enums.Platform.Mac;
else
return Enums.Platform.Linux;
Expand Down Expand Up @@ -51,12 +48,15 @@ public static Task<bool> DownloadPSI()
break;
}

WebClient WC = new WebClient();
WC.DownloadFileCompleted += (s, e) =>
using (WebClient WC = new WebClient())
{
Result.SetResult(true);
};
WC.DownloadFileAsync(new Uri(URI), "server.psi");
WC.DownloadFileCompleted += (s, e) =>
{
Result.SetResult(true);
};
WC.DownloadFileAsync(new Uri(URI), "server.psi");
}

}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Visual Studio Project/ZWaveJS.NET/ZWaveJS.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<Authors>Marcus Davies</Authors>
<Company>ZWave-JS</Company>
<Product>ZWaveJS.NET</Product>
Expand Down

0 comments on commit eab71a7

Please sign in to comment.