feat: expose template name used in stationInfo
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 31 Jan 2024 10:06:38 +0000 (11:06 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 31 Jan 2024 10:06:38 +0000 (11:06 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/types/ChargingStationInfo.ts

index 5c3c13c75d6cc3bec77b2e4f8091c7081611ed65..aa68abdf346cdc251f99cc856708e173a7cc0cb4 100644 (file)
@@ -3,7 +3,7 @@
 import { createHash } from 'node:crypto'
 import { EventEmitter } from 'node:events'
 import { type FSWatcher, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
-import { dirname, join } from 'node:path'
+import { dirname, join, parse } from 'node:path'
 import { URL } from 'node:url'
 import { parentPort } from 'node:worker_threads'
 
@@ -1126,6 +1126,7 @@ export class ChargingStation extends EventEmitter {
     }
     const stationInfo = stationTemplateToStationInfo(stationTemplate)
     stationInfo.hashId = getHashId(this.index, stationTemplate)
+    stationInfo.templateName = parse(this.templateFile).name
     stationInfo.chargingStationId = getChargingStationId(this.index, stationTemplate)
     stationInfo.ocppVersion = stationTemplate.ocppVersion ?? OCPPVersion.VERSION_16
     createSerialNumber(stationTemplate, stationInfo)
@@ -1180,6 +1181,10 @@ export class ChargingStation extends EventEmitter {
       stationInfo = this.getConfigurationFromFile()?.stationInfo
       if (stationInfo != null) {
         delete stationInfo.infoHash
+        // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+        if (stationInfo.templateName == null) {
+          stationInfo.templateName = parse(this.templateFile).name
+        }
       }
     }
     return stationInfo
index 0f4fe97dd33eeb33c5b0034b1993b0e9b5ee07fd..d4e4f8db675c606a613b0488d2b5dede109ae8ce 100644 (file)
@@ -14,6 +14,7 @@ ChargingStationTemplate,
 | 'meterSerialNumberPrefix'
 > & {
   hashId: string
+  templateName: string
   /** @deprecated Use hashId instead */
   infoHash?: string
   chargingStationId?: string