@@ -52,42 +52,52 @@ export const ApiProvider: FC<PropsWithChildren<unknown>> = ({ children }) => {
5252 console . log ( 'new Api' ) ;
5353
5454 useEffect ( ( ) => {
55- dispatch ( setTriedToConnect ( { triedToConnect : false } ) ) ;
55+ if ( configIndex === null ) {
56+ console . log ( 'ApiProvider - configIndex is null' ) ;
5657
57- if ( currentConfiguration && configIndex !== null ) {
58+ return ;
59+ }
60+
61+ dispatch ( setTriedToConnect ( { triedToConnect : false , index : configIndex } ) ) ;
62+
63+ if ( currentConfiguration ) {
5864 console . info (
5965 'Initializing API Handler' ,
6066 currentConfiguration ,
6167 configIndex ,
6268 ) ;
6369
6470 api . registerOnDisconnectedHandler ( ( ) => {
65- dispatch ( clearOpenDtuState ( ) ) ;
71+ dispatch ( clearOpenDtuState ( { index : configIndex } ) ) ;
6672 } ) ;
6773
6874 api . disconnect ( ) ;
6975
7076 api . setConfig ( currentConfiguration , configIndex ) ;
7177
7278 api . registerOnConnectedHandler ( index => {
73- dispatch ( setIsConnected ( { isConnected : true } ) ) ;
79+ dispatch ( setIsConnected ( { isConnected : true , index : configIndex } ) ) ;
7480 dispatch ( setDeviceState ( { deviceState : DeviceState . Connected , index } ) ) ;
7581 } ) ;
7682
7783 api . registerOnDisconnectedHandler ( ( ) => {
78- dispatch ( setIsConnected ( { isConnected : false } ) ) ;
84+ dispatch ( setIsConnected ( { isConnected : false , index : configIndex } ) ) ;
7985 } ) ;
8086
8187 api . registerLiveDataHandler ( ( data , valid , index ) => {
82- dispatch ( setTriedToConnect ( { triedToConnect : true } ) ) ;
83- dispatch ( setLiveData ( { data, valid } ) ) ;
88+ dispatch (
89+ setTriedToConnect ( { triedToConnect : true , index : configIndex } ) ,
90+ ) ;
91+ dispatch ( setLiveData ( { data, valid, index : configIndex } ) ) ;
8492 dispatch ( setDeviceState ( { deviceState : DeviceState . Connected , index } ) ) ;
8593 } ) ;
8694
8795 api . registerHttpStatusHandler (
8896 ( { systemStatus, networkStatus, ntpStatus, mqttStatus } , index ) => {
8997 if ( systemStatus ) {
90- dispatch ( setSystemStatus ( { data : systemStatus } ) ) ;
98+ dispatch (
99+ setSystemStatus ( { data : systemStatus , index : configIndex } ) ,
100+ ) ;
91101 dispatch (
92102 updateDtuHostname ( {
93103 hostname : systemStatus . hostname ,
@@ -103,15 +113,17 @@ export const ApiProvider: FC<PropsWithChildren<unknown>> = ({ children }) => {
103113 }
104114
105115 if ( networkStatus ) {
106- dispatch ( setNetworkStatus ( { data : networkStatus } ) ) ;
116+ dispatch (
117+ setNetworkStatus ( { data : networkStatus , index : configIndex } ) ,
118+ ) ;
107119 }
108120
109121 if ( ntpStatus ) {
110- dispatch ( setNtpStatus ( { data : ntpStatus } ) ) ;
122+ dispatch ( setNtpStatus ( { data : ntpStatus , index : configIndex } ) ) ;
111123 }
112124
113125 if ( mqttStatus ) {
114- dispatch ( setMqttStatus ( { data : mqttStatus } ) ) ;
126+ dispatch ( setMqttStatus ( { data : mqttStatus , index : configIndex } ) ) ;
115127 }
116128
117129 setDeviceState ( { deviceState : DeviceState . Connected , index } ) ;
0 commit comments