@@ -80,7 +80,7 @@ import { isUndefined } from "cypress/types/lodash";
8080interface IuiSlave {
8181 slave : Islave ;
8282 label : string ;
83- specsObservable ?: Observable < IidentificationSpecification [ ] > ;
83+ specs ?: IidentificationSpecification [ ] ;
8484 specification ?: Ispecification ;
8585 slaveForm : FormGroup ;
8686 commandEntities ?: ImodbusEntity [ ] ;
@@ -119,8 +119,7 @@ interface IuiSlave {
119119 MatExpansionPanelHeader ,
120120 MatExpansionPanelTitle ,
121121 MatInput ,
122- MatError ,
123- AsyncPipe ,
122+ MatError
124123 ] ,
125124} )
126125export class SelectSlaveComponent extends SessionStorage implements OnInit {
@@ -177,26 +176,14 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
177176 this . currentLanguage = getCurrentLanguage ( navigator . language ) ;
178177 this . entityApiService . getSpecifications ( ) . subscribe ( ( specs ) => {
179178 this . preparedSpecs = specs ;
180- specs . forEach ( ( spec ) => {
181- let name = getSpecificationI18nName ( spec , this . currentLanguage ) ;
182-
183- let entities : IidentEntity [ ] = spec . entities . map ( ( e ) => {
184- return {
185- id : e . id ,
186- name : e . name ,
187- readonly : e . readonly ,
188- mqttname : e . mqttname ,
189- } ;
190- } ) ;
191- if ( name == undefined ) name = "unknown" ;
192- } ) ;
193179 } ) ;
194180 this . paramsSubscription = this . route . params . subscribe ( ( params ) => {
195181 let busId = + params [ "busid" ] ;
196182 this . entityApiService . getBus ( busId ) . subscribe ( ( bus ) => {
197183 this . bus = bus ;
198184 if ( this . bus ) {
199185 this . busname = getConnectionName ( this . bus . connectionData ) ;
186+ this . getIdentSpecs ( undefined ) . then ( ( identSpecs ) => { this . preparedIdentSpecs = identSpecs } )
200187 this . updateSlaves ( ) ;
201188 }
202189 } ) ;
@@ -345,8 +332,8 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
345332 ) ;
346333 return rc
347334 }
348- getSpecsForConfiguredSlave ( uiSlave :IuiSlave ) : Observable < IidentificationSpecification [ ] > {
349- let rc = new Subject < IidentificationSpecification [ ] > ( )
335+ getIdentSpecs ( uiSlave :IuiSlave | undefined ) : Promise < IidentificationSpecification [ ] > {
336+ return new Promise < IidentificationSpecification [ ] > ( ( resolve , reject ) => {
350337 let fct = ( specModbus :ImodbusSpecification | undefined ) => {
351338 let rci :IidentificationSpecification [ ] = [ ]
352339 this . preparedSpecs . forEach ( spec => {
@@ -356,15 +343,14 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
356343 identified : specModbus && spec . filename == specModbus . filename ?specModbus . identified :IdentifiedStates . unknown ,
357344 filename : spec . filename ,
358345 } as IidentificationSpecification ) ;
359- rc . next ( rci )
360346 } )
347+ resolve ( rci )
361348 }
362- if ( uiSlave . slave . specificationid )
349+ if ( uiSlave && uiSlave . slave . specificationid )
363350 this . entityApiService . getModbusSpecification ( this . bus . busId , uiSlave . slave . slaveid , uiSlave . slave . specificationid , true ) . subscribe ( fct )
364351 else
365352 fct ( undefined )
366-
367- return rc ;
353+ } )
368354 }
369355 getUiSlave ( slave : Islave , detectSpec : boolean | undefined ) : IuiSlave {
370356 let fg = this . initiateSlaveControl ( slave , null ) ;
@@ -373,8 +359,7 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
373359 label : this . getSlaveName ( slave ) ,
374360 slaveForm : fg ,
375361 } as any ;
376-
377- rc . specsObservable = this . getSpecsForConfiguredSlave ( rc ) // getDetectedSpecs is disabled, because of performance issues
362+ this . getIdentSpecs ( rc ) . then ( ( identSpecs ) => { rc . specs = identSpecs } ) . catch ( e => { console . log ( e . message ) } ) // getDetectedSpecs is disabled, because of performance issues
378363 this . addSpecificationToUiSlave ( rc ) ;
379364 ( rc . selectedEntitites = this . getSelectedEntites ( slave ) ) ,
380365 this . fillCommandTopics ( rc ) ;
@@ -592,10 +577,13 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
592577 // Initialization of the UI
593578 // replacing this.uiSlaves with newUiSlaves will initialize and show it
594579 // Now, the new value needs to be marked as touched to enable cancel and save.
595- let specCtrl = newUiSlave . slaveForm . get ( "specificationid" ) ;
580+ if ( detectSpec ) {
581+ let specCtrl = newUiSlave . slaveForm . get ( "specificationid" ) ;
582+
583+ if ( specCtrl && specCtrl . value != undefined )
584+ newUiSlave . slaveForm . markAllAsTouched ( ) ;
596585
597- if ( specCtrl && specCtrl . value != undefined )
598- newUiSlave . slaveForm . markAllAsTouched ( ) ;
586+ }
599587 } ) ;
600588 }
601589 private static form2SlaveSetValue ( uiSlave : IuiSlave , controlname : string ) {
0 commit comments