From: Jérôme Benoit Date: Sat, 2 May 2026 21:41:49 +0000 (+0200) Subject: fix: stop nullifying wsConnection prematurely in close/terminate X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b8ba9459c73b25fa93251c2a97d1aa72a88f0185;p=e-mobility-charging-stations-simulator.git fix: stop nullifying wsConnection prematurely in close/terminate 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. --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 7f981991..37f1c697 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 } } } diff --git a/ui/web/tests/unit/skins/modern/ConnectorRow.test.ts b/ui/web/tests/unit/skins/modern/ConnectorRow.test.ts index 19015e19..0dedc111 100644 --- a/ui/web/tests/unit/skins/modern/ConnectorRow.test.ts +++ b/ui/web/tests/unit/skins/modern/ConnectorRow.test.ts @@ -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 () => { diff --git a/ui/web/tests/unit/skins/modern/ModernLayout.test.ts b/ui/web/tests/unit/skins/modern/ModernLayout.test.ts index 5d652422..fab7a241 100644 --- a/ui/web/tests/unit/skins/modern/ModernLayout.test.ts +++ b/ui/web/tests/unit/skins/modern/ModernLayout.test.ts @@ -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: - '
', + template: '
', }, }, }, @@ -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: `
diff --git a/ui/web/tests/unit/skins/modern/StationCard.test.ts b/ui/web/tests/unit/skins/modern/StationCard.test.ts index b284fde4..984e9cb7 100644 --- a/ui/web/tests/unit/skins/modern/StationCard.test.ts +++ b/ui/web/tests/unit/skins/modern/StationCard.test.ts @@ -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 () => {