Skip to content

Commit eab71a7

Browse files
v1.1.0 (#7)
* LGTM * Update README.md * Update README.md * Update README.md * Update README.md * Remove, Replace Methods * Update CHANGELOG.md * Update CHANGELOG.md
1 parent 43764f1 commit eab71a7

File tree

8 files changed

+116
-18
lines changed

8 files changed

+116
-18
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## v1.1.0
2+
3+
- Versions
4+
- ZWave JS Driver Version: 8.9.1
5+
- ZWave JS Server Version: 1.14.0 (Schema Version 14)
6+
7+
- New Features
8+
- Added **RemoveFailedNode** method
9+
- Added **ReplaceFailedNode** method
10+
- Added **inclusion aborted** event handler
11+
- Added ability to override the schema on which to connect to a zwave-js-server instance.
12+
This allows backwards compatibility with older server versions.
13+
14+
- Fixes
15+
- Webclient instance is now correctly disposed, after downloading the PSI.
16+
- Fixed platform detection logic
17+
- Fixed throwing exception on server process exit.
18+
119
## v1.0.0
220

321
- Versions

PSI/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.0",
2+
"version": "1.1.0",
33
"name": "server",
44
"bin": "./server.js",
55
"dependencies": {

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ZWaveJS.NET
22

3+
4+
![Nuget](https://img.shields.io/static/v1?label=license&message=MIT&color=green)
5+
![Nuget](https://img.shields.io/nuget/v/zwavejs.net)
6+
[![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)
7+
8+
39
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.
410

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

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

2329
**Self Hosted**
2430
The library will host its own zwave-js instance.
@@ -65,8 +71,8 @@ All releases will be published to nuget, so search for **ZWaveJS.NET** and insta
6571
- [x] Heal Network
6672
- [x] Heal Network Progress Event Subscription
6773
- [x] Heal Node
68-
- [ ] Remove Failed Node
69-
- [ ] Replace Failed Node
74+
- [x] Remove Failed Node
75+
- [x] Replace Failed Node
7076
- [ ] Smart Start
7177

7278
- [ ] Node

Visual Studio Project/ZWaveJS.NET/Controller.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ internal Controller()
1010

1111
}
1212

13+
14+
public delegate void InclusionAbortedEvent();
15+
public event InclusionAbortedEvent InclusionAborted;
16+
internal void Trigger_InclusionAborted()
17+
{
18+
InclusionAborted?.Invoke();
19+
}
20+
1321
public delegate void HealNetworkProgressEvent(Dictionary<string,string> Progress);
1422
public event HealNetworkProgressEvent HealNetworkProgress;
1523
internal void Trigger_HealNetworkProgress(Dictionary<string, string> Progress)
@@ -81,6 +89,60 @@ internal void Trigger_NodeAdded(ZWaveNode Node)
8189
NodeAdded?.Invoke(Node);
8290
}
8391

92+
public Task<bool> ReplaceFailedNode(int NodeID, Enums.InclusionStrategy Strategy)
93+
{
94+
if (Strategy == Enums.InclusionStrategy.Default || Strategy == Enums.InclusionStrategy.Security_S2)
95+
{
96+
if (GrantSecurityClasses == null || ValidateDSK == null)
97+
{
98+
throw new InvalidOperationException("Events: Controller.GrantSecurityClasses and Controller.ValidateDSK need to be subscribed to.");
99+
}
100+
}
101+
102+
Guid ID = Guid.NewGuid();
103+
TaskCompletionSource<bool> Result = new TaskCompletionSource<bool>();
104+
Driver.Callbacks.Add(ID, (JO) =>
105+
{
106+
Result.SetResult(JO.Value<bool>("success"));
107+
});
108+
109+
Dictionary<string, object> Options = new Dictionary<string, object>();
110+
Options.Add("strategy", (int)Strategy);
111+
112+
Dictionary<string, object> Request = new Dictionary<string, object>();
113+
Request.Add("messageId", ID);
114+
Request.Add("command", Enums.Commands.ReplaceFailedNode);
115+
Request.Add("nodeId", NodeID);
116+
Request.Add("options", Options);
117+
118+
string RequestPL = Newtonsoft.Json.JsonConvert.SerializeObject(Request);
119+
Driver.Client.Send(RequestPL);
120+
121+
return Result.Task;
122+
}
123+
124+
public Task<bool> RemoveFailedNode(int NodeID)
125+
{
126+
Guid ID = Guid.NewGuid();
127+
TaskCompletionSource<bool> Result = new TaskCompletionSource<bool>();
128+
129+
Driver.Callbacks.Add(ID, (JO) =>
130+
{
131+
Result.SetResult(true);
132+
});
133+
134+
Dictionary<string, object> Request = new Dictionary<string, object>();
135+
136+
Request.Add("messageId", ID);
137+
Request.Add("command", Enums.Commands.RemoveFailedNode);
138+
Request.Add("nodeId", NodeID);
139+
140+
string RequestPL = Newtonsoft.Json.JsonConvert.SerializeObject(Request);
141+
Driver.Client.Send(RequestPL);
142+
143+
return Result.Task;
144+
}
145+
84146
public Task<bool> HealNode(int NodeID)
85147
{
86148
Guid ID = Guid.NewGuid();

Visual Studio Project/ZWaveJS.NET/Driver.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Driver
1313
internal static WebsocketClient Client;
1414
internal static Dictionary<Guid, Action<JObject>> Callbacks;
1515
private Dictionary<string, Action<JObject>> EventMap;
16-
private const int SchemaVersionID = 14;
16+
private static int SchemaVersionID = 14;
1717
internal static CustomBooleanJsonConverter BoolConverter;
1818

1919
internal static bool Inited = false;
@@ -125,6 +125,11 @@ private void MapNodeEvents()
125125

126126
private void MapControllerEvents()
127127
{
128+
EventMap.Add("inclusion aborted", (JO) =>
129+
{
130+
this.Controller.Trigger_InclusionAborted();
131+
});
132+
128133
EventMap.Add("inclusion started", (JO) =>
129134
{
130135
bool Secure = JO.SelectToken("event.secure").Value<bool>();
@@ -215,8 +220,13 @@ private void MapEvents()
215220
}
216221

217222
// Client Mode
218-
public Driver(Uri Server)
223+
public Driver(Uri Server, int SchemaVersion = 0)
219224
{
225+
if(SchemaVersion > 0)
226+
{
227+
SchemaVersionID = SchemaVersion;
228+
}
229+
220230
Callbacks = new Dictionary<Guid, Action<JObject>>();
221231
MapEvents();
222232
BoolConverter = new CustomBooleanJsonConverter();
@@ -244,9 +254,9 @@ public Driver(string SerialPort, ZWaveOptions Options)
244254

245255
Client.MessageReceived.Subscribe(ProcessMessage);
246256
}
247-
catch (Exception err)
257+
catch
248258
{
249-
throw err;
259+
throw;
250260
}
251261
}
252262

Visual Studio Project/ZWaveJS.NET/Enums.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ internal class Commands
3636
public const string SetName = "node.set_name";
3737
public const string SetLocation = "node.set_location";
3838
public const string KeepNodeAwake = "node.set_keep_awake";
39+
public const string RemoveFailedNode = "controller.remove_failed_node";
40+
public const string ReplaceFailedNode = "controller.replace_failed_node";
3941
}
4042

4143
public enum SecurityClass

Visual Studio Project/ZWaveJS.NET/Helpers.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ internal static Enums.Platform RunningPlatform()
1818
switch (Environment.OSVersion.Platform)
1919
{
2020
case PlatformID.Unix:
21-
if (Directory.Exists("/Applications")
22-
& Directory.Exists("/System")
23-
& Directory.Exists("/Users")
24-
& Directory.Exists("/Volumes"))
21+
if (Directory.Exists("/Applications") && Directory.Exists("/System") && Directory.Exists("/Users"))
2522
return Enums.Platform.Mac;
2623
else
2724
return Enums.Platform.Linux;
@@ -51,12 +48,15 @@ public static Task<bool> DownloadPSI()
5148
break;
5249
}
5350

54-
WebClient WC = new WebClient();
55-
WC.DownloadFileCompleted += (s, e) =>
51+
using (WebClient WC = new WebClient())
5652
{
57-
Result.SetResult(true);
58-
};
59-
WC.DownloadFileAsync(new Uri(URI), "server.psi");
53+
WC.DownloadFileCompleted += (s, e) =>
54+
{
55+
Result.SetResult(true);
56+
};
57+
WC.DownloadFileAsync(new Uri(URI), "server.psi");
58+
}
59+
6060
}
6161
else
6262
{

Visual Studio Project/ZWaveJS.NET/ZWaveJS.NET.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
<Version>1.0.0</Version>
5+
<Version>1.1.0</Version>
66
<Authors>Marcus Davies</Authors>
77
<Company>ZWave-JS</Company>
88
<Product>ZWaveJS.NET</Product>

0 commit comments

Comments
 (0)