Smart Charging - test excluded charging stations
MODIFY
test/api/SmartChargingTest.ts
test/api/SmartChargingTest.ts
@@ -5,7 +5,7 @@ import { StaticLimitAmps, Voltage } from '../../src/types/ChargingStation';
import Transaction, { CSPhasesUsed } from '../../src/types/Transaction';
import chai, { assert, expect } from 'chai';
-import AssetStorage from '../../src//storage/mongodb/AssetStorage';
+import AssetStorage from '../../src/storage/mongodb/AssetStorage';
import CentralServerService from './client/CentralServerService';
import { ChargingProfile } from '../../src/types/ChargingProfile';
import ChargingStationContext from './context/ChargingStationContext';
@@ -14,7 +14,9 @@ import Constants from '../../src/utils/Constants';
import ContextDefinition from './context/ContextDefinition';
import ContextProvider from './context/ContextProvider';
import Cypher from '../../src/utils/Cypher';
+import LoggingStorage from '../../src/storage/mongodb/LoggingStorage';
import MongoDBStorage from '../../src/storage/mongodb/MongoDBStorage';
+import { ServerAction } from '../../src/types/Server';
import SiteAreaContext from './context/SiteAreaContext';
import SiteContext from './context/SiteContext';
import SmartChargingFactory from '../../src/integration/smart-charging/SmartChargingFactory';
@@ -421,6 +423,18 @@ describe('Smart Charging Service', function() {
expect(chargingProfiles[2].profile.chargingSchedule.chargingSchedulePeriod).containSubset(limit32);
});
+ it('Test if single phased charging station is excluded from root fuse correctly', async () => {
+ await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea(), [testData.chargingStationContext1.getChargingStation().id]);
+ // Get the log of the site area limitation adjustment and check the root fuse
+ const log = await LoggingStorage.getLogs(testData.tenantContext.getTenant().id, { actions: [ServerAction.SMART_CHARGING], search: 'currently being used' }, Constants.DB_PARAMS_SINGLE_RECORD, null);
+ const siteArea = testData.siteAreaContext.getSiteArea();
+ const siteAreaLimitPerPhase = Utils.createDecimal(siteArea.maximumPower).div(siteArea.voltage).div(3).toNumber();
+ const connectorLimit = Utils.createDecimal(Utils.getChargingStationAmperage(testData.chargingStationContext1.getChargingStation(), null, 1)).toNumber();
+ expect(log.result[0].detailedMessages).include('"fusePhase1": ' + (siteAreaLimitPerPhase - connectorLimit));
+ expect(log.result[0].detailedMessages).include('"fusePhase2": ' + siteAreaLimitPerPhase);
+ expect(log.result[0].detailedMessages).include('"fusePhase3": ' + siteAreaLimitPerPhase);
+ });
+
it('Test for 3 single phased cars charging with lower site area limit and one car on a single phased station (meter value received)', async () => {
// Send meter values for both connectors of the 3 phased stations
await TestData.sendMeterValue(Voltage.VOLTAGE_230, 32, transaction, testData.chargingStationContext, { csPhase1: false, csPhase2: true, csPhase3: false });
@@ -652,6 +666,16 @@ describe('Smart Charging Service', function() {
expect(chargingProfiles[0].profile.chargingSchedule.chargingSchedulePeriod).containSubset(limit32);
});
+ it('Test if one charging connector is excluded from root fuse when charging station is excluded', async () => {
+ await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea(), [testData.chargingStationContext.getChargingStation().id]);
+ const log = await LoggingStorage.getLogs(testData.tenantContext.getTenant().id, { actions: [ServerAction.SMART_CHARGING], search: 'currently being used' }, Constants.DB_PARAMS_SINGLE_RECORD, null);
+ const siteArea = testData.siteAreaContext.getSiteArea();
+ expect(log.result[0].detailedMessages).include('"fusePhase1": ' +
+ Utils.createDecimal(siteArea.maximumPower).div(siteArea.voltage).minus(
+ Utils.getChargingStationAmperage(testData.chargingStationContext.getChargingStation(), null, 1)).toNumber()
+ );
+ });
+
it('Test for two cars charging', async () => {
const transactionStartResponse = await testData.chargingStationContext.startTransaction(2, testData.userContext.tags[0].id, 180, new Date);
const transactionResponse = await testData.centralUserService.transactionApi.readById(transactionStartResponse.transactionId);
@@ -664,6 +688,16 @@ describe('Smart Charging Service', function() {
expect(chargingProfiles[1].profile.chargingSchedule.chargingSchedulePeriod).containSubset(limit32);
});
+ it('Test if both charging connectors are excluded from root fuse when charging station is excluded', async () => {
+ await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea(), [testData.chargingStationContext.getChargingStation().id]);
+ const log = await LoggingStorage.getLogs(testData.tenantContext.getTenant().id, { actions: [ServerAction.SMART_CHARGING], search: 'currently being used' }, Constants.DB_PARAMS_SINGLE_RECORD, null);
+ const siteArea = testData.siteAreaContext.getSiteArea();
+ expect(log.result[0].detailedMessages).include('"fusePhase1": ' +
+ Utils.createDecimal(siteArea.maximumPower).div(siteArea.voltage).minus(
+ Utils.getChargingStationAmperage(testData.chargingStationContext.getChargingStation())).toNumber()
+ );
+ });
+
it('Test for two cars charging with lower site area limit', async () => {
testData.siteAreaContext.getSiteArea().maximumPower = 10000;
const chargingProfiles = await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea());
@@ -854,6 +888,17 @@ describe('Smart Charging Service', function() {
]);
});
+ it('Test if whole charge point is excluded from root fuse when charging station is excluded (one connector charging)', async () => {
+ await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea(), [testData.chargingStationContext.getChargingStation().id]);
+ const log = await LoggingStorage.getLogs(testData.tenantContext.getTenant().id, { actions: [ServerAction.SMART_CHARGING], search: 'currently being used' }, Constants.DB_PARAMS_SINGLE_RECORD, null);
+ const siteArea = testData.siteAreaContext.getSiteArea();
+ const siteAreaLimitPerPhase = Utils.createDecimal(siteArea.maximumPower).div(siteArea.voltage).div(3).toNumber();
+ const connectorLimitPerPhase = Utils.createDecimal(Utils.getChargingStationAmperage(testData.chargingStationContext.getChargingStation())).div(3).toNumber();
+ expect(log.result[0].detailedMessages).include('"fusePhase1": ' + (siteAreaLimitPerPhase - connectorLimitPerPhase));
+ expect(log.result[0].detailedMessages).include('"fusePhase2": ' + (siteAreaLimitPerPhase - connectorLimitPerPhase));
+ expect(log.result[0].detailedMessages).include('"fusePhase3": ' + (siteAreaLimitPerPhase - connectorLimitPerPhase));
+ });
+
it('Test for two cars charging', async () => {
const transactionStartResponse = await testData.chargingStationContext.startTransaction(2, testData.userContext.tags[0].id, 180, new Date);
const transactionResponse = await testData.centralUserService.transactionApi.readById(transactionStartResponse.transactionId);
@@ -892,6 +937,17 @@ describe('Smart Charging Service', function() {
]);
});
+ it('Test if only charge point is excluded from root fuse when charging station is excluded (two connectors charging)', async () => {
+ await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea(), [testData.chargingStationContext.getChargingStation().id]);
+ const log = await LoggingStorage.getLogs(testData.tenantContext.getTenant().id, { actions: [ServerAction.SMART_CHARGING], search: 'currently being used' }, Constants.DB_PARAMS_SINGLE_RECORD, null);
+ const siteArea = testData.siteAreaContext.getSiteArea();
+ const siteAreaLimitPerPhase = Utils.createDecimal(siteArea.maximumPower).div(siteArea.voltage).div(3).toNumber();
+ const connectorLimitPerPhase = Utils.createDecimal(Utils.getChargingStationAmperage(testData.chargingStationContext.getChargingStation())).div(3).toNumber();
+ expect(log.result[0].detailedMessages).include('"fusePhase1": ' + (siteAreaLimitPerPhase - connectorLimitPerPhase));
+ expect(log.result[0].detailedMessages).include('"fusePhase2": ' + (siteAreaLimitPerPhase - connectorLimitPerPhase));
+ expect(log.result[0].detailedMessages).include('"fusePhase3": ' + (siteAreaLimitPerPhase - connectorLimitPerPhase));
+ });
+
it('Test for two cars charging with lower site area limit', async () => {
testData.siteAreaContext.getSiteArea().maximumPower = 100000;
const chargingProfiles = await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea());
@@ -1074,7 +1130,8 @@ describe('Smart Charging Service', function() {
});
});
});
- describe('Test for ChargingStation refusing the charging profile', () => {
+
+ describe('Test limit adjustments, when charging stations are excluded', () => {
before(async () => {
testData.siteContext = testData.tenantContext.getSiteContext(ContextDefinition.SITE_CONTEXTS.SITE_BASIC);
testData.siteAreaContext = testData.siteContext.getSiteAreaContext(ContextDefinition.SITE_AREA_CONTEXTS.WITH_SMART_CHARGING_THREE_PHASED);
@@ -1084,17 +1141,19 @@ describe('Smart Charging Service', function() {
after(async () => {
chargingStationConnector1Available.timestamp = new Date().toISOString();
+ chargingStationConnector2Available.timestamp = new Date().toISOString();
await testData.chargingStationContext.setConnectorStatus(chargingStationConnector1Available);
+ await testData.chargingStationContext.setConnectorStatus(chargingStationConnector2Available);
await testData.chargingStationContext1.setConnectorStatus(chargingStationConnector1Available);
-
+ await testData.chargingStationContext1.setConnectorStatus(chargingStationConnector2Available);
// Reset modifications on siteArea
testData.siteAreaContext.getSiteArea().smartCharging = false;
await testData.userService.siteAreaApi.update(testData.siteAreaContext.getSiteArea());
});
-
- it('Check if charging station will be excluded from smart charging, when pushing fails', async () => {
- testData.siteAreaContext.getSiteArea().maximumPower = 200000;
+ it('Check if one charging connector of three phased charging station will be excluded from smart charging on three phased site area', async () => {
+ testData.siteAreaContext.getSiteArea().maximumPower = 22080 +
+ Utils.createDecimal(limitMinThreePhased[0].limit).mul(testData.siteAreaContext.getSiteArea().voltage).toNumber() ;
testData.siteAreaContext.getSiteArea().smartCharging = true;
await testData.userService.siteAreaApi.update(testData.siteAreaContext.getSiteArea());
await testData.chargingStationContext.startTransaction(1, testData.userContext.tags[0].id, 180, new Date);
@@ -1104,7 +1163,36 @@ describe('Smart Charging Service', function() {
await testData.chargingStationContext1.setConnectorStatus(chargingStationConnector1Charging);
const chargingProfiles = await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea(),
[testData.chargingStationContext.getChargingStation().id]);
- expect(chargingProfiles[0].profile.chargingSchedule.chargingSchedulePeriod).containSubset(limit32);
+ expect(chargingProfiles.length).to.be.eq(1);
+ expect(chargingProfiles[0].profile.chargingSchedule.chargingSchedulePeriod).containSubset(limitMinSinglePhased);
+ });
+
+ it('Check if one charging connector of single phased station will be excluded only on one phase on three phased site area', async () => {
+ const chargingProfiles = await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea(),
+ [testData.chargingStationContext1.getChargingStation().id]);
+ expect(chargingProfiles.length).to.be.eq(1);
+ expect(chargingProfiles[0].profile.chargingSchedule.chargingSchedulePeriod).containSubset(limitMinThreePhased);
+ });
+
+ it('Check if two charging connectors of three phased charging station will be excluded only on one phase on three phased site area', async () => {
+ await testData.chargingStationContext.startTransaction(2, testData.userContext.tags[0].id, 180, new Date);
+ chargingStationConnector2Charging.timestamp = new Date().toISOString();
+ await testData.chargingStationContext.setConnectorStatus(chargingStationConnector2Charging);
+ const chargingProfiles = await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea(),
+ [testData.chargingStationContext.getChargingStation().id]);
+ expect(chargingProfiles.length).to.be.eq(1);
+ expect(chargingProfiles[0].profile.chargingSchedule.chargingSchedulePeriod).containSubset(limit0);
+ });
+
+ it('Check if two charging connectors of single phased charging station will be excluded only on one phase on three phased site area', async () => {
+ await testData.chargingStationContext1.startTransaction(2, testData.userContext.tags[0].id, 180, new Date);
+ chargingStationConnector2Charging.timestamp = new Date().toISOString();
+ await testData.chargingStationContext1.setConnectorStatus(chargingStationConnector2Charging);
+ const chargingProfiles = await smartChargingIntegration.buildChargingProfiles(testData.siteAreaContext.getSiteArea(),
+ [testData.chargingStationContext1.getChargingStation().id]);
+ expect(chargingProfiles.length).to.be.eq(2);
+ expect(chargingProfiles[0].profile.chargingSchedule.chargingSchedulePeriod).containSubset(limit0);
+ expect(chargingProfiles[1].profile.chargingSchedule.chargingSchedulePeriod).containSubset(limit0);
});
});

Smart Charging - test excluded charging stations