import type { JSONSchemaType } from 'ajv';
+import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
import OCPPError from '../../../exception/OCPPError';
import type { JsonObject, JsonType } from '../../../types/JsonType';
import {
OCPP20BootNotificationResponse,
OCPP20ClearCacheResponse,
OCPP20HeartbeatResponse,
+ OCPP20StatusNotificationResponse,
} from '../../../types/ocpp/2.0/Responses';
import { ErrorType } from '../../../types/ocpp/ErrorType';
import { OCPPVersion } from '../../../types/ocpp/OCPPVersion';
import logger from '../../../utils/Logger';
import type ChargingStation from '../../ChargingStation';
import OCPPResponseService from '../OCPPResponseService';
-import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
const moduleName = 'OCPP20ResponseService';
this.responseHandlers = new Map<OCPP20RequestCommand, ResponseHandler>([
[OCPP20RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
[OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this)],
+ [OCPP20RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
]);
this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP20RequestCommand.BOOT_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20BootNotificationResponse>,
+ this.parseJsonSchemaFile<OCPP20BootNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json'
+ ),
],
[
OCPP20RequestCommand.HEARTBEAT,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20HeartbeatResponse>,
+ this.parseJsonSchemaFile<OCPP20HeartbeatResponse>(
+ '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json'
+ ),
+ ],
+ [
+ OCPP20RequestCommand.STATUS_NOTIFICATION,
+ this.parseJsonSchemaFile<OCPP20StatusNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json'
+ ),
],
]);
this.jsonIncomingRequestResponseSchemas = new Map([
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20ClearCacheResponse>,
+ this.parseJsonSchemaFile<OCPP20ClearCacheResponse>(
+ '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json'
+ ),
],
]);
this.validatePayload.bind(this);
: logger.info(logMsg);
} else {
logger.error(
- chargingStation.logPrefix() +
- ' Charging station boot notification response received: %j with undefined registration status',
+ `${chargingStation.logPrefix()} Charging station boot notification response received: %j with undefined registration status`,
payload
);
}
}
+
+ private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
+ return JSON.parse(
+ fs.readFileSync(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
+ 'utf8'
+ )
+ ) as JSONSchemaType<T>;
+ }
}