@@ -38,13 +38,13 @@ export class NodeBindingDialog extends LitElement {
3838 @property ( { attribute : false } )
3939 endpoint ! : number ;
4040
41- @query ( "md-outlined-text-field[label='node id ']" )
41+ @query ( "md-outlined-text-field[name='NodeId ']" )
4242 private _targetNodeId ! : MdOutlinedTextField ;
4343
44- @query ( "md-outlined-text-field[label='endpoint ']" )
44+ @query ( "md-outlined-text-field[name='Endpoint ']" )
4545 private _targetEndpoint ! : MdOutlinedTextField ;
4646
47- @query ( "md-outlined-text-field[label='cluster ']" )
47+ @query ( "md-outlined-text-field[name='Cluster ']" )
4848 private _targetCluster ! : MdOutlinedTextField ;
4949
5050 private fetchBindingEntry ( ) : BindingEntryStruct [ ] {
@@ -201,21 +201,42 @@ export class NodeBindingDialog extends LitElement {
201201 }
202202
203203 async addBindingHandler ( ) {
204- const targetNodeId = parseInt ( this . _targetNodeId . value , 10 ) ;
205- const targetEndpoint = parseInt ( this . _targetEndpoint . value , 10 ) ;
206- const targetCluster = parseInt ( this . _targetCluster . value , 10 ) ;
207-
208- if ( isNaN ( targetNodeId ) || targetNodeId <= 0 ) {
204+ const targetNodeId = this . _targetNodeId . value
205+ ? parseInt ( this . _targetNodeId . value , 10 )
206+ : undefined ;
207+ const targetEndpoint = this . _targetEndpoint . value
208+ ? parseInt ( this . _targetEndpoint . value , 10 )
209+ : undefined ;
210+ const targetCluster = this . _targetCluster . value
211+ ? parseInt ( this . _targetCluster . value , 10 )
212+ : undefined ;
213+
214+ // Matter Server does not use random NodeIds, so this is ok for now, but needs to be adjusted later
215+ if (
216+ targetNodeId === undefined ||
217+ targetNodeId <= 0 ||
218+ targetNodeId > 65535
219+ ) {
209220 alert ( "Please enter a valid target node ID" ) ;
210221 return ;
211222 }
212- if ( isNaN ( targetEndpoint ) || targetEndpoint < 0 ) {
223+
224+ if (
225+ targetEndpoint === undefined ||
226+ targetEndpoint <= 0 ||
227+ targetEndpoint > 0xfffe
228+ ) {
213229 alert ( "Please enter a valid target endpoint" ) ;
214230 return ;
215231 }
216- if ( isNaN ( targetCluster ) || targetCluster < 0 ) {
217- alert ( "Please enter a valid target cluster" ) ;
218- return ;
232+
233+ // cluster optional
234+ if ( targetCluster !== undefined ) {
235+ // We ignore vendor specific clusters for now
236+ if ( targetCluster < 0 || targetCluster > 0x7fff ) {
237+ alert ( "Please enter a valid target cluster" ) ;
238+ return ;
239+ }
219240 }
220241
221242 const targets : AccessControlTargetStruct = {
@@ -231,6 +252,7 @@ export class NodeBindingDialog extends LitElement {
231252 targets : [ targets ] ,
232253 fabricIndex : this . client . connection . serverInfo ! . fabric_id ,
233254 } ;
255+
234256 const result_acl = await this . add_target_acl ( targetNodeId , acl_entry ) ;
235257 if ( ! result_acl ) {
236258 alert ( "add target acl error!" ) ;
@@ -264,6 +286,23 @@ export class NodeBindingDialog extends LitElement {
264286 this . parentNode ! . removeChild ( this ) ;
265287 }
266288
289+ private onChange ( e : Event ) {
290+ const textfield = e . target as MdOutlinedTextField ;
291+ const value = parseInt ( textfield . value , 10 ) ;
292+
293+ if (
294+ parseInt ( textfield . max , 10 ) < value ||
295+ value < parseInt ( textfield . min , 10 )
296+ ) {
297+ textfield . error = true ;
298+ textfield . errorText = "value error" ;
299+ } else {
300+ textfield . error = false ;
301+ }
302+
303+ // console.log(`value: ${value} error: ${textfield.error}`);
304+ }
305+
267306 protected render ( ) {
268307 const bindings = Object . values (
269308 this . node ! . attributes [ this . endpoint + "/30/0" ] ,
@@ -296,18 +335,50 @@ export class NodeBindingDialog extends LitElement {
296335 </ md- lis t>
297336 <div class= "inline-group" >
298337 <div class= "group-label" > target </ div>
299- <md- outlined- text- field
300- label= "node id"
301- class = "target- item"
302- > </ md- outlined- text- field>
303- <md- outlined- text- field
304- label= "endpoint"
305- class = "target- item"
306- > </ md- outlined- text- field>
307- <md- outlined- text- field
308- label= "cluster"
309- class = "target- item"
310- > </ md- outlined- text- field>
338+ <div class= "group-input" >
339+ <md- outlined- text- field
340+ label= "node id"
341+ name = "NodeId"
342+ type= "number"
343+ min= "0"
344+ max= "65535"
345+ class= "target- item"
346+ @change = ${ this . onChange }
347+ suppor ting- text= "required"
348+ > </ md- outlined- text- field>
349+ <md- outlined- text- field
350+ label= "endpoint"
351+ name = "Endpoint"
352+ type= "number"
353+ min= "0"
354+ max= "65534"
355+ @change = ${ this . onChange }
356+ class= "target- item"
357+ suppor ting- text= "required"
358+ > </ md- outlined- text- field>
359+ <md- outlined- text- field
360+ label= "cluster"
361+ name = "Cluster"
362+ type= "number"
363+ min= "0"
364+ max= "32767"
365+ @change = ${ this . onChange }
366+ class= "target- item"
367+ suppor ting- text= "optional"
368+ > </ md- outlined- text- field>
369+ </ div>
370+ </ div>
371+ <div style= "margin:8px;" >
372+ <Text
373+ style= "font-size: 10px;font-style: italic;font-weight: bold;"
374+ >
375+ Note : The Cluster ID field is optional according to the Matter
376+ specification . If you leave it blank , the binding applies to all
377+ eligible clusters on the target endpoint . However , some devices
378+ may require a specific cluster to be set in order for the
379+ binding to function correctly . If you experience unexpected
380+ behavior , try specifying the cluster explicitly .
381+ </ Text>
311382 </ div>
312383 </ div>
313384 </ div>
@@ -329,13 +400,19 @@ export class NodeBindingDialog extends LitElement {
329400 margin : 8px ;
330401 }
331402
403+ .group-input {
404+ display : flex;
405+ width : -webkit-fill-available;
406+ }
407+
332408 .target-item {
333409 display : inline-block;
334410 padding : 20px 10px 10px 10px ;
335411 border-radius : 4px ;
336412 vertical-align : middle;
337413 min-width : 80px ;
338414 text-align : center;
415+ width : -webkit-fill-available;
339416 }
340417
341418 .group-label {
0 commit comments