pricing - no dependency to charging station interface
MODIFY
src/integration/pricing/PricingEngine.ts
src/integration/pricing/PricingEngine.ts
@@ -166,8 +166,7 @@ export default class PricingEngine {
private static checkConnectorType(staticRestrictions: PricingStaticRestriction, pricingContext: PricingContext): boolean {
if (!Utils.isNullOrUndefined(staticRestrictions.connectorType)) {
- const connectorType = Utils.getConnectorFromID(pricingContext.chargingStation, pricingContext.connectorId)?.type;
- if (staticRestrictions.connectorType !== connectorType) {
+ if (staticRestrictions.connectorType !== pricingContext.connectorType) {
return false;
}
}
@@ -176,8 +175,7 @@ export default class PricingEngine {
private static checkConnectorPower(staticRestrictions: PricingStaticRestriction, pricingContext: PricingContext): boolean {
if (!Utils.isNullOrUndefined(staticRestrictions.connectorPowerkW)) {
- const connectorPowerWatts = Utils.getConnectorFromID(pricingContext.chargingStation, pricingContext.connectorId)?.power;
- if (!Utils.createDecimal(connectorPowerWatts).div(1000).equals(staticRestrictions.connectorPowerkW)) {
+ if (!Utils.createDecimal(pricingContext.connectorPower).div(1000).equals(staticRestrictions.connectorPowerkW)) {
return false;
}
}

MODIFY
src/integration/pricing/PricingHelper.ts
src/integration/pricing/PricingHelper.ts
@@ -12,6 +12,9 @@ import Utils from '../../utils/Utils';
export default class PricingHelper {
public static buildTransactionPricingContext(tenant: Tenant, transaction: Transaction, chargingStation: ChargingStation): PricingContext {
+ const connectorId = transaction.connectorId ;
+ const connectorType = Utils.getConnectorFromID(chargingStation, connectorId)?.type;
+ const connectorPower = Utils.getConnectorFromID(chargingStation, connectorId)?.power;
return {
tenant,
userID: transaction.userID,
@@ -19,14 +22,17 @@ export default class PricingHelper {
siteID : transaction.siteID,
siteAreaID: transaction.siteAreaID,
chargingStationID : transaction.chargeBoxID,
- connectorId : transaction.connectorId,
+ connectorId,
+ connectorType,
+ connectorPower,
timestamp : transaction.timestamp,
timezone : transaction.timezone,
- chargingStation : chargingStation,
};
}
public static buildUserPricingContext(tenant: Tenant, user: User, chargingStation: ChargingStation, connectorId: number, timestamp: Date): PricingContext {
+ const connectorType = Utils.getConnectorFromID(chargingStation, connectorId)?.type;
+ const connectorPower = Utils.getConnectorFromID(chargingStation, connectorId)?.power;
return {
tenant,
userID: user.id,
@@ -34,18 +40,25 @@ export default class PricingHelper {
siteID : chargingStation.siteID,
siteAreaID: chargingStation.siteAreaID,
chargingStationID : chargingStation.id,
- connectorId : connectorId,
+ connectorId,
+ connectorType,
+ connectorPower,
timestamp,
timezone : Utils.getTimezone(chargingStation.coordinates),
- chargingStation,
};
}
public static checkContextConsistency(pricingContext: PricingContext): boolean {
- if (pricingContext.tenant && pricingContext.userID && pricingContext.companyID && pricingContext.siteID && pricingContext.siteAreaID
- && pricingContext.chargingStationID && pricingContext.chargingStation && pricingContext.chargingStation.coordinates
- && pricingContext.connectorId && pricingContext.timestamp
- && pricingContext.timestamp) {
+ if (pricingContext.tenant
+ && pricingContext.userID
+ && pricingContext.companyID
+ && pricingContext.siteID
+ && pricingContext.siteAreaID
+ && pricingContext.chargingStationID
+ && !Utils.isNullOrUndefined(pricingContext.connectorId)
+ && pricingContext.connectorType
+ && !Utils.isNullOrUndefined(pricingContext.connectorPower)
+ && pricingContext.timestamp && pricingContext.timezone) {
return true;
}
return false;

MODIFY
src/types/Pricing.ts
src/types/Pricing.ts
@@ -29,9 +29,11 @@ export interface PricingContext {
siteAreaID: string,
chargingStationID: string,
connectorId: number,
+ connectorType: ConnectorType,
+ connectorPower: number,
timezone: string,
timestamp: Date,
- chargingStation: ChargingStation
+ // chargingStation: ChargingStation
}
export interface ResolvedPricingModel {

pricing - no dependency to charging station interface