@citrineos/configuration
Version:
The configuration module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.
136 lines • 6.75 kB
JavaScript
;
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceModelService = void 0;
const base_1 = require("@citrineos/base");
class DeviceModelService {
constructor(deviceModelRepository) {
this._deviceModelRepository = deviceModelRepository;
}
/**
* Fetches the ItemsPerMessageSetVariables attribute from the device model.
* Returns null if no such attribute exists.
* It is possible for there to be multiple ItemsPerMessageSetVariables attributes if component instances or evses
* are associated with alternate options. That structure is not supported by this logic, and that
* structure is a violation of Part 2 - Specification of OCPP 2.0.1.
* In that case, the first attribute will be returned.
* @param stationId Charging station identifier.
* @returns ItemsPerMessageSetVariables as a number or null if no such attribute exists.
*/
getItemsPerMessageSetVariablesByStationId(stationId) {
return __awaiter(this, void 0, void 0, function* () {
const itemsPerMessageSetVariablesAttributes = yield this._deviceModelRepository.readAllByQuerystring({
stationId: stationId,
component_name: 'DeviceDataCtrlr',
variable_name: 'ItemsPerMessage',
variable_instance: 'SetVariables',
type: base_1.OCPP2_0_1.AttributeEnumType.Actual,
});
if (itemsPerMessageSetVariablesAttributes.length === 0) {
return null;
}
else {
// It is possible for itemsPerMessageSetVariablesAttributes.length > 1 if component instances or evses
// are associated with alternate options. That structure is not supported by this logic, and that
// structure is a violation of Part 2 - Specification of OCPP 2.0.1.
return Number(itemsPerMessageSetVariablesAttributes[0].value);
}
});
}
/**
* Fetches the ItemsPerMessageGetVariables attribute from the device model.
* Returns null if no such attribute exists.
* It is possible for there to be multiple ItemsPerMessageGetVariables attributes if component instances or evses
* are associated with alternate options. That structure is not supported by this logic, and that
* structure is a violation of Part 2 - Specification of OCPP 2.0.1.
* In that case, the first attribute will be returned.
* @param stationId Charging station identifier.
* @returns ItemsPerMessageGetVariables as a number or null if no such attribute exists.
*/
getItemsPerMessageGetVariablesByStationId(stationId) {
return __awaiter(this, void 0, void 0, function* () {
const itemsPerMessageGetVariablesAttributes = yield this._deviceModelRepository.readAllByQuerystring({
stationId: stationId,
component_name: 'DeviceDataCtrlr',
variable_name: 'ItemsPerMessage',
variable_instance: 'GetVariables',
type: base_1.OCPP2_0_1.AttributeEnumType.Actual,
});
if (itemsPerMessageGetVariablesAttributes.length === 0) {
return null;
}
else {
// It is possible for itemsPerMessageGetVariablesAttributes.length > 1 if component instances or evses
// are associated with alternate options. That structure is not supported by this logic, and that
// structure is a violation of Part 2 - Specification of OCPP 2.0.1.
return Number(itemsPerMessageGetVariablesAttributes[0].value);
}
});
}
updateDeviceModel(chargingStation, stationId, timestamp) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const attributes = [
{
component: 'ChargingStation',
variable: 'Model',
value: chargingStation.model,
},
{
component: 'ChargingStation',
variable: 'VendorName',
value: chargingStation.vendorName,
},
{
component: 'Controller',
variable: 'FirmwareVersion',
value: chargingStation.firmwareVersion,
},
{
component: 'ChargingStation',
variable: 'SerialNumber',
value: chargingStation.serialNumber,
},
{
component: 'DataLink',
variable: 'IMSI',
value: (_a = chargingStation.modem) === null || _a === void 0 ? void 0 : _a.imsi,
},
{
component: 'DataLink',
variable: 'ICCID',
value: (_b = chargingStation.modem) === null || _b === void 0 ? void 0 : _b.iccid,
},
];
const promises = attributes
.filter((attr) => attr.value !== undefined)
.map((attr) => this._deviceModelRepository.createOrUpdateDeviceModelByStationId({
component: { name: attr.component },
variable: { name: attr.variable },
variableAttribute: [
{
type: base_1.OCPP2_0_1.AttributeEnumType.Actual,
value: attr.value,
mutability: base_1.OCPP2_0_1.MutabilityEnumType.ReadOnly,
persistent: true,
constant: true,
},
],
}, stationId, timestamp));
yield Promise.all(promises);
});
}
}
exports.DeviceModelService = DeviceModelService;
//# sourceMappingURL=DeviceModelService.js.map