@@ -178,7 +178,8 @@ public byte EndPointCount
178178 /// <returns></returns>
179179 public EndPoint ? GetEndPoint ( byte ID )
180180 {
181- if ( ID >= endPoints . Count )
181+ ID -- ;
182+ if ( ID >= endPoints . Count || ID < 0 )
182183 return null ;
183184 return endPoints [ ID ] ;
184185 }
@@ -258,15 +259,15 @@ private async Task<SupervisionStatus> HandleReport(ReportMessage msg)
258259 {
259260 if ( msg . SourceEndpoint == 0 )
260261 {
261- if ( ! commandClasses . ContainsKey ( msg . CommandClass ) )
262+ if ( ! HasCommandClass ( msg . CommandClass ) )
262263 AddCommandClass ( msg . CommandClass , ( msg . SecurityLevel != SecurityKey . None ) ) ;
263264 return await commandClasses [ msg . CommandClass ] . ProcessMessage ( msg ) ;
264265 }
265266 else
266267 {
267268 EndPoint ? ep = GetEndPoint ( msg . SourceEndpoint ) ;
268269 if ( ep != null )
269- return await ep . HandleReport ( msg ) . ConfigureAwait ( false ) ;
270+ return await ep . HandleReport ( msg ) ;
270271 }
271272 return SupervisionStatus . NoSupport ;
272273 }
@@ -317,7 +318,8 @@ internal NodeJSON Serialize()
317318 NodeProtocolInfo = nodeInfo ,
318319 ID = ID ,
319320 CommandClasses = new CommandClassJson [ commandClasses . Count ] ,
320- Interviewed = Interviewed
321+ Interviewed = Interviewed ,
322+ EndPoints = new EndPointJson [ endPoints . Count ]
321323 } ;
322324 if ( controller . SecurityManager != null )
323325 {
@@ -334,11 +336,13 @@ internal NodeJSON Serialize()
334336 CommandClass cls = commandClasses . ElementAt ( i ) . Key ;
335337 json . CommandClasses [ i ] = new CommandClassJson
336338 {
337- CommandClass = commandClasses [ cls ] . CommandClass ,
339+ CommandClass = cls ,
338340 Version = commandClasses [ cls ] . Version ,
339341 Secure = commandClasses [ cls ] . Secure
340342 } ;
341343 }
344+ for ( int i = 0 ; i < endPoints . Count ; i ++ )
345+ json . EndPoints [ i ] = endPoints [ i ] . Serialize ( ) ;
342346 return json ;
343347 }
344348
@@ -348,6 +352,9 @@ internal void Deserialize(NodeJSON json)
348352 foreach ( CommandClassJson cc in json . CommandClasses )
349353 AddCommandClass ( cc . CommandClass , cc . Secure , cc . Version ) ;
350354
355+ foreach ( EndPointJson ep in json . EndPoints )
356+ endPoints . Add ( new EndPoint ( ep , this ) ) ;
357+
351358 if ( controller . SecurityManager != null )
352359 {
353360 foreach ( SecurityKey grantedKey in json . GrantedKeys )
@@ -394,7 +401,7 @@ private async Task Interview(bool newlyIncluded, SecurityManager.NetworkKey? key
394401 if ( ! newlyIncluded && key == null )
395402 {
396403 //We need to try keys one at a time
397- if ( commandClasses . ContainsKey ( CommandClass . Security0 ) )
404+ if ( HasCommandClass ( CommandClass . Security0 ) )
398405 {
399406 controller . SecurityManager . GrantKey ( ID , SecurityManager . RecordType . S0 ) ;
400407 Log . Information ( "Checking S0 Security" ) ;
@@ -426,7 +433,7 @@ private async Task Interview(bool newlyIncluded, SecurityManager.NetworkKey? key
426433 controller . SecurityManager . RevokeKey ( ID , SecurityManager . RecordType . S0 ) ;
427434 }
428435 }
429- if ( commandClasses . ContainsKey ( CommandClass . Security2 ) )
436+ if ( HasCommandClass ( CommandClass . Security2 ) )
430437 {
431438 controller . SecurityManager . GrantKey ( ID , SecurityManager . RecordType . S2UnAuth , controller . NetworkKeyS2UnAuth ) ;
432439 Log . Information ( "Checking S2 Unauth Security" ) ;
@@ -525,22 +532,25 @@ private async Task Interview(bool newlyIncluded, SecurityManager.NetworkKey? key
525532 else
526533 {
527534 //Whatever keys we have is what the device has
528- if ( key != null && key . Key == SecurityManager . RecordType . S0 && commandClasses . ContainsKey ( CommandClass . Security0 ) )
535+ if ( key != null && key . Key == SecurityManager . RecordType . S0 && HasCommandClass ( CommandClass . Security0 ) )
529536 await RequestS0 ( cancellationToken ) . ConfigureAwait ( false ) ;
530- else if ( key != null && commandClasses . ContainsKey ( CommandClass . Security2 ) )
537+ else if ( key != null && HasCommandClass ( CommandClass . Security2 ) )
531538 await RequestS2 ( cancellationToken ) . ConfigureAwait ( false ) ;
532539 }
533540 }
534- if ( this . commandClasses . ContainsKey ( CommandClass . MultiChannel ) )
541+ if ( HasCommandClass ( CommandClass . MultiChannel ) )
535542 {
536543 Log . Information ( "Requesting MultiChannel EndPoints" ) ;
537- EndPointReport epReport = await ( ( MultiChannel ) commandClasses [ CommandClass . MultiChannel ] ) . GetEndPoints ( cancellationToken ) ;
544+ EndPointReport epReport = await GetCommandClass < MultiChannel > ( ) ! . GetEndPoints ( cancellationToken ) ;
538545 for ( int i = 0 ; i < epReport . IndividualEndPoints ; i ++ )
539- endPoints . Add ( new EndPoint ( ( byte ) ( i + 1 ) , this ) ) ;
546+ {
547+ EndPointCapabilities caps = await GetCommandClass < MultiChannel > ( ) ! . GetCapabilities ( ( byte ) ( i + 1 ) , cancellationToken ) ;
548+ endPoints . Add ( new EndPoint ( ( byte ) ( i + 1 ) , this , caps . CommandClasses ) ) ;
549+ }
540550 }
541551
542552 Log . Information ( "Checking Command Class Versions" ) ;
543- if ( this . commandClasses . ContainsKey ( CommandClass . Version ) )
553+ if ( HasCommandClass ( CommandClass . Version ) )
544554 {
545555 CommandClasses . Version version = ( CommandClasses . Version ) commandClasses [ CommandClass . Version ] ;
546556 foreach ( CommandClassBase cc in commandClasses . Values )
@@ -557,6 +567,11 @@ private async Task Interview(bool newlyIncluded, SecurityManager.NetworkKey? key
557567 try
558568 {
559569 cc . Version = await version . GetCommandClassVersion ( cc . CommandClass , cts . Token ) ;
570+ foreach ( EndPoint ep in endPoints )
571+ {
572+ if ( HasCommandClass ( cc . CommandClass ) )
573+ ep . CommandClasses [ cc . CommandClass ] . Version = cc . Version ;
574+ }
560575 }
561576 catch ( OperationCanceledException oc )
562577 {
0 commit comments