public automaticTransactionGenerator!: AutomaticTransactionGenerator | undefined;
public ocppConfiguration!: ChargingStationOcppConfiguration | undefined;
public wsConnection!: WebSocket | null;
- public connectors: Map<number, ConnectorStatus>;
+ public readonly connectors: Map<number, ConnectorStatus>;
public readonly evses: Map<number, EvseStatus>;
public readonly requests: Map<string, CachedRequest>;
public performanceStatistics!: PerformanceStatistics | undefined;
private initializeConnectorsOrEvsesFromFile(configuration: ChargingStationConfiguration): void {
if (configuration?.connectorsStatus && !configuration?.evsesStatus) {
- this.connectors = new Map<number, ConnectorStatus>(
- configuration?.connectorsStatus.map((connectorStatus, connectorId) => [
- connectorId,
- connectorStatus,
- ])
- );
+ for (const [connectorId, connectorStatus] of configuration.connectorsStatus.entries()) {
+ this.connectors.set(connectorId, Utils.cloneObject<ConnectorStatus>(connectorStatus));
+ }
} else if (configuration?.evsesStatus && !configuration?.connectorsStatus) {
for (const [evseId, evseStatusConfiguration] of configuration.evsesStatus.entries()) {
- const evseStatus = Utils.cloneObject(evseStatusConfiguration);
+ const evseStatus = Utils.cloneObject<EvseStatusConfiguration>(evseStatusConfiguration);
delete evseStatus.connectorsStatus;
this.evses.set(evseId, {
- ...evseStatus,
+ ...(evseStatus as EvseStatus),
connectors: new Map<number, ConnectorStatus>(
evseStatusConfiguration.connectorsStatus.map((connectorStatus, connectorId) => [
connectorId,
fs.mkdirSync(path.dirname(this.configurationFile), { recursive: true });
}
let configurationData: ChargingStationConfiguration =
- Utils.cloneObject(this.getConfigurationFromFile()) ?? {};
+ Utils.cloneObject<ChargingStationConfiguration>(this.getConfigurationFromFile()) ?? {};
if (this.getStationInfoPersistentConfiguration() && this.stationInfo) {
configurationData.stationInfo = this.stationInfo;
}
}
private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration | undefined {
- let configuration: ChargingStationConfiguration | undefined;
if (this.getOcppPersistentConfiguration() === true) {
- const configurationFromFile = this.getConfigurationFromFile();
- configuration = configurationFromFile?.configurationKey && configurationFromFile;
- }
- if (!Utils.isNullOrUndefined(configuration)) {
- delete configuration.stationInfo;
- delete configuration.connectorsStatus;
- delete configuration.evsesStatus;
- delete configuration.automaticTransactionGenerator;
- delete configuration.automaticTransactionGeneratorStatuses;
- delete configuration.configurationHash;
+ return { configurationKey: this.getConfigurationFromFile()?.configurationKey };
}
- return configuration;
}
private getOcppConfiguration(): ChargingStationOcppConfiguration | undefined {
public static stationTemplateToStationInfo(
stationTemplate: ChargingStationTemplate
): ChargingStationInfo {
- stationTemplate = Utils.cloneObject(stationTemplate);
+ stationTemplate = Utils.cloneObject<ChargingStationTemplate>(stationTemplate);
delete stationTemplate.power;
delete stationTemplate.powerUnit;
delete stationTemplate?.Connectors;
let limit: number, matchingChargingProfile: ChargingProfile;
// Get charging profiles for connector and sort by stack level
const chargingProfiles =
- Utils.cloneObject(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)?.sort(
- (a, b) => b.stackLevel - a.stackLevel
- ) ?? [];
+ Utils.cloneObject<ChargingProfile[]>(
+ chargingStation.getConnectorStatus(connectorId)?.chargingProfiles
+ )?.sort((a, b) => b.stackLevel - a.stackLevel) ?? [];
// Get profiles on connector 0
if (chargingStation.getConnectorStatus(0)?.chargingProfiles) {
chargingProfiles.push(
- ...Utils.cloneObject(chargingStation.getConnectorStatus(0).chargingProfiles).sort(
- (a, b) => b.stackLevel - a.stackLevel
- )
+ ...Utils.cloneObject<ChargingProfile[]>(
+ chargingStation.getConnectorStatus(0).chargingProfiles
+ ).sort((a, b) => b.stackLevel - a.stackLevel)
);
}
if (Utils.isNotEmptyArray(chargingProfiles)) {