X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F2.0%2FOCPP20ResponseService.ts;h=50566300231ddfe3347870f3234737d64d31df9e;hb=c3da35d496cbb2c78e85fb3d2e125ffd6fd297f4;hp=5561b82b0943c2b9e7c2a23c5533ef944b9c2bc2;hpb=268a74bb051fcbbad532fd833f0d8fd2b33b6c64;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index 5561b82b..50566300 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -3,25 +3,24 @@ import type { JSONSchemaType } from 'ajv'; import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; +import { type ChargingStation, ChargingStationConfigurationUtils } from '../../../charging-station'; import { OCPPError } from '../../../exception'; import { ErrorType, type JsonObject, type JsonType, - OCPP16StandardParametersKey, type OCPP20BootNotificationResponse, type OCPP20ClearCacheResponse, type OCPP20HeartbeatResponse, OCPP20IncomingRequestCommand, + OCPP20OptionalVariableName, OCPP20RequestCommand, type OCPP20StatusNotificationResponse, OCPPVersion, RegistrationStatusEnumType, type ResponseHandler, } from '../../../types'; -import { logger } from '../../../utils/Logger'; -import type { ChargingStation } from '../../ChargingStation'; -import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils'; +import { logger } from '../../../utils'; import { OCPPResponseService } from '../OCPPResponseService'; const moduleName = 'OCPP20ResponseService'; @@ -36,9 +35,9 @@ export class OCPP20ResponseService extends OCPPResponseService { private jsonSchemas: Map>; public constructor() { - if (new.target?.name === moduleName) { - throw new TypeError(`Cannot construct ${new.target?.name} instances directly`); - } + // if (new.target?.name === moduleName) { + // throw new TypeError(`Cannot construct ${new.target?.name} instances directly`); + // } super(OCPPVersion.VERSION_20); this.responseHandlers = new Map([ [OCPP20RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)], @@ -49,7 +48,7 @@ export class OCPP20ResponseService extends OCPPResponseService { [ OCPP20RequestCommand.BOOT_NOTIFICATION, OCPP20ServiceUtils.parseJsonSchemaFile( - '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json', + 'assets/json-schemas/ocpp/2.0/BootNotificationResponse.json', moduleName, 'constructor' ), @@ -57,7 +56,7 @@ export class OCPP20ResponseService extends OCPPResponseService { [ OCPP20RequestCommand.HEARTBEAT, OCPP20ServiceUtils.parseJsonSchemaFile( - '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json', + 'assets/json-schemas/ocpp/2.0/HeartbeatResponse.json', moduleName, 'constructor' ), @@ -65,7 +64,7 @@ export class OCPP20ResponseService extends OCPPResponseService { [ OCPP20RequestCommand.STATUS_NOTIFICATION, OCPP20ServiceUtils.parseJsonSchemaFile( - '../../../assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json', + 'assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json', moduleName, 'constructor' ), @@ -75,13 +74,17 @@ export class OCPP20ResponseService extends OCPPResponseService { [ OCPP20IncomingRequestCommand.CLEAR_CACHE, OCPP20ServiceUtils.parseJsonSchemaFile( - '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json', + 'assets/json-schemas/ocpp/2.0/ClearCacheResponse.json', moduleName, 'constructor' ), ], ]); - this.validatePayload.bind(this); + this.validatePayload = this.validatePayload.bind(this) as ( + chargingStation: ChargingStation, + commandName: OCPP20RequestCommand, + payload: JsonType + ) => boolean; } public async responseHandler( @@ -161,21 +164,12 @@ export class OCPP20ResponseService extends OCPPResponseService { if (payload.status === RegistrationStatusEnumType.ACCEPTED) { ChargingStationConfigurationUtils.addConfigurationKey( chargingStation, - OCPP16StandardParametersKey.HeartbeatInterval, + OCPP20OptionalVariableName.HeartbeatInterval, payload.interval.toString(), {}, { overwrite: true, save: true } ); - ChargingStationConfigurationUtils.addConfigurationKey( - chargingStation, - OCPP16StandardParametersKey.HeartBeatInterval, - payload.interval.toString(), - { visible: false }, - { overwrite: true, save: true } - ); - chargingStation.heartbeatSetInterval - ? chargingStation.restartHeartbeat() - : chargingStation.startHeartbeat(); + OCPP20ServiceUtils.startHeartbeatInterval(chargingStation, payload.interval); } if (Object.values(RegistrationStatusEnumType).includes(payload.status)) { const logMsg = `${chargingStation.logPrefix()} Charging station in '${