Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions Visual Studio Projects/ZWaveJS.NET/ZWaveJS.NET/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Driver

private Dictionary<string, Action<JObject>> NodeEventMap;
private Dictionary<string, Action<JObject>> ControllerEventMap;
private Dictionary<string, Action<JObject>> DriverEventMap;
private static int SchemaVersionID = 17;
private string SerialPort;

Expand Down Expand Up @@ -52,6 +53,13 @@ public string ZWaveJSServerVersion
public delegate void StartupError(string Message);
public event StartupError StartupErrorEvent;

public delegate void LoggingEventDelegate(LoggingEventArgs args);
public event LoggingEventDelegate LoggingEvent;
internal void Trigger_LoggingEvent(LoggingEventArgs args)
{
LoggingEvent?.Invoke(args);
}

private void MapNodeEvents()
{
NodeEventMap.Add("check lifeline health progress", (JO) =>
Expand Down Expand Up @@ -303,13 +311,36 @@ private void MapControllerEvents()
});
}

private void MapDriverEvents()
{
DriverEventMap.Add("logging", (JO) =>
{
LoggingEventArgs args = new LoggingEventArgs();
args.formattedMessage = JO.SelectToken("event.formattedMessage")?.Value<string>();
args.direction = JO.SelectToken("event.direction")?.Value<string>();
args.primaryTags = JO.SelectToken("event.primaryTags")?.Value<string>();
args.secondaryTags = JO.SelectToken("event.secondaryTags")?.Value<string>();
args.secondaryTagPadding = JO.SelectToken("event.secondaryTagPadding")?.Value<int>();
args.multiline = JO.SelectToken("event.multiline")?.Value<bool>();
args.timestamp = JO.SelectToken("event.timestamp")?.Value<string>();
args.label = JO.SelectToken("event.label")?.Value<string>();
args.message = JO.SelectToken("event.message")?.Value<string>();
args.level = JO.SelectToken("event.level")?.Value<string>();

Trigger_LoggingEvent(args);
});
}

private void MapEvents()
{
NodeEventMap = new Dictionary<string, Action<JObject>>();
MapNodeEvents();

ControllerEventMap = new Dictionary<string, Action<JObject>>();
MapControllerEvents();

DriverEventMap = new Dictionary<string, Action<JObject>>();
MapDriverEvents();
}


Expand Down Expand Up @@ -429,6 +460,13 @@ private void WebsocketClient_MessageReceived(object sender, WatsonWebsocket.Mess
}
break;

case "driver":
if (DriverEventMap.ContainsKey(_Event))
{
DriverEventMap[_Event].Invoke(JO);
}
break;

}
return;
}
Expand Down Expand Up @@ -572,5 +610,51 @@ private void StartListetningCB(JObject JO)
}
}
}

public Task<CMDResult> StartListeningLogs()
{
Guid ID = Guid.NewGuid();

TaskCompletionSource<CMDResult> Result = new TaskCompletionSource<CMDResult>();

Callbacks.Add(ID, (JO) =>
{
CMDResult Res = new CMDResult(JO);
Result.SetResult(Res);
});

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

Request.Add("messageId", ID);
Request.Add("command", Enums.Commands.StartListeningLogs);

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

return Result.Task;
}

public Task<CMDResult> StopListeningLogs()
{
Guid ID = Guid.NewGuid();

TaskCompletionSource<CMDResult> Result = new TaskCompletionSource<CMDResult>();

Callbacks.Add(ID, (JO) =>
{
CMDResult Res = new CMDResult(JO);
Result.SetResult(Res);
});

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

Request.Add("messageId", ID);
Request.Add("command", Enums.Commands.StopListeningLogs);

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

return Result.Task;
}
}
}
2 changes: 2 additions & 0 deletions Visual Studio Projects/ZWaveJS.NET/ZWaveJS.NET/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ internal class Commands
public const string MCGetDefinedValueIDs = "multicast_group.get_defined_value_ids";
public const string MCSupportsCCAPI = "multicast_group.supports_cc_api";
public const string MCInvokeCCAPI = "multicast_group.invoke_cc_api";
public const string StartListeningLogs = "driver.start_listening_logs";
public const string StopListeningLogs = "driver.stop_listening_logs";
}

public enum SecurityClass
Expand Down
14 changes: 14 additions & 0 deletions Visual Studio Projects/ZWaveJS.NET/ZWaveJS.NET/Structures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,18 @@ public class InclusionUserCallbacks
public GrantSecurityClasses grantSecurityClasses { get; set; }
public Abort abort { get; set; }
}

public class LoggingEventArgs
{
public string formattedMessage { get; set; }
public string direction { get; set; }
public string primaryTags { get; set; }
public string secondaryTags { get; set; }
public int? secondaryTagPadding { get; set; }
public bool? multiline { get; set; }
public string timestamp { get; set; }
public string label { get; set; }
public string message { get; set; }
public string level { get; set; }
}
}