From: Jérôme Benoit Date: Sat, 27 Aug 2022 23:07:01 +0000 (+0200) Subject: Ensure charging station data is always JSON serializable X-Git-Tag: v1.1.68~11 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fc040c43a050868c037485c658de49576f00fa55;p=e-mobility-charging-stations-simulator.git Ensure charging station data is always JSON serializable And fix/improve logging messages Signed-off-by: Jérôme Benoit --- diff --git a/build-requirements.js b/build-requirements.js index 7f36a487..74d38ccd 100644 --- a/build-requirements.js +++ b/build-requirements.js @@ -5,7 +5,7 @@ const SemVer = require('semver'); const enginesNodeVersion = require('./package.json').engines.node; /** - * + * Check if the current node version match the required engines version. */ function checkNodeVersion() { if (SemVer.satisfies(process.version, enginesNodeVersion) === false) { diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index c9065cda..db6f914c 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -13,4 +13,4 @@ services: networks: - ev_network ports: - - "3030:3030" + - '3030:3030' diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index c5b89152..bd23b37d 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -583,7 +583,7 @@ export default class ChargingStation { if (!Utils.isEmptyArray(chargingProfiles)) { const result = ChargingStationUtils.getLimitFromChargingProfiles( chargingProfiles, - Utils.logPrefix() + this.logPrefix() ); if (!Utils.isNullOrUndefined(result)) { limit = result.limit; @@ -846,14 +846,14 @@ export default class ChargingStation { ChargingStationUtils.checkConfiguredMaxConnectors( configuredMaxConnectors, this.templateFile, - Utils.logPrefix() + this.logPrefix() ); const templateMaxConnectors = ChargingStationUtils.getTemplateMaxNumberOfConnectors(stationTemplate); ChargingStationUtils.checkTemplateMaxConnectors( templateMaxConnectors, this.templateFile, - Utils.logPrefix() + this.logPrefix() ); if ( configuredMaxConnectors > @@ -920,10 +920,8 @@ export default class ChargingStation { } private handleUnsupportedVersion(version: OCPPVersion) { - const errMsg = `${this.logPrefix()} Unsupported protocol version '${version}' configured in template file ${ - this.templateFile - }`; - logger.error(errMsg); + const errMsg = `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`; + logger.error(`${this.logPrefix()} ${errMsg}`); throw new BaseError(errMsg); } @@ -1142,10 +1140,8 @@ export default class ChargingStation { templateMaxConnectors: number ): void { if (!stationInfo?.Connectors && this.connectors.size === 0) { - const logMsg = `${this.logPrefix()} No already defined connectors and charging station information from template ${ - this.templateFile - } with no connectors configuration defined`; - logger.error(logMsg); + const logMsg = `No already defined connectors and charging station information from template ${this.templateFile} with no connectors configuration defined`; + logger.error(`${this.logPrefix()} ${logMsg}`); throw new BaseError(logMsg); } if (!stationInfo?.Connectors[0]) { @@ -1506,8 +1502,8 @@ export default class ChargingStation { // Error default: // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - errMsg = `${this.logPrefix()} Wrong message type ${messageType}`; - logger.error(errMsg); + errMsg = `Wrong message type ${messageType}`; + logger.error(`${this.logPrefix()} ${errMsg}`); throw new OCPPError(ErrorType.PROTOCOL_ERROR, errMsg); } parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); @@ -1519,19 +1515,18 @@ export default class ChargingStation { } catch (error) { // Log logger.error( - "%s Incoming OCPP '%s' message '%j' matching cached request '%j' processing error:", - this.logPrefix(), - commandName ?? requestCommandName ?? null, - data.toString(), - this.requests.get(messageId), + `${this.logPrefix()} Incoming OCPP '${ + commandName ?? requestCommandName ?? null + }' message '${data.toString()}' matching cached request '${JSON.stringify( + this.requests.get(messageId) + )}' processing error:`, error ); if (!(error instanceof OCPPError)) { logger.warn( - "%s Error thrown at incoming OCPP '%s' message '%j' handling is not an OCPPError:", - this.logPrefix(), - commandName ?? requestCommandName ?? null, - data.toString(), + `${this.logPrefix()} Error thrown at incoming OCPP '${ + commandName ?? requestCommandName ?? null + }' message '${data.toString()}' handling is not an OCPPError:`, error ); } diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 645fbd95..8978f0c8 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -426,7 +426,7 @@ export class ChargingStationUtils { templateFile: string, logPrefix: string ): Voltage { - const errMsg = `${logPrefix} Unknown ${currentType} currentOutType in template file ${templateFile}, cannot define default voltage out`; + const errMsg = `Unknown ${currentType} currentOutType in template file ${templateFile}, cannot define default voltage out`; let defaultVoltageOut: number; switch (currentType) { case CurrentType.AC: @@ -436,7 +436,7 @@ export class ChargingStationUtils { defaultVoltageOut = Voltage.VOLTAGE_400; break; default: - logger.error(errMsg); + logger.error(`${logPrefix} ${errMsg}`); throw new BaseError(errMsg); } return defaultVoltageOut; @@ -514,8 +514,8 @@ export class ChargingStationUtils { } } if (measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER) { - const errorMsg = `${chargingStation.logPrefix()} Missing MeterValues for default measurand '${measurand}' in template on connectorId ${connectorId}`; - logger.error(errorMsg); + const errorMsg = `Missing MeterValues for default measurand '${measurand}' in template on connectorId ${connectorId}`; + logger.error(`${chargingStation.logPrefix()} ${errorMsg}`); throw new BaseError(errorMsg); } logger.debug( diff --git a/src/charging-station/MessageChannelUtils.ts b/src/charging-station/MessageChannelUtils.ts index 3084a388..4cf037ba 100644 --- a/src/charging-station/MessageChannelUtils.ts +++ b/src/charging-station/MessageChannelUtils.ts @@ -55,7 +55,9 @@ export class MessageChannelUtils { stationInfo: chargingStation.stationInfo, stopped: chargingStation.stopped, bootNotificationResponse: chargingStation.bootNotificationResponse, - connectors: Array.from(chargingStation.connectors.values()), + connectors: Array.from(chargingStation.connectors.values()).map( + ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest + ), }; } } diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 70ae3c25..d765e1d2 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -417,14 +417,14 @@ export default class OCPP16ResponseService extends OCPPResponseService { ); return; } - if (!Number.isInteger(payload.transactionId)) { - logger.warn( - `${chargingStation.logPrefix()} Trying to start a transaction on connector ${connectorId.toString()} with a non integer transaction Id ${ - payload.transactionId - }, converting to integer` - ); - payload.transactionId = Utils.convertToInt(payload.transactionId); - } + // if (!Number.isInteger(payload.transactionId)) { + // logger.warn( + // `${chargingStation.logPrefix()} Trying to start a transaction on connector ${connectorId.toString()} with a non integer transaction Id ${ + // payload.transactionId + // }, converting to integer` + // ); + // payload.transactionId = Utils.convertToInt(payload.transactionId); + // } if (payload.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) { chargingStation.getConnectorStatus(connectorId).transactionStarted = true; @@ -489,8 +489,9 @@ export default class OCPP16ResponseService extends OCPPResponseService { payload.transactionId.toString() + " REJECTED with status '" + payload?.idTagInfo?.status + - "', idTag " + - requestPayload.idTag + "', idTag '" + + requestPayload.idTag + + "'" ); await this.resetConnectorOnStartTransactionError(chargingStation, connectorId); } diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 0915aa46..62fa8e50 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -224,7 +224,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { chargingStation, powerSampledValueTemplate.measurand ); - const errMsg = `${chargingStation.logPrefix()} MeterValues measurand ${ + const errMsg = `MeterValues measurand ${ powerSampledValueTemplate.measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: Unknown ${chargingStation.getCurrentOutType()} currentOutType in template file ${ @@ -334,7 +334,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { : Utils.getRandomFloatRounded(connectorMaximumPower / unitDivider); break; default: - logger.error(errMsg); + logger.error(`${chargingStation.logPrefix()} ${errMsg}`); throw new OCPPError(ErrorType.INTERNAL_ERROR, errMsg, OCPP16RequestCommand.METER_VALUES); } meterValue.sampledValue.push( @@ -431,7 +431,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { chargingStation, currentSampledValueTemplate.measurand ); - const errMsg = `${chargingStation.logPrefix()} MeterValues measurand ${ + const errMsg = `MeterValues measurand ${ currentSampledValueTemplate.measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: Unknown ${chargingStation.getCurrentOutType()} currentOutType in template file ${ @@ -547,7 +547,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { : Utils.getRandomFloatRounded(connectorMaximumAmperage); break; default: - logger.error(errMsg); + logger.error(`${chargingStation.logPrefix()} ${errMsg}`); throw new OCPPError(ErrorType.INTERNAL_ERROR, errMsg, OCPP16RequestCommand.METER_VALUES); } meterValue.sampledValue.push( @@ -770,16 +770,16 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { measurandType: OCPP16MeterValueMeasurand ): void { if (Utils.isUndefined(chargingStation.powerDivider)) { - const errMsg = `${chargingStation.logPrefix()} MeterValues measurand ${ + const errMsg = `MeterValues measurand ${ measurandType ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: powerDivider is undefined`; - logger.error(errMsg); + logger.error(`${chargingStation.logPrefix()} ${errMsg}`); throw new OCPPError(ErrorType.INTERNAL_ERROR, errMsg, OCPP16RequestCommand.METER_VALUES); } else if (chargingStation?.powerDivider <= 0) { - const errMsg = `${chargingStation.logPrefix()} MeterValues measurand ${ + const errMsg = `MeterValues measurand ${ measurandType ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: powerDivider have zero or below value ${chargingStation.powerDivider}`; - logger.error(errMsg); + logger.error(`${chargingStation.logPrefix()} ${errMsg}`); throw new OCPPError(ErrorType.INTERNAL_ERROR, errMsg, OCPP16RequestCommand.METER_VALUES); } } diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 4b68b8a8..2ee0465c 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -37,8 +37,7 @@ export default abstract class OCPPIncomingRequestService { params: HandleErrorParams = { throwError: true } ): T { logger.error( - `${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command %s error:`, - commandName, + `${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command ${commandName} error:`, error ); if (!params?.throwError && params?.errorResponse) { diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index c3311b85..25c89435 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -268,10 +268,10 @@ export default abstract class OCPPRequestService { ); } logger.error( - `${chargingStation.logPrefix()} Error %j occurred when calling command %s with message data %j`, - error, - commandName, - messagePayload + `${chargingStation.logPrefix()} Error occurred when calling command ${commandName} with message data ${JSON.stringify( + messagePayload + )}:`, + error ); chargingStation.requests.delete(messageId); reject(error); @@ -361,7 +361,7 @@ export default abstract class OCPPRequestService { error: Error, params: HandleErrorParams = { throwError: true } ): void { - logger.error(chargingStation.logPrefix() + ' Request command %s error:', commandName, error); + logger.error(`${chargingStation.logPrefix()} Request command ${commandName} error:`, error); if (params?.throwError) { throw error; } diff --git a/src/ui/web/package.json b/src/ui/web/package.json index 8050bbce..03e86c51 100644 --- a/src/ui/web/package.json +++ b/src/ui/web/package.json @@ -2,11 +2,11 @@ "name": "webui", "version": "0.1.0", "scripts": { + "start": "npm run build && node start.js", "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint", "lint:fix": "vue-cli-service lint --fix", - "start": "npm run build && node start.js", "test": "vue-cli-service test:unit" }, "dependencies": { diff --git a/src/ui/web/src/components/charging-stations/CSTable.vue b/src/ui/web/src/components/charging-stations/CSTable.vue index fb50b2f5..c76d9e4d 100644 --- a/src/ui/web/src/components/charging-stations/CSTable.vue +++ b/src/ui/web/src/components/charging-stations/CSTable.vue @@ -51,8 +51,8 @@ const props = defineProps<{ #cs-table__head, #cs-table__body { width: 100%; - display: block; min-width: 930px; + display: block; } #cs-table__body { diff --git a/src/ui/web/src/types/UIProtocol.ts b/src/ui/web/src/types/UIProtocol.ts index d324acc5..22871d68 100644 --- a/src/ui/web/src/types/UIProtocol.ts +++ b/src/ui/web/src/types/UIProtocol.ts @@ -43,4 +43,5 @@ export enum ResponseStatus { export interface ResponsePayload extends JsonObject { status: ResponseStatus; + hashIds?: string[]; }