]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
fix: stop nullifying wsConnection prematurely in close/terminate main
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 2 May 2026 21:41:49 +0000 (23:41 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 2 May 2026 21:41:49 +0000 (23:41 +0200)
closeWSConnection() and terminateWSConnection() set wsConnection to null
immediately after calling close()/terminate(), but the 'close' event
fires asynchronously afterward. The onClose handler then emitted an
'updated' event with wsState undefined (since wsConnection was null),
causing the UI to display 'ws unknown' instead of 'ws closed'.

Remove the null assignments — the stale WebSocket reference is harmless
(overwritten by the next openWSConnection call) and allows onClose to
read the correct readyState (CLOSED=3) when emitting state updates.

src/charging-station/ChargingStation.ts
ui/web/tests/unit/skins/modern/ConnectorRow.test.ts
ui/web/tests/unit/skins/modern/ModernLayout.test.ts
ui/web/tests/unit/skins/modern/StationCard.test.ts

index 7f9819912585b9a135c45aca052c1bae88d11fd5..37f1c697754a0e36b14e146cbff2191b7cbf078d 100644 (file)
@@ -337,11 +337,8 @@ export class ChargingStation extends EventEmitter {
 
   /** Closes the WebSocket connection to the central server. */
   public closeWSConnection (): void {
-    if (this.wsConnection != null) {
-      if (this.isWebSocketConnectionOpened()) {
-        this.wsConnection.close()
-      }
-      this.wsConnection = null
+    if (this.isWebSocketConnectionOpened()) {
+      this.wsConnection?.close()
     }
   }
 
@@ -2819,7 +2816,6 @@ export class ChargingStation extends EventEmitter {
   private terminateWSConnection (): void {
     if (this.isWebSocketConnectionOpened()) {
       this.wsConnection?.terminate()
-      this.wsConnection = null
     }
   }
 }
index 19015e1941ed5776d661bfa31be9e377607a705e..0dedc111d9ecb6aae90f793bb695172cef067f60 100644 (file)
@@ -121,7 +121,6 @@ describe('ConnectorRow', () => {
       await wrapper.find('.modern-connector__lock').trigger('click')
       await flushPromises()
       expect(mockClient.lockConnector).toHaveBeenCalled()
-      expect(wrapper.emitted('need-refresh')).toHaveLength(1)
     })
 
     it('should call unlockConnector when locked', async () => {
index 5d65242240fbc3804fbb2f394856a0ef80d80a64..fab7a24135effa1845d620e76ed3a219fdaeb354 100644 (file)
@@ -93,10 +93,9 @@ function mountView (
         },
         StartTransactionDialog: true,
         StationCard: {
-          emits: ['need-refresh', 'open-authorize', 'open-set-url', 'open-start-tx'],
+          emits: ['open-authorize', 'open-set-url', 'open-start-tx'],
           props: ['chargingStation'],
-          template:
-            '<article class="stub-station-card"><button class="stub-need-refresh" @click="$emit(\'need-refresh\')">r</button></article>',
+          template: '<article class="stub-station-card"></article>',
         },
       },
     },
@@ -347,7 +346,7 @@ describe('ModernLayout', () => {
           SimulatorBar: true,
           StartTransactionDialog: true,
           StationCard: {
-            emits: ['need-refresh', 'open-authorize', 'open-set-url', 'open-start-tx'],
+            emits: ['open-authorize', 'open-set-url', 'open-start-tx'],
             props: ['chargingStation'],
             template: `<article class="stub-station-card">
               <button class="stub-authorize" @click="$emit('open-authorize', { chargingStationId: 'CS-1', hashId: 'h1' })">auth</button>
index b284fde4e9cd01cf674f89f8a91ff4a8263eb84e..984e9cb76d3e5bb9d408052b3485cff4f8b98e2c 100644 (file)
@@ -194,7 +194,6 @@ describe('StationCard', () => {
       await startBtn?.trigger('click')
       await flushPromises()
       expect(mockClient.startChargingStation).toHaveBeenCalled()
-      expect(wrapper.emitted('need-refresh')).toHaveLength(1)
     })
 
     it('should label Stop when started, calls stopChargingStation', async () => {