UNPKG

@citrineos/data

Version:

The OCPP data module which includes all persistence layer implementation.

82 lines 3.56 kB
// SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project // // SPDX-License-Identifier: Apache-2.0 import { ChargingProfileKindEnum, ChargingProfilePurposeEnum, ChargingRateUnitEnum, OCPP1_6, RecurrencyKindEnum, } from '@citrineos/base'; export class ChargingProfileMapper { /** * OCPP 1.6 'ChargePointMaxProfile' maps to native 'ChargingStationMaxProfile'. * All other enum values are identical and are type-safe casts. */ static fromChargingProfilePurpose(purpose) { if (purpose === 'ChargePointMaxProfile') { return 'ChargingStationMaxProfile'; } return purpose; } static fromChargingProfileKind(kind) { return kind; } static fromRecurrencyKind(kind) { if (!kind) return undefined; return kind; } static fromChargingRateUnit(unit) { return unit; } /** * Converts an OCPP 1.6 SetChargingProfile csChargingProfiles to a native ChargingProfileInput. */ static fromSetChargingProfileRequest(profile) { return { id: profile.chargingProfileId, stackLevel: profile.stackLevel, chargingProfilePurpose: ChargingProfileMapper.fromChargingProfilePurpose(profile.chargingProfilePurpose), chargingProfileKind: ChargingProfileMapper.fromChargingProfileKind(profile.chargingProfileKind), recurrencyKind: ChargingProfileMapper.fromRecurrencyKind(profile.recurrencyKind), validFrom: profile.validFrom, validTo: profile.validTo, transactionId: profile.transactionId?.toString(), chargingSchedule: [ ChargingProfileMapper.fromChargingSchedule(profile.chargingProfileId, profile.chargingSchedule), ], }; } /** * Converts an OCPP 1.6 RemoteStartTransaction chargingProfile to a native ChargingProfileInput. */ static fromRemoteStartChargingProfile(profile) { return { id: profile.chargingProfileId ?? 0, stackLevel: profile.stackLevel, chargingProfilePurpose: ChargingProfileMapper.fromChargingProfilePurpose(profile.chargingProfilePurpose), chargingProfileKind: ChargingProfileMapper.fromChargingProfileKind(profile.chargingProfileKind), recurrencyKind: ChargingProfileMapper.fromRecurrencyKind(profile.recurrencyKind), validFrom: profile.validFrom, validTo: profile.validTo, transactionId: profile.transactionId?.toString(), chargingSchedule: [ ChargingProfileMapper.fromChargingSchedule(profile.chargingProfileId ?? 0, profile.chargingSchedule), ], }; } /** * Converts an OCPP 1.6 ChargingSchedule to a native ChargingScheduleInput. * Accepts a scheduleId since OCPP 1.6 schedules don't have their own id. */ static fromChargingSchedule(scheduleId, schedule) { return { id: scheduleId, chargingRateUnit: ChargingProfileMapper.fromChargingRateUnit(schedule.chargingRateUnit), chargingSchedulePeriod: schedule.chargingSchedulePeriod.map((period) => ({ startPeriod: period.startPeriod, limit: period.limit, numberPhases: period.numberPhases, })), duration: schedule.duration, startSchedule: schedule.startSchedule, minChargingRate: schedule.minChargingRate, }; } } //# sourceMappingURL=ChargingProfileMapper.js.map