@@ -48,18 +48,7 @@ class PredbatTableCard extends HTMLElement {
4848
4949 this . _reactiveDataState . carCharging = this . _configManager . carChargeSwitch ;
5050
51- if ( this . _predbatRestApiService ) {
52- this . _predbatRestApiService . disconnect ( ) ;
53- this . _predbatRestApiService = null ;
54- }
55-
56- PredbatRestApiService . restApiAvailable ( restApiPort )
57- . then ( ( restApiAvailable ) => {
58- this . _restApiAvailable = restApiAvailable ;
59-
60- if ( restApiAvailable ) this . _predbatRestApiService = new PredbatRestApiService ( restApiPort , this . setPlanData ) ;
61- } )
62- . catch ( ( ) => this . _restApiAvailable = false ) ;
51+ this . _initialiseRestApi ( ) ;
6352 }
6453
6554 // * New state received from Home Assistant
@@ -170,6 +159,7 @@ class PredbatTableCard extends HTMLElement {
170159 if ( this . _predbatRestApiService ) this . _render ( ) ;
171160 } ;
172161
162+ this . _initialiseRestApi ( ) ;
173163 this . _render ( ) ;
174164 }
175165
@@ -183,6 +173,9 @@ class PredbatTableCard extends HTMLElement {
183173 this . _predbatRestApiService . disconnect ( ) ;
184174 this . _predbatRestApiService = null ;
185175 }
176+
177+ this . _lastPlanUpdated = null ;
178+ this . _planData = null ;
186179 }
187180
188181 // * Register card with Home Assistant
@@ -206,6 +199,29 @@ class PredbatTableCard extends HTMLElement {
206199 this . _render ( ) ;
207200 } ;
208201
202+ private _initialiseRestApi ( ) : void {
203+ if ( this . _predbatRestApiService ) {
204+ this . _predbatRestApiService . disconnect ( ) ;
205+ this . _predbatRestApiService = null ;
206+ }
207+
208+ this . _restApiAvailable = null ;
209+
210+ PredbatRestApiService . restApiAvailable ( restApiPort )
211+ . then ( ( restApiAvailable ) => {
212+ this . _restApiAvailable = restApiAvailable ;
213+
214+ if ( restApiAvailable ) this . _predbatRestApiService = new PredbatRestApiService ( restApiPort , this . setPlanData ) ;
215+
216+ this . _render ( ) ;
217+ } )
218+ . catch ( ( ) => {
219+ this . _restApiAvailable = false ;
220+
221+ this . _render ( ) ;
222+ } ) ;
223+ }
224+
209225 private _render ( ) : void {
210226 if (
211227 this . _restApiAvailable === null ||
0 commit comments