type BootNotificationRequest,
type BootNotificationResponse,
type CachedRequest,
- type ChargingStationAutomaticTransactionGeneratorConfiguration,
type ChargingStationConfiguration,
type ChargingStationInfo,
type ChargingStationOcppConfiguration,
FileUtils,
MessageChannelUtils,
Utils,
+ buildChargingStationAutomaticTransactionGeneratorConfiguration,
+ buildConnectorsStatus,
+ buildEvsesStatus,
logger,
} from '../utils';
return configuration;
}
- private saveChargingStationAutomaticTransactionGeneratorConfiguration(
- stationTemplate?: ChargingStationTemplate
- ): void {
- this.saveConfiguration({
- automaticTransactionGenerator: (stationTemplate ?? this.getTemplateFromFile())
- .AutomaticTransactionGenerator,
- ...(!Utils.isNullOrUndefined(this.automaticTransactionGenerator?.connectorsStatus) && {
- automaticTransactionGeneratorStatuses: [
- ...this.automaticTransactionGenerator.connectorsStatus.values(),
- ],
- }),
- });
+ private saveChargingStationAutomaticTransactionGeneratorConfiguration(): void {
+ this.saveConfiguration();
}
private saveConnectorsStatus() {
this.saveConfiguration();
}
- private saveConfiguration(
- chargingStationAutomaticTransactionGeneratorConfiguration?: ChargingStationAutomaticTransactionGeneratorConfiguration
- ): void {
+ private saveConfiguration(): void {
if (Utils.isNotEmptyString(this.configurationFile)) {
try {
if (!fs.existsSync(path.dirname(this.configurationFile))) {
if (this.getOcppPersistentConfiguration() && this.ocppConfiguration?.configurationKey) {
configurationData.configurationKey = this.ocppConfiguration.configurationKey;
}
- if (chargingStationAutomaticTransactionGeneratorConfiguration) {
- configurationData = merge<ChargingStationConfiguration>(
- configurationData,
- chargingStationAutomaticTransactionGeneratorConfiguration
- );
- }
+ configurationData = merge<ChargingStationConfiguration>(
+ configurationData,
+ buildChargingStationAutomaticTransactionGeneratorConfiguration(this)
+ );
if (this.connectors.size > 0) {
- configurationData.connectorsStatus = [...this.connectors.values()].map(
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest
- );
+ configurationData.connectorsStatus = buildConnectorsStatus(this);
}
if (this.evses.size > 0) {
- configurationData.evsesStatus = [...this.evses.values()].map((evseStatus) => {
- const status = {
- ...evseStatus,
- connectorsStatus: [...evseStatus.connectors.values()].map(
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest
- ),
- };
- delete status.connectors;
- return status as EvseStatusConfiguration;
- });
+ configurationData.evsesStatus = buildEvsesStatus(this);
}
delete configurationData.configurationHash;
const configurationHash = crypto
--- /dev/null
+import { Utils } from './Utils';
+import type { ChargingStation } from '../charging-station';
+import type {
+ ChargingStationAutomaticTransactionGeneratorConfiguration,
+ ConnectorStatus,
+ EvseStatusConfiguration,
+} from '../types';
+
+export const buildChargingStationAutomaticTransactionGeneratorConfiguration = (
+ chargingStation: ChargingStation
+): ChargingStationAutomaticTransactionGeneratorConfiguration => {
+ return {
+ automaticTransactionGenerator: chargingStation.getAutomaticTransactionGeneratorConfiguration(),
+ ...(!Utils.isNullOrUndefined(
+ chargingStation.automaticTransactionGenerator?.connectorsStatus
+ ) && {
+ automaticTransactionGeneratorStatuses: [
+ ...chargingStation.automaticTransactionGenerator.connectorsStatus.values(),
+ ],
+ }),
+ };
+};
+
+export const buildConnectorsStatus = (chargingStation: ChargingStation): ConnectorStatus[] => {
+ return [...chargingStation.connectors.values()].map(
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest
+ );
+};
+
+export const enum OutputFormat {
+ configuration = 'configuration',
+ ipc = 'ipc',
+}
+
+export const buildEvsesStatus = (
+ chargingStation: ChargingStation,
+ outputFormat: OutputFormat = OutputFormat.configuration
+): EvseStatusConfiguration[] => {
+ return [...chargingStation.evses.values()].map((evseStatus) => {
+ const connectorsStatus = [...evseStatus.connectors.values()].map(
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest
+ );
+ if (outputFormat === OutputFormat.ipc) {
+ return {
+ ...evseStatus,
+ connectors: connectorsStatus,
+ };
+ } else if (outputFormat === OutputFormat.configuration) {
+ const status = {
+ ...evseStatus,
+ connectorsStatus,
+ };
+ delete status.connectors;
+ return status;
+ }
+ });
+};
+import {
+ OutputFormat,
+ buildChargingStationAutomaticTransactionGeneratorConfiguration,
+ buildConnectorsStatus,
+ buildEvsesStatus,
+} from './ChargingStationConfigurationUtils';
import type { ChargingStation } from '../charging-station';
import {
type ChargingStationData,
return {
started: chargingStation.started,
stationInfo: chargingStation.stationInfo,
- connectors: [...chargingStation.connectors.values()].map(
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest
- ),
- evses: [...chargingStation.evses.values()].map((evseStatus) => {
- return {
- ...evseStatus,
- connectors: [...evseStatus.connectors.values()].map(
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest
- ),
- };
- }),
+ connectors: buildConnectorsStatus(chargingStation),
+ evses: buildEvsesStatus(chargingStation, OutputFormat.ipc),
ocppConfiguration: chargingStation.ocppConfiguration,
wsState: chargingStation?.wsConnection?.readyState,
bootNotificationResponse: chargingStation.bootNotificationResponse,
...(chargingStation.automaticTransactionGenerator && {
- automaticTransactionGenerator: {
- automaticTransactionGenerator:
- chargingStation.getAutomaticTransactionGeneratorConfiguration(),
- automaticTransactionGeneratorStatuses: [
- ...chargingStation.automaticTransactionGenerator.connectorsStatus.values(),
- ],
- },
+ automaticTransactionGenerator:
+ buildChargingStationAutomaticTransactionGeneratorConfiguration(chargingStation),
}),
};
}
export { ACElectricUtils, DCElectricUtils } from './ElectricUtils';
export { AsyncLock, AsyncLockType } from './AsyncLock';
+export {
+ OutputFormat,
+ buildChargingStationAutomaticTransactionGeneratorConfiguration,
+ buildConnectorsStatus,
+ buildEvsesStatus,
+} from './ChargingStationConfigurationUtils';
export { CircularArray } from './CircularArray';
export { Configuration } from './Configuration';
export { Constants } from './Constants';