@@ -21,6 +21,7 @@ public class Driver
2121
2222 private Dictionary < string , Action < JObject > > NodeEventMap ;
2323 private Dictionary < string , Action < JObject > > ControllerEventMap ;
24+ private Dictionary < string , Action < JObject > > DriverEventMap ;
2425 private static int SchemaVersionID = 17 ;
2526 private string SerialPort ;
2627
@@ -52,6 +53,13 @@ public string ZWaveJSServerVersion
5253 public delegate void StartupError ( string Message ) ;
5354 public event StartupError StartupErrorEvent ;
5455
56+ public delegate void LoggingEventDelegate ( LoggingEventArgs args ) ;
57+ public event LoggingEventDelegate LoggingEvent ;
58+ internal void Trigger_LoggingEvent ( LoggingEventArgs args )
59+ {
60+ LoggingEvent ? . Invoke ( args ) ;
61+ }
62+
5563 private void MapNodeEvents ( )
5664 {
5765 NodeEventMap . Add ( "check lifeline health progress" , ( JO ) =>
@@ -303,13 +311,36 @@ private void MapControllerEvents()
303311 } ) ;
304312 }
305313
314+ private void MapDriverEvents ( )
315+ {
316+ DriverEventMap . Add ( "logging" , ( JO ) =>
317+ {
318+ LoggingEventArgs args = new LoggingEventArgs ( ) ;
319+ args . formattedMessage = JO . SelectToken ( "event.formattedMessage" ) ? . Value < string > ( ) ;
320+ args . direction = JO . SelectToken ( "event.direction" ) ? . Value < string > ( ) ;
321+ args . primaryTags = JO . SelectToken ( "event.primaryTags" ) ? . Value < string > ( ) ;
322+ args . secondaryTags = JO . SelectToken ( "event.secondaryTags" ) ? . Value < string > ( ) ;
323+ args . secondaryTagPadding = JO . SelectToken ( "event.secondaryTagPadding" ) ? . Value < int > ( ) ;
324+ args . multiline = JO . SelectToken ( "event.multiline" ) ? . Value < bool > ( ) ;
325+ args . timestamp = JO . SelectToken ( "event.timestamp" ) ? . Value < string > ( ) ;
326+ args . label = JO . SelectToken ( "event.label" ) ? . Value < string > ( ) ;
327+ args . message = JO . SelectToken ( "event.message" ) ? . Value < string > ( ) ;
328+ args . level = JO . SelectToken ( "event.level" ) ? . Value < string > ( ) ;
329+
330+ Trigger_LoggingEvent ( args ) ;
331+ } ) ;
332+ }
333+
306334 private void MapEvents ( )
307335 {
308336 NodeEventMap = new Dictionary < string , Action < JObject > > ( ) ;
309337 MapNodeEvents ( ) ;
310338
311339 ControllerEventMap = new Dictionary < string , Action < JObject > > ( ) ;
312340 MapControllerEvents ( ) ;
341+
342+ DriverEventMap = new Dictionary < string , Action < JObject > > ( ) ;
343+ MapDriverEvents ( ) ;
313344 }
314345
315346
@@ -429,6 +460,13 @@ private void WebsocketClient_MessageReceived(object sender, WatsonWebsocket.Mess
429460 }
430461 break ;
431462
463+ case "driver" :
464+ if ( DriverEventMap . ContainsKey ( _Event ) )
465+ {
466+ DriverEventMap [ _Event ] . Invoke ( JO ) ;
467+ }
468+ break ;
469+
432470 }
433471 return ;
434472 }
@@ -572,5 +610,51 @@ private void StartListetningCB(JObject JO)
572610 }
573611 }
574612 }
613+
614+ public Task < CMDResult > StartListeningLogs ( )
615+ {
616+ Guid ID = Guid . NewGuid ( ) ;
617+
618+ TaskCompletionSource < CMDResult > Result = new TaskCompletionSource < CMDResult > ( ) ;
619+
620+ Callbacks . Add ( ID , ( JO ) =>
621+ {
622+ CMDResult Res = new CMDResult ( JO ) ;
623+ Result . SetResult ( Res ) ;
624+ } ) ;
625+
626+ Dictionary < string , object > Request = new Dictionary < string , object > ( ) ;
627+
628+ Request . Add ( "messageId" , ID ) ;
629+ Request . Add ( "command" , Enums . Commands . StartListeningLogs ) ;
630+
631+ string RequestPL = Newtonsoft . Json . JsonConvert . SerializeObject ( Request ) ;
632+ Client . SendAsync ( RequestPL ) ;
633+
634+ return Result . Task ;
635+ }
636+
637+ public Task < CMDResult > StopListeningLogs ( )
638+ {
639+ Guid ID = Guid . NewGuid ( ) ;
640+
641+ TaskCompletionSource < CMDResult > Result = new TaskCompletionSource < CMDResult > ( ) ;
642+
643+ Callbacks . Add ( ID , ( JO ) =>
644+ {
645+ CMDResult Res = new CMDResult ( JO ) ;
646+ Result . SetResult ( Res ) ;
647+ } ) ;
648+
649+ Dictionary < string , object > Request = new Dictionary < string , object > ( ) ;
650+
651+ Request . Add ( "messageId" , ID ) ;
652+ Request . Add ( "command" , Enums . Commands . StopListeningLogs ) ;
653+
654+ string RequestPL = Newtonsoft . Json . JsonConvert . SerializeObject ( Request ) ;
655+ Client . SendAsync ( RequestPL ) ;
656+
657+ return Result . Task ;
658+ }
575659 }
576660}
0 commit comments