[EMSP] Send removed status when switching charging status from public to private
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -476,6 +476,35 @@ export default class CpoOCPIClient extends OCPIClient {
});
}
+ async removeChargingStation(chargingStation: ChargingStation) {
+ if (!chargingStation.siteAreaID && !chargingStation.siteArea) {
+ throw new BackendError({
+ source: chargingStation.id,
+ action: ServerAction.OCPI_PATCH_STATUS,
+ message: 'Charging Station must be associated to a site area',
+ module: MODULE_NAME, method: 'removeChargingStation',
+ });
+ }
+ if (!chargingStation.issuer) {
+ throw new BackendError({
+ source: chargingStation.id,
+ action: ServerAction.OCPI_PATCH_STATUS,
+ message: 'Only charging Station issued locally can be exposed to IOP',
+ module: MODULE_NAME, method: 'removeChargingStation',
+ });
+ }
+ let siteID;
+ if (!chargingStation.siteArea || !chargingStation.siteArea.siteID) {
+ const siteArea = await SiteAreaStorage.getSiteArea(this.tenant.id, chargingStation.siteAreaID);
+ siteID = siteArea ? siteArea.siteID : null;
+ } else {
+ siteID = chargingStation.siteArea.siteID;
+ }
+ for (const connector of chargingStation.connectors) {
+ await this.patchEVSEStatus(siteID, OCPIUtils.buildEvseUID(chargingStation, connector), OCPIEvseStatus.REMOVED);
+ }
+ }
+
async patchChargingStationStatus(chargingStation: ChargingStation, connector: Connector) {
if (!chargingStation.siteAreaID && !chargingStation.siteArea) {
throw new BackendError({

MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
@@ -34,6 +34,10 @@ import UserToken from '../../../types/UserToken';
import Utils from '../../../utils/Utils';
import UtilsService from './UtilsService';
import fs from 'fs';
+import TenantStorage from '../../../storage/mongodb/TenantStorage';
+import OCPIClientFactory from '../../../client/ocpi/OCPIClientFactory';
+import { OCPIRole } from '../../../types/ocpi/OCPIRole';
+import CpoOCPIClient from '../../../client/ocpi/CpoOCPIClient';
const MODULE_NAME = 'ChargingStationService';
@@ -71,6 +75,27 @@ export default class ChargingStationService {
chargingStation.maximumPower = filteredRequest.maximumPower;
}
if (Utils.objectHasProperty(filteredRequest, 'public')) {
+ if (filteredRequest.public === false && filteredRequest.public !== chargingStation.public) {
+ // Remove charging station from ocpi
+ if (Utils.isComponentActiveFromToken(req.user, TenantComponents.OCPI)) {
+ const tenant = await TenantStorage.getTenant(req.user.tenantID);
+ try {
+ const ocpiClient: CpoOCPIClient = await OCPIClientFactory.getAvailableOcpiClient(tenant, OCPIRole.CPO) as CpoOCPIClient;
+ if (ocpiClient) {
+ await ocpiClient.removeChargingStation(chargingStation);
+ }
+ } catch (error) {
+ Logging.logError({
+ tenantID: req.user.tenantID,
+ module: MODULE_NAME, method: 'handleUpdateChargingStationParams',
+ action: action,
+ user: req.user,
+ message: `Unable to remove charging station ${chargingStation.id} from IOP`,
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ }
+ }
+ }
chargingStation.public = filteredRequest.public;
}
if (Utils.objectHasProperty(filteredRequest, 'excludeFromSmartCharging')) {

[EMSP] Send removed status when switching charging status from public to private