- /**
- * Charging profiles should already be sorted by connectorId and stack level (highest stack level has priority)
- *
- * @param chargingProfiles -
- * @param logPrefix -
- * @returns
- */
- private static getLimitFromChargingProfiles(
- chargingProfiles: ChargingProfile[],
- logPrefix: string
- ): {
- limit: number;
- matchingChargingProfile: ChargingProfile;
- } | null {
- const debugLogMsg = `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Matching charging profile found for power limitation: %j`;
- for (const chargingProfile of chargingProfiles) {
- // Set helpers
- const currentMoment = moment();
- const chargingSchedule = chargingProfile.chargingSchedule;
- // Check type (recurring) and if it is already active
- // Adjust the daily recurring schedule to today
- if (
- chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING &&
- chargingProfile.recurrencyKind === RecurrencyKindType.DAILY &&
- currentMoment.isAfter(chargingSchedule.startSchedule)
- ) {
- const currentDate = new Date();
- chargingSchedule.startSchedule = new Date(chargingSchedule.startSchedule);
- chargingSchedule.startSchedule.setFullYear(
- currentDate.getFullYear(),
- currentDate.getMonth(),
- currentDate.getDate()
+const initializeConnectorStatus = (connectorStatus: ConnectorStatus): void => {
+ connectorStatus.availability = AvailabilityType.Operative;
+ connectorStatus.idTagLocalAuthorized = false;
+ connectorStatus.idTagAuthorized = false;
+ connectorStatus.transactionRemoteStarted = false;
+ connectorStatus.transactionStarted = false;
+ connectorStatus.energyActiveImportRegisterValue = 0;
+ connectorStatus.transactionEnergyActiveImportRegisterValue = 0;
+ if (isUndefined(connectorStatus.chargingProfiles)) {
+ connectorStatus.chargingProfiles = [];
+ }
+};
+
+const warnDeprecatedTemplateKey = (
+ template: ChargingStationTemplate,
+ key: string,
+ logPrefix: string,
+ templateFile: string,
+ logMsgToAppend = ''
+): void => {
+ if (!isUndefined(template[key])) {
+ const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${
+ isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
+ }`;
+ logger.warn(`${logPrefix} ${logMsg}`);
+ console.warn(chalk.yellow(`${logMsg}`));
+ }
+};
+
+const convertDeprecatedTemplateKey = (
+ template: ChargingStationTemplate,
+ deprecatedKey: string,
+ key: string
+): void => {
+ if (!isUndefined(template[deprecatedKey])) {
+ template[key] = template[deprecatedKey] as unknown;
+ delete template[deprecatedKey];
+ }
+};
+
+/**
+ * Charging profiles should already be sorted by connector id and stack level (highest stack level has priority)
+ *
+ * @param chargingProfiles -
+ * @param logPrefix -
+ * @returns
+ */
+const getLimitFromChargingProfiles = (
+ chargingProfiles: ChargingProfile[],
+ logPrefix: string
+): {
+ limit: number;
+ matchingChargingProfile: ChargingProfile;
+} | null => {
+ const debugLogMsg = `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Matching charging profile found for power limitation: %j`;
+ const currentMoment = moment();
+ const currentDate = new Date();
+ for (const chargingProfile of chargingProfiles) {
+ // Set helpers
+ const chargingSchedule = chargingProfile.chargingSchedule;
+ if (!chargingSchedule?.startSchedule) {
+ logger.warn(
+ `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not defined in charging profile id ${chargingProfile.chargingProfileId}`
+ );
+ }
+ // Check type (recurring) and if it is already active
+ // Adjust the daily recurring schedule to today
+ if (
+ chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING &&
+ chargingProfile.recurrencyKind === RecurrencyKindType.DAILY &&
+ currentMoment.isAfter(chargingSchedule.startSchedule)
+ ) {
+ if (!(chargingSchedule?.startSchedule instanceof Date)) {
+ logger.warn(
+ `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not a Date object in charging profile id ${chargingProfile.chargingProfileId}. Trying to convert it to a Date object`