import { AutomaticTransactionGenerator } from './AutomaticTransactionGenerator';
import { ChargingStationWorkerBroadcastChannel } from './broadcast-channel/ChargingStationWorkerBroadcastChannel';
-import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils';
+import {
+ addConfigurationKey,
+ deleteConfigurationKey,
+ getConfigurationKey,
+ setConfigurationKeyValue,
+} from './ChargingStationConfigurationUtils';
import {
buildConnectorsMap,
checkConnectorsConfiguration,
private configurationFileHash!: string;
private connectorsConfigurationHash!: string;
private evsesConfigurationHash!: string;
+ private automaticTransactionGeneratorConfiguration?: AutomaticTransactionGeneratorConfiguration;
private ocppIncomingRequestService!: OCPPIncomingRequestService;
private readonly messageBuffer: Set<string>;
private configuredSupervisionUrl!: URL;
`${
this.getSupervisionUrlOcppConfiguration() &&
isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
- isNotEmptyString(
- ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- this.getSupervisionUrlOcppKey(),
- )?.value,
- )
- ? ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- this.getSupervisionUrlOcppKey(),
- )!.value
+ isNotEmptyString(getConfigurationKey(this, this.getSupervisionUrlOcppKey())?.value)
+ ? getConfigurationKey(this, this.getSupervisionUrlOcppKey())!.value
: this.configuredSupervisionUrl.href
}/${this.stationInfo.chargingStationId}`,
);
public getMaximumPower(stationInfo?: ChargingStationInfo): number {
const localStationInfo = stationInfo ?? this.stationInfo;
// eslint-disable-next-line @typescript-eslint/dot-notation
- return (localStationInfo['maxPower'] as number) ?? localStationInfo.maximumPower;
+ return (
+ (localStationInfo['maxPower' as keyof ChargingStationInfo] as number) ??
+ localStationInfo.maximumPower
+ );
}
public getConnectorMaximumAvailablePower(connectorId: number): number {
}
public getAuthorizeRemoteTxRequests(): boolean {
- const authorizeRemoteTxRequests = ChargingStationConfigurationUtils.getConfigurationKey(
+ const authorizeRemoteTxRequests = getConfigurationKey(
this,
StandardParametersKey.AuthorizeRemoteTxRequests,
);
}
public getLocalAuthListEnabled(): boolean {
- const localAuthListEnabled = ChargingStationConfigurationUtils.getConfigurationKey(
+ const localAuthListEnabled = getConfigurationKey(
this,
StandardParametersKey.LocalAuthListEnabled,
);
}
public getHeartbeatInterval(): number {
- const HeartbeatInterval = ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.HeartbeatInterval,
- );
+ const HeartbeatInterval = getConfigurationKey(this, StandardParametersKey.HeartbeatInterval);
if (HeartbeatInterval) {
return convertToInt(HeartbeatInterval.value) * 1000;
}
- const HeartBeatInterval = ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.HeartBeatInterval,
- );
+ const HeartBeatInterval = getConfigurationKey(this, StandardParametersKey.HeartBeatInterval);
if (HeartBeatInterval) {
return convertToInt(HeartBeatInterval.value) * 1000;
}
this.getSupervisionUrlOcppConfiguration() &&
isNotEmptyString(this.getSupervisionUrlOcppKey())
) {
- ChargingStationConfigurationUtils.setConfigurationKeyValue(
- this,
- this.getSupervisionUrlOcppKey(),
- url,
- );
+ setConfigurationKeyValue(this, this.getSupervisionUrlOcppKey(), url);
} else {
this.stationInfo.supervisionUrls = url;
this.saveStationInfo();
this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo)!);
// Restart the ATG
this.stopAutomaticTransactionGenerator();
+ delete this.automaticTransactionGeneratorConfiguration;
if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) {
this.startAutomaticTransactionGenerator();
}
}
public hasFeatureProfile(featureProfile: SupportedFeatureProfiles): boolean | undefined {
- return ChargingStationConfigurationUtils.getConfigurationKey(
+ return getConfigurationKey(
this,
StandardParametersKey.SupportedFeatureProfiles,
)?.value?.includes(featureProfile);
}
public getAutomaticTransactionGeneratorConfiguration(): AutomaticTransactionGeneratorConfiguration {
- let automaticTransactionGeneratorConfiguration:
- | AutomaticTransactionGeneratorConfiguration
- | undefined;
- const automaticTransactionGeneratorConfigurationFromFile =
- this.getConfigurationFromFile()?.automaticTransactionGenerator;
- if (
- this.getAutomaticTransactionGeneratorPersistentConfiguration() &&
- automaticTransactionGeneratorConfigurationFromFile
- ) {
- automaticTransactionGeneratorConfiguration =
- automaticTransactionGeneratorConfigurationFromFile;
- } else {
- automaticTransactionGeneratorConfiguration =
- this.getTemplateFromFile()?.AutomaticTransactionGenerator;
+ if (isNullOrUndefined(this.automaticTransactionGeneratorConfiguration)) {
+ let automaticTransactionGeneratorConfiguration:
+ | AutomaticTransactionGeneratorConfiguration
+ | undefined;
+ const automaticTransactionGeneratorConfigurationFromFile =
+ this.getConfigurationFromFile()?.automaticTransactionGenerator;
+ if (
+ this.getAutomaticTransactionGeneratorPersistentConfiguration() &&
+ automaticTransactionGeneratorConfigurationFromFile
+ ) {
+ automaticTransactionGeneratorConfiguration =
+ automaticTransactionGeneratorConfigurationFromFile;
+ } else {
+ automaticTransactionGeneratorConfiguration =
+ this.getTemplateFromFile()?.AutomaticTransactionGenerator;
+ }
+ this.automaticTransactionGeneratorConfiguration = {
+ ...Constants.DEFAULT_ATG_CONFIGURATION,
+ ...automaticTransactionGeneratorConfiguration,
+ };
}
- return {
- ...Constants.DEFAULT_ATG_CONFIGURATION,
- ...automaticTransactionGeneratorConfiguration,
- };
+ return this.automaticTransactionGeneratorConfiguration!;
}
public getAutomaticTransactionGeneratorStatuses(): Status[] | undefined {
public getReservationOnConnectorId0Enabled(): boolean {
return convertToBoolean(
- ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.ReserveConnectorZeroSupported,
- )!.value,
+ getConfigurationKey(this, StandardParametersKey.ReserveConnectorZeroSupported)!.value,
);
}
if (this.hasEvses) {
for (const evseStatus of this.evses.values()) {
for (const connectorStatus of evseStatus.connectors.values()) {
- if (connectorStatus?.reservation?.[filterKey] === value) {
+ if (connectorStatus?.reservation?.[filterKey as keyof Reservation] === value) {
return connectorStatus.reservation;
}
}
}
} else {
for (const connectorStatus of this.connectors.values()) {
- if (connectorStatus?.reservation?.[filterKey] === value) {
+ if (connectorStatus?.reservation?.[filterKey as keyof Reservation] === value) {
return connectorStatus.reservation;
}
}
`${this.logPrefix()} Reservation expiration date interval is set to ${interval}
and starts on charging station now`,
);
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- this.reservationExpirationSetInterval = setInterval(async (): Promise<void> => {
- const now = new Date();
- if (this.hasEvses) {
- for (const evseStatus of this.evses.values()) {
- for (const connectorStatus of evseStatus.connectors.values()) {
- if (connectorStatus.reservation!.expiryDate < now) {
- await this.removeReservation(
- connectorStatus.reservation!,
- ReservationTerminationReason.EXPIRED,
- );
+ if (interval > 0) {
+ this.reservationExpirationSetInterval = setInterval((): void => {
+ const currentDate = new Date();
+ if (this.hasEvses) {
+ for (const evseStatus of this.evses.values()) {
+ for (const connectorStatus of evseStatus.connectors.values()) {
+ if (
+ connectorStatus.reservation &&
+ connectorStatus.reservation.expiryDate < currentDate
+ ) {
+ this.removeReservation(
+ connectorStatus.reservation,
+ ReservationTerminationReason.EXPIRED,
+ ).catch(Constants.EMPTY_FUNCTION);
+ }
}
}
- }
- } else {
- for (const connectorStatus of this.connectors.values()) {
- if (connectorStatus.reservation!.expiryDate < now) {
- await this.removeReservation(
- connectorStatus.reservation!,
- ReservationTerminationReason.EXPIRED,
- );
+ } else {
+ for (const connectorStatus of this.connectors.values()) {
+ if (
+ connectorStatus.reservation &&
+ connectorStatus.reservation.expiryDate < currentDate
+ ) {
+ this.removeReservation(
+ connectorStatus.reservation,
+ ReservationTerminationReason.EXPIRED,
+ ).catch(Constants.EMPTY_FUNCTION);
+ }
}
}
- }
- }, interval);
+ }, interval);
+ }
}
public restartReservationExpiryDateSetInterval(): void {
}
private initializeOcppConfiguration(): void {
- if (
- !ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.HeartbeatInterval,
- )
- ) {
- ChargingStationConfigurationUtils.addConfigurationKey(
- this,
- StandardParametersKey.HeartbeatInterval,
- '0',
- );
+ if (!getConfigurationKey(this, StandardParametersKey.HeartbeatInterval)) {
+ addConfigurationKey(this, StandardParametersKey.HeartbeatInterval, '0');
}
- if (
- !ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.HeartBeatInterval,
- )
- ) {
- ChargingStationConfigurationUtils.addConfigurationKey(
- this,
- StandardParametersKey.HeartBeatInterval,
- '0',
- { visible: false },
- );
+ if (!getConfigurationKey(this, StandardParametersKey.HeartBeatInterval)) {
+ addConfigurationKey(this, StandardParametersKey.HeartBeatInterval, '0', { visible: false });
}
if (
this.getSupervisionUrlOcppConfiguration() &&
isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
- !ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
+ !getConfigurationKey(this, this.getSupervisionUrlOcppKey())
) {
- ChargingStationConfigurationUtils.addConfigurationKey(
+ addConfigurationKey(
this,
this.getSupervisionUrlOcppKey(),
this.configuredSupervisionUrl.href,
} else if (
!this.getSupervisionUrlOcppConfiguration() &&
isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
- ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
+ getConfigurationKey(this, this.getSupervisionUrlOcppKey())
) {
- ChargingStationConfigurationUtils.deleteConfigurationKey(
- this,
- this.getSupervisionUrlOcppKey(),
- { save: false },
- );
+ deleteConfigurationKey(this, this.getSupervisionUrlOcppKey(), { save: false });
}
if (
isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
- !ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- this.stationInfo.amperageLimitationOcppKey!,
- )
+ !getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)
) {
- ChargingStationConfigurationUtils.addConfigurationKey(
+ addConfigurationKey(
this,
this.stationInfo.amperageLimitationOcppKey!,
(
).toString(),
);
}
- if (
- !ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.SupportedFeatureProfiles,
- )
- ) {
- ChargingStationConfigurationUtils.addConfigurationKey(
+ if (!getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)) {
+ addConfigurationKey(
this,
StandardParametersKey.SupportedFeatureProfiles,
`${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.FirmwareManagement},${SupportedFeatureProfiles.LocalAuthListManagement},${SupportedFeatureProfiles.SmartCharging},${SupportedFeatureProfiles.RemoteTrigger}`,
);
}
- ChargingStationConfigurationUtils.addConfigurationKey(
+ addConfigurationKey(
this,
StandardParametersKey.NumberOfConnectors,
this.getNumberOfConnectors().toString(),
{ readonly: true },
{ overwrite: true },
);
- if (
- !ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.MeterValuesSampledData,
- )
- ) {
- ChargingStationConfigurationUtils.addConfigurationKey(
+ if (!getConfigurationKey(this, StandardParametersKey.MeterValuesSampledData)) {
+ addConfigurationKey(
this,
StandardParametersKey.MeterValuesSampledData,
MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER,
);
}
- if (
- !ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.ConnectorPhaseRotation,
- )
- ) {
+ if (!getConfigurationKey(this, StandardParametersKey.ConnectorPhaseRotation)) {
const connectorsPhaseRotation: string[] = [];
if (this.hasEvses) {
for (const evseStatus of this.evses.values()) {
);
}
}
- ChargingStationConfigurationUtils.addConfigurationKey(
+ addConfigurationKey(
this,
StandardParametersKey.ConnectorPhaseRotation,
connectorsPhaseRotation.toString(),
);
}
- if (
- !ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.AuthorizeRemoteTxRequests,
- )
- ) {
- ChargingStationConfigurationUtils.addConfigurationKey(
- this,
- StandardParametersKey.AuthorizeRemoteTxRequests,
- 'true',
- );
- }
- if (
- !ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.LocalAuthListEnabled,
- ) &&
- ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.SupportedFeatureProfiles,
- )?.value?.includes(SupportedFeatureProfiles.LocalAuthListManagement)
- ) {
- ChargingStationConfigurationUtils.addConfigurationKey(
- this,
- StandardParametersKey.LocalAuthListEnabled,
- 'false',
- );
+ if (!getConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests)) {
+ addConfigurationKey(this, StandardParametersKey.AuthorizeRemoteTxRequests, 'true');
}
if (
- !ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.ConnectionTimeOut,
+ !getConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled) &&
+ getConfigurationKey(this, StandardParametersKey.SupportedFeatureProfiles)?.value?.includes(
+ SupportedFeatureProfiles.LocalAuthListManagement,
)
) {
- ChargingStationConfigurationUtils.addConfigurationKey(
+ addConfigurationKey(this, StandardParametersKey.LocalAuthListEnabled, 'false');
+ }
+ if (!getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)) {
+ addConfigurationKey(
this,
StandardParametersKey.ConnectionTimeOut,
Constants.DEFAULT_CONNECTION_TIMEOUT.toString(),
if (!existsSync(dirname(this.configurationFile))) {
mkdirSync(dirname(this.configurationFile), { recursive: true });
}
- let configurationData: ChargingStationConfiguration =
- cloneObject<ChargingStationConfiguration>(this.getConfigurationFromFile()!) ?? {};
+ let configurationData: ChargingStationConfiguration = this.getConfigurationFromFile()
+ ? cloneObject<ChargingStationConfiguration>(this.getConfigurationFromFile()!)
+ : {};
if (this.getStationInfoPersistentConfiguration() && this.stationInfo) {
configurationData.stationInfo = this.stationInfo;
} else {
// 0 for disabling
private getConnectionTimeout(): number {
- if (
- ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.ConnectionTimeOut,
- )
- ) {
+ if (getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)) {
return (
- parseInt(
- ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.ConnectionTimeOut,
- )!.value!,
- ) ?? Constants.DEFAULT_CONNECTION_TIMEOUT
+ parseInt(getConfigurationKey(this, StandardParametersKey.ConnectionTimeOut)!.value!) ??
+ Constants.DEFAULT_CONNECTION_TIMEOUT
);
}
return Constants.DEFAULT_CONNECTION_TIMEOUT;
private getAmperageLimitation(): number | undefined {
if (
isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
- ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- this.stationInfo.amperageLimitationOcppKey!,
- )
+ getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)
) {
return (
convertToInt(
- ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- this.stationInfo.amperageLimitationOcppKey!,
- )?.value,
+ getConfigurationKey(this, this.stationInfo.amperageLimitationOcppKey!)?.value,
) / getAmperageLimitationUnitDivider(this.stationInfo)
);
}
}
private startWebSocketPing(): void {
- const webSocketPingInterval: number = ChargingStationConfigurationUtils.getConfigurationKey(
+ const webSocketPingInterval: number = getConfigurationKey(
this,
StandardParametersKey.WebSocketPingInterval,
)
- ? convertToInt(
- ChargingStationConfigurationUtils.getConfigurationKey(
- this,
- StandardParametersKey.WebSocketPingInterval,
- )?.value,
- )
+ ? convertToInt(getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value)
: 0;
if (webSocketPingInterval > 0 && !this.webSocketPingSetInterval) {
this.webSocketPingSetInterval = setInterval(() => {