key,
caseInsensitive,
);
- if (keyFound && chargingStation.ocppConfiguration?.configurationKey) {
- chargingStation.ocppConfiguration.configurationKey[
- chargingStation.ocppConfiguration.configurationKey.indexOf(keyFound)
+ if (keyFound) {
+ chargingStation.ocppConfiguration!.configurationKey![
+ chargingStation.ocppConfiguration!.configurationKey!.indexOf(keyFound)
].value = value;
chargingStation.saveOcppConfiguration();
} else {
? getMaxNumberOfConnectors(stationTemplate.Connectors) - 1
: getMaxNumberOfConnectors(stationTemplate.Connectors);
} else if (stationTemplate.Evses && !stationTemplate.Connectors) {
- configuredMaxConnectors = 0;
for (const evse in stationTemplate.Evses) {
if (evse === '0') {
continue;
): GetConfigurationResponse {
const configurationKey: OCPPConfigurationKey[] = [];
const unknownKey: string[] = [];
- if (
- chargingStation.ocppConfiguration?.configurationKey &&
- isUndefined(commandPayload.key) === true
- ) {
- for (const configuration of chargingStation.ocppConfiguration.configurationKey) {
+ if (isUndefined(commandPayload.key) === true) {
+ for (const configuration of chargingStation.ocppConfiguration!.configurationKey!) {
if (isUndefined(configuration.visible) === true) {
configuration.visible = true;
}
value: configuration.value,
});
}
- } else if (commandPayload.key && isNotEmptyArray(commandPayload.key) === true) {
- for (const key of commandPayload.key) {
+ } else if (isNotEmptyArray(commandPayload.key) === true) {
+ for (const key of commandPayload.key!) {
const keyFound = ChargingStationConfigurationUtils.getConfigurationKey(
chargingStation,
key,
:visibility="state.isIdTagModalVisible"
:id-tag="state.idTag"
@close="hideIdTagModal()"
- @done="Utils.compose(state.transaction, hideIdTagModal)()"
+ @done="compose(state.transaction, hideIdTagModal)()"
>
Start Transaction
</IdTagInputModal> -->
// import IdTagInputModal from './IdTagInputModal.vue';
import type { ConnectorStatus } from '@/types';
import UIClient from '@/composables/UIClient';
-// import Utils from '@/composables/Utils';
+// import { compose } from '@/composables/Utils';
const props = defineProps<{
hashId: string;
// import { reactive } from 'vue';
import CSConnector from './CSConnector.vue';
import type { ChargingStationData, ChargingStationInfo, ConnectorStatus } from '@/types';
-import Utils from '@/composables/Utils';
+import { ifUndefined } from '@/composables/Utils';
const props = defineProps<{
chargingStation: ChargingStationData;
return getInfo().hashId;
}
function getId(): string {
- return Utils.ifUndefined<string>(getInfo().chargingStationId, 'Ø');
+ return ifUndefined<string>(getInfo().chargingStationId, 'Ø');
}
function getModel(): string {
return getInfo().chargePointModel;
return getInfo().chargePointVendor;
}
function getFirmwareVersion(): string {
- return Utils.ifUndefined<string>(getInfo().firmwareVersion, 'Ø');
+ return ifUndefined<string>(getInfo().firmwareVersion, 'Ø');
}
function getStarted(): string {
return props.chargingStation.started === true ? 'Yes' : 'No';
-import Utils from './Utils';
+import { promiseWithTimeout } from './Utils';
import {
ProcedureName,
type ProtocolResponse,
data: RequestPayload
): Promise<ResponsePayload> {
let uuid: string;
- return Utils.promiseWithTimeout(
+ return promiseWithTimeout(
new Promise((resolve, reject) => {
uuid = crypto.randomUUID();
const msg = JSON.stringify([uuid, command, data]);
import util from 'node:util';
-export default class Utils {
- // STATE
- public static isUndefined(value: unknown): boolean {
- return typeof value === 'undefined';
+const isUndefined = (value: unknown): boolean => {
+ return typeof value === 'undefined';
+};
+
+export const ifUndefined = <T>(value: T | undefined, isValue: T): T => {
+ if (isUndefined(value) === true) return isValue;
+ return value as T;
+};
+
+// const isIterable = <T>(obj: T): boolean => {
+// if (obj === null || obj === undefined) {
+// return false;
+// }
+// return typeof (obj as unknown as Iterable<T>)[Symbol.iterator] === 'function';
+// };
+
+// const ifNotIterableDo = <T>(obj: T, cb: () => void): void => {
+// if (isIterable(obj) === false) cb();
+// };
+
+const isPromisePending = (promise: Promise<unknown>): boolean => {
+ return util.inspect(promise).includes('pending');
+};
+
+export const promiseWithTimeout = <T>(
+ promise: Promise<T>,
+ timeoutMs: number,
+ timeoutError: Error,
+ timeoutCallback: () => void = () => {
+ /* This is intentional */
}
-
- public static ifUndefined<T>(value: T | undefined, isValue: T): T {
- if (Utils.isUndefined(value) === true) return isValue;
- return value as T;
- }
-
- public static isIterable<T>(obj: T): boolean {
- if (obj === null || obj === undefined) {
- return false;
- }
- return typeof (obj as unknown as Iterable<T>)[Symbol.iterator] === 'function';
- }
-
- // public static ifNotIterableDo<T>(obj: T, cb: () => void): void {
- // if (this.isIterable(obj) === false) cb();
- // }
-
- public static isPromisePending(promise: Promise<unknown>): boolean {
- return util.inspect(promise).includes('pending');
- }
-
- public static async promiseWithTimeout<T>(
- promise: Promise<T>,
- timeoutMs: number,
- timeoutError: Error,
- timeoutCallback: () => void = () => {
- /* This is intentional */
- }
- ): Promise<T> {
- // Create a timeout promise that rejects in timeout milliseconds
- const timeoutPromise = new Promise<never>((_, reject) => {
- setTimeout(() => {
- if (Utils.isPromisePending(promise)) {
- timeoutCallback();
- // FIXME: The original promise shall be canceled
- }
- reject(timeoutError);
- }, timeoutMs);
- });
-
- // Returns a race between timeout promise and the passed promise
- return Promise.race<T>([promise, timeoutPromise]);
- }
-
- // FUNCTIONAL
- // public static compose<T>(...fns: ((arg: T) => T)[]): (x: T) => T {
- // return (x: T) => fns.reduceRight((y, fn) => fn(y), x);
- // }
-}
+): Promise<T> => {
+ // Create a timeout promise that rejects in timeout milliseconds
+ const timeoutPromise = new Promise<never>((_, reject) => {
+ setTimeout(() => {
+ if (isPromisePending(promise)) {
+ timeoutCallback();
+ // FIXME: The original promise shall be canceled
+ }
+ reject(timeoutError);
+ }, timeoutMs);
+ });
+
+ // Returns a race between timeout promise and the passed promise
+ return Promise.race<T>([promise, timeoutPromise]);
+};
+
+// export const compose = <T>(...fns: ((arg: T) => T)[]): ((x: T) => T) => {
+// return (x: T) => fns.reduceRight((y, fn) => fn(y), x);
+// };