X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=a5319eccbf93b1ab8f5c4c634a72e46cd0ea70e6;hb=86ad08b201bdfb35de3295a5f36a3998f24ae702;hp=b035e5b3dc297ca239e0df7fc80bd87848962a5e;hpb=32b0224999178acf1101ff9075c95072d207206e;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index b035e5b3..a5319ecc 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -508,8 +508,9 @@ export default class ChargingStation { this.stationInfo.randomConnectors = true; } const connectorsConfigHash = crypto.createHash('sha256').update(JSON.stringify(this.stationInfo.Connectors) + maxConnectors.toString()).digest('hex'); - // FIXME: Handle shrinking the number of connectors - if (!this.connectors || (this.connectors && this.connectorsConfigurationHash !== connectorsConfigHash)) { + const connectorsConfigChanged = !Utils.isEmptyObject(this.connectors) && this.connectorsConfigurationHash !== connectorsConfigHash; + if (Utils.isEmptyObject(this.connectors) || connectorsConfigChanged) { + connectorsConfigChanged && (this.connectors = {} as Connectors); this.connectorsConfigurationHash = connectorsConfigHash; // Add connector Id 0 let lastConnector = '0'; @@ -679,11 +680,11 @@ export default class ChargingStation { if (Utils.isIterable(cachedRequest)) { [responseCallback, , , requestPayload] = cachedRequest; } else { - throw new OCPPError(ErrorType.PROTOCOL_ERROR, `Response request for message id ${messageId} is not iterable`, commandName); + throw new OCPPError(ErrorType.PROTOCOL_ERROR, `Cached request for message id ${messageId} response is not iterable`, commandName); } if (!responseCallback) { // Error - throw new OCPPError(ErrorType.INTERNAL_ERROR, `Response request for unknown message id ${messageId}`, commandName); + throw new OCPPError(ErrorType.INTERNAL_ERROR, `Response for unknown message id ${messageId}`, commandName); } responseCallback(commandName, requestPayload); break; @@ -693,11 +694,11 @@ export default class ChargingStation { if (Utils.isIterable(cachedRequest)) { [, rejectCallback, requestCommandName] = cachedRequest; } else { - throw new OCPPError(ErrorType.PROTOCOL_ERROR, `Error request for message id ${messageId} is not iterable`); + throw new OCPPError(ErrorType.PROTOCOL_ERROR, `Cached request for message id ${messageId} error response is not iterable`); } if (!rejectCallback) { // Error - throw new OCPPError(ErrorType.INTERNAL_ERROR, `Error request for unknown message id ${messageId}`, requestCommandName); + throw new OCPPError(ErrorType.INTERNAL_ERROR, `Error response for unknown message id ${messageId}`, requestCommandName); } rejectCallback(new OCPPError(commandName, commandPayload.toString(), requestCommandName, errorDetails)); break; @@ -709,7 +710,7 @@ export default class ChargingStation { } } catch (error) { // Log - logger.error('%s Incoming request message %j matching cached request %j processing error %j ', this.logPrefix(), data, this.requests.get(messageId), error); + logger.error('%s Incoming OCPP message %j matching cached request %j processing error %j', this.logPrefix(), data, this.requests.get(messageId), error); // Send error messageType === MessageType.CALL_MESSAGE && await this.ocppRequestService.sendError(messageId, error, commandName); }