iobroker.eos-admin 9.0.17 → 9.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NEXOWATT_EOS_BUILD_INFO.json +12 -14
- package/README.md +5 -3
- package/START_HIER_9.0.18.md +47 -0
- package/adminWww/.vite/manifest.json +39 -39
- package/adminWww/NEXOWATT_EOS_FRONTEND_MANIFEST.json +107 -107
- package/adminWww/assets/{AdapterUpdateDialog-Cpo3dAfY.js → AdapterUpdateDialog-ByJk9Cxj.js} +1 -1
- package/adminWww/assets/{Adapters-n2ukPDdC.js → Adapters-V2JtEPZX.js} +1 -1
- package/adminWww/assets/{ConfigManager-BVZ6_Ebo.js → ConfigManager-BKcdyJnN.js} +1 -1
- package/adminWww/assets/{Enums-CQ6yHG2W.js → Enums-ChbfAWzp.js} +1 -1
- package/adminWww/assets/{Fields-CaJqzoW-.js → Fields-DzaVXEvg.js} +1 -1
- package/adminWww/assets/{Files-DfvpKGa3.js → Files-CRpIXj4X.js} +1 -1
- package/adminWww/assets/{Hosts-3xLBsdG6.js → Hosts-rOgfd2wo.js} +1 -1
- package/adminWww/assets/{Instances-B7hKEhyw.js → Instances-BxLhJ6Pb.js} +1 -1
- package/adminWww/assets/{Intro-BV4kYZdT.js → Intro-BOql527d.js} +1 -1
- package/adminWww/assets/{Logs-DpL9eY69.js → Logs-WUUDY7a4.js} +1 -1
- package/adminWww/assets/{Objects-dN06jhQk.js → Objects-DYaZkCK7.js} +1 -1
- package/adminWww/assets/{Overview-Lip63_ej.js → Overview-C6hiiPbm.js} +1 -1
- package/adminWww/assets/{State-BSO2X_xN.js → State-AH43l7fG.js} +1 -1
- package/adminWww/assets/{UsedResources-DvqzszKI.js → UsedResources-jhsRMH4X.js} +1 -1
- package/adminWww/assets/{Users-Csqd1xA-.js → Users-D9wyLyJ1.js} +1 -1
- package/adminWww/assets/{bootstrap-C3HM8kNL.js → bootstrap-gVLo1K_2.js} +3 -3
- package/adminWww/assets/{hostInit-DdxBUeXQ.js → hostInit-Dt_M-NAC.js} +1 -1
- package/adminWww/assets/{icons-material-D1Tb_725.js → icons-material-DuVW_EUA.js} +1 -1
- package/adminWww/assets/{index-BOujTMyH.js → index-B1cnPkSO.js} +2 -2
- package/adminWww/assets/{installSVGRenderer-BZyrUVAo.js → installSVGRenderer-GvgHjubR.js} +1 -1
- package/adminWww/assets/{mf-entry-bootstrap-0-3418586b.js → mf-entry-bootstrap-0-6b32b635.js} +2 -2
- package/adminWww/index.html +23 -23
- package/adminWww/mf-manifest.json +1 -1
- package/adminWww/mf-stats.json +1 -1
- package/adminWww/remoteEntry-eos-9.0.18.js +12 -0
- package/adminWww/remoteEntry.js +1 -1
- package/build/lib/eosDeviceEmsPlan.js +739 -0
- package/build/lib/eosDeviceEmsPlan.js.map +1 -0
- package/build/lib/eosDeviceEmsService.js +377 -0
- package/build/lib/eosDeviceEmsService.js.map +1 -0
- package/build/lib/eosModuleHost.js +53 -2
- package/build/lib/eosModuleHost.js.map +1 -1
- package/build/lib/eosModuleHttp.js +1 -1
- package/build/lib/eosModuleHttp.js.map +1 -1
- package/build/lib/web.js +15 -0
- package/build/lib/web.js.map +1 -1
- package/docs/reports/unified-9.0.18/ALIAS_V1_COVERAGE.json +5056 -0
- package/docs/reports/unified-9.0.18/ALIAS_V1_VERTRAG.md +257 -0
- package/docs/reports/unified-9.0.18/ANFORDERUNGEN.md +55 -0
- package/docs/reports/unified-9.0.18/CUSTOMER_TARIFF_REVIEW.md +33 -0
- package/docs/reports/unified-9.0.18/GERAETE_EMS_EINRICHTUNG.md +86 -0
- package/docs/reports/unified-9.0.18/INSTALLER_LIFECYCLE_REVIEW.md +29 -0
- package/docs/reports/unified-9.0.18/KUNDENTARIF_EINRICHTUNG.md +27 -0
- package/docs/reports/unified-9.0.18/PRUEFBERICHT.md +87 -0
- package/docs/reports/unified-9.0.18/UNABHAENGIGER_REVIEW.md +63 -0
- package/docs/reports/unified-9.0.18/raw/INDEX.json +331 -0
- package/docs/reports/unified-9.0.18/raw/audit-full.log +345 -0
- package/docs/reports/unified-9.0.18/raw/audit-full.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/audit-runtime.log +23 -0
- package/docs/reports/unified-9.0.18/raw/audit-runtime.result.json +15 -0
- package/docs/reports/unified-9.0.18/raw/backend-final.log +5 -0
- package/docs/reports/unified-9.0.18/raw/backend-final.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/frontend-build.log +152 -0
- package/docs/reports/unified-9.0.18/raw/frontend-build.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/installer-build.log +26 -0
- package/docs/reports/unified-9.0.18/raw/installer-build.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/keygen-source.json +6 -0
- package/docs/reports/unified-9.0.18/raw/lint-final.log +5 -0
- package/docs/reports/unified-9.0.18/raw/lint-final.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/modules-build.log +5 -0
- package/docs/reports/unified-9.0.18/raw/modules-build.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/node22-tests-final.log +9859 -0
- package/docs/reports/unified-9.0.18/raw/node22-tests-final.result.json +13 -0
- package/docs/reports/unified-9.0.18/raw/node22-typecheck-final.log +7 -0
- package/docs/reports/unified-9.0.18/raw/node22-typecheck-final.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/node22-version.log +1 -0
- package/docs/reports/unified-9.0.18/raw/node24-tests-final.log +1663 -0
- package/docs/reports/unified-9.0.18/raw/node24-tests-final.result.json +13 -0
- package/docs/reports/unified-9.0.18/raw/node24-typecheck-final.log +5 -0
- package/docs/reports/unified-9.0.18/raw/node24-typecheck-final.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/node24-version.log +1 -0
- package/docs/reports/unified-9.0.18/raw/sbom-runtime.log +7 -0
- package/docs/reports/unified-9.0.18/raw/sbom-runtime.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/sbom-vendor-check.log +1 -0
- package/docs/reports/unified-9.0.18/raw/sbom-vendor-check.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/ui-docs-check.log +6 -0
- package/docs/reports/unified-9.0.18/raw/ui-docs-check.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/ui-runtime-final.log +7 -0
- package/docs/reports/unified-9.0.18/raw/ui-runtime-final.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/ui-runtime-sync.log +6 -0
- package/docs/reports/unified-9.0.18/raw/ui-runtime-sync.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/ui-sbom-check.log +6 -0
- package/docs/reports/unified-9.0.18/raw/ui-sbom-check.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/ui-sbom-final.log +14 -0
- package/docs/reports/unified-9.0.18/raw/ui-sbom-final.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/ui-secret-final.log +6 -0
- package/docs/reports/unified-9.0.18/raw/ui-secret-final.result.json +14 -0
- package/docs/reports/unified-9.0.18/raw/ui-security-final.log +8 -0
- package/docs/reports/unified-9.0.18/raw/ui-security-final.result.json +14 -0
- package/io-package.json +8 -8
- package/modules/devices/admin/alias-contract-v1.json +189 -0
- package/modules/devices/admin/ems-assignment.d.ts +10 -0
- package/modules/devices/admin/ems-assignment.js +194 -0
- package/modules/devices/admin/host-bridge.js +47 -0
- package/modules/devices/admin/index.html +19 -1
- package/modules/devices/admin/index_m.js +73 -1
- package/modules/devices/admin/style.css +15 -0
- package/modules/devices/checks/emsAssignment.check.js +128 -0
- package/modules/devices/eslint.hosted.config.mjs +1 -1
- package/modules/devices/index.js +11 -0
- package/modules/devices/lib/alias-contract-v1.json +189 -0
- package/modules/devices/lib/aliasContract.js +7 -1
- package/modules/devices/lib/device-alias-semantics-v1.json +1605 -0
- package/modules/devices/lib/deviceAliasSemantics.js +109 -0
- package/modules/devices/lib/deviceRuntime.js +3 -0
- package/modules/devices/test/aliasContractV1.test.js +1 -1
- package/modules/devices/test/deviceAliasSemantics.test.js +163 -0
- package/modules/devices/test/emsAssignmentUi.test.js +190 -0
- package/modules/devices/tsconfig.alias-semantics.json +17 -0
- package/modules/devices/tsconfig.ems-ui.json +9 -0
- package/package.json +9 -7
- package/release-manifests/unified/build-environment.cdx.json +6 -6
- package/release-manifests/unified/files.json +194 -85
- package/release-manifests/unified/frontend.cdx.json +6 -6
- package/release-manifests/unified/installer.cdx.json +6 -6
- package/release-manifests/unified/obsolete-admin-assets.json +84 -0
- package/release-manifests/unified/runtime.cdx.json +23 -23
- package/release-manifests/unified/validation.json +15 -15
- package/tools/eos-release-check.cjs +1 -1
- package/tools/eos-release-manifest.cjs +5 -5
- package/ui/docs/security/eslint-reviewed-findings.json +32 -18
- package/ui/ems/datapoints.js +22 -1
- package/ui/ems/modules/tariff-provider.js +232 -54
- package/ui/io-package.json +5 -1
- package/ui/lib/customer-tariff.js +241 -0
- package/ui/lib/installer-lifecycle.js +87 -0
- package/ui/main.js +203 -117
- package/ui/package.json +8 -4
- package/ui/www/customer-tariff.css +21 -0
- package/ui/www/customer-tariff.js +333 -0
- package/ui/www/ems-apps.js +16 -6
- package/ui/www/manifest.webmanifest +2 -2
- package/ui/www/settings.html +45 -0
- package/adminWww/remoteEntry-eos-9.0.17.js +0 -12
|
@@ -0,0 +1,739 @@
|
|
|
1
|
+
/* Copyright (c) 2026 NexoWatt. Confidential and proprietary. */
|
|
2
|
+
// @ts-check
|
|
3
|
+
'use strict';
|
|
4
|
+
/**
|
|
5
|
+
* NexoWatt Quellcode-Erklärung (DE)
|
|
6
|
+
* Aufgabe: Plant passende EMS-Zuordnungen aus geprüften Geräte-Aliasdaten.
|
|
7
|
+
* Daten und Wirkung: Arbeitet nur mit Kopien der Konfiguration; führt keine Datenbank- oder Geräteschreibzugriffe aus.
|
|
8
|
+
* Bei Änderungen: Wiederholtes Speichern, Neustart, manuelle Zuordnungen, Lizenz-/Eigentumsentzug und begrenzte Fehlerpfade prüfen.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Deterministic commissioning plan for verified device inventories. This module
|
|
12
|
+
* never accesses the controller, writes states, enables an app, or creates a
|
|
13
|
+
* device command. Its output must pass the normal versioned configuration save.
|
|
14
|
+
* Existing non-empty installer assignments are authoritative.
|
|
15
|
+
* @typedef {import('./eosDeviceEmsPlan').Json} Json
|
|
16
|
+
* @typedef {{[key: string]: Json}} Dict
|
|
17
|
+
* @typedef {{id: string, type: string, unit: string, read: boolean, write: boolean, targetId: string}} Alias
|
|
18
|
+
* @typedef {{baseId: string, devId: string, name: string, templateId: string, deviceClass: string, enabled: boolean, aliases: Map<string, Alias>, ems: Dict, discoveryCode: string}} Device
|
|
19
|
+
* @typedef {{baseId: string, devId: string, status: string, code: string, target: string, mappedFields: string[], missing: string[], optionalMissing: string[]}} Status
|
|
20
|
+
*/
|
|
21
|
+
const MODES = new Set(['auto', 'monitor', 'manual', 'singleStorage', 'storageFarm', 'gridMeter', 'generationMeter', 'consumptionMeter', 'pvInverter']);
|
|
22
|
+
const STORAGE_CLASSES = new Set(['storageSystem', 'battery', 'batteryInverter']);
|
|
23
|
+
const MAX_DEVICES = 256;
|
|
24
|
+
const MAX_CONFIG_BYTES = 2 * 1024 * 1024;
|
|
25
|
+
const MAX_ROWS = 100;
|
|
26
|
+
const { Buffer } = require('node:buffer');
|
|
27
|
+
/** @param {unknown} value @returns {value is Dict} */
|
|
28
|
+
function isRecord(value) {
|
|
29
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) &&
|
|
30
|
+
[Object.prototype, null].includes(Object.getPrototypeOf(value));
|
|
31
|
+
}
|
|
32
|
+
/** @param {unknown} value @returns {Dict} */
|
|
33
|
+
function record(value) { return isRecord(value) ? value : {}; }
|
|
34
|
+
/** @param {unknown} value @returns {string} */
|
|
35
|
+
function text(value) { return typeof value === 'string' ? value.trim() : ''; }
|
|
36
|
+
/** @param {unknown} value @returns {boolean} */
|
|
37
|
+
function empty(value) { return value === undefined || value === null || value === ''; }
|
|
38
|
+
/** @param {string} code @returns {Error & {code: string}} */
|
|
39
|
+
function fail(code) { return Object.assign(new Error(code), { code }); }
|
|
40
|
+
/** Reject malformed/hostile config, rather than substituting an empty config. @param {unknown} value @returns {Dict} */
|
|
41
|
+
function copyConfig(value) {
|
|
42
|
+
if (!isRecord(value))
|
|
43
|
+
throw fail('EOS_EMS_PLAN_CONFIG_INVALID');
|
|
44
|
+
let nodes = 0;
|
|
45
|
+
/** @param {unknown} item @param {number} depth */
|
|
46
|
+
const visit = (item, depth) => {
|
|
47
|
+
if (++nodes > 100000 || depth > 24)
|
|
48
|
+
throw fail('EOS_EMS_PLAN_CONFIG_SIZE');
|
|
49
|
+
if (item === null || typeof item === 'boolean' || typeof item === 'string')
|
|
50
|
+
return;
|
|
51
|
+
if (typeof item === 'number' && Number.isFinite(item))
|
|
52
|
+
return;
|
|
53
|
+
if (Array.isArray(item)) {
|
|
54
|
+
for (const child of item)
|
|
55
|
+
visit(child, depth + 1);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (!isRecord(item))
|
|
59
|
+
throw fail('EOS_EMS_PLAN_CONFIG_INVALID');
|
|
60
|
+
for (const [key, child] of Object.entries(item)) {
|
|
61
|
+
if (['__proto__', 'constructor', 'prototype'].includes(key))
|
|
62
|
+
throw fail('EOS_EMS_PLAN_CONFIG_KEY');
|
|
63
|
+
visit(child, depth + 1);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
visit(value, 0);
|
|
67
|
+
const serialized = JSON.stringify(value);
|
|
68
|
+
if (Buffer.byteLength(serialized) > MAX_CONFIG_BYTES)
|
|
69
|
+
throw fail('EOS_EMS_PLAN_CONFIG_SIZE');
|
|
70
|
+
return /** @type {Dict} */ (JSON.parse(serialized));
|
|
71
|
+
}
|
|
72
|
+
/** @param {Dict} parent @param {string} key @returns {Dict} */
|
|
73
|
+
function section(parent, key) {
|
|
74
|
+
if (!empty(parent[key]) && !isRecord(parent[key]))
|
|
75
|
+
throw fail('EOS_EMS_PLAN_SECTION_INVALID');
|
|
76
|
+
if (!isRecord(parent[key]))
|
|
77
|
+
parent[key] = {};
|
|
78
|
+
return /** @type {Dict} */ (parent[key]);
|
|
79
|
+
}
|
|
80
|
+
/** @param {Dict} parent @param {string} key @param {number} [max] @returns {Dict[]} */
|
|
81
|
+
function rows(parent, key, max = MAX_ROWS) {
|
|
82
|
+
if (parent[key] === undefined)
|
|
83
|
+
parent[key] = [];
|
|
84
|
+
const value = parent[key];
|
|
85
|
+
if (!Array.isArray(value) || value.length > max || value.some(row => !isRecord(row)))
|
|
86
|
+
throw fail('EOS_EMS_PLAN_ROWS_INVALID');
|
|
87
|
+
return /** @type {Dict[]} */ (value);
|
|
88
|
+
}
|
|
89
|
+
/** Only actual Alias V1 objects verified by the caller are accepted. @param {unknown} raw @returns {Device} */
|
|
90
|
+
function device(raw) {
|
|
91
|
+
const row = record(raw);
|
|
92
|
+
const baseId = text(row.baseId);
|
|
93
|
+
const devId = text(row.devId || row.deviceId);
|
|
94
|
+
if (!/^(?:eos-admin|nexowatt-devices)\.\d+\.devices\.[A-Za-z0-9_.-]+$/.test(baseId) || baseId.length > 450 ||
|
|
95
|
+
!devId || devId.length > 128 || !baseId.endsWith(`.devices.${devId}`))
|
|
96
|
+
throw fail('EOS_EMS_PLAN_DEVICE_INVALID');
|
|
97
|
+
const ems = record(row.ems);
|
|
98
|
+
if (ems.mode !== undefined && !MODES.has(text(ems.mode)))
|
|
99
|
+
throw fail('EOS_EMS_PLAN_INTENT_INVALID');
|
|
100
|
+
if (ems.scope !== undefined && !['M0', 'M1'].includes(text(ems.scope)))
|
|
101
|
+
throw fail('EOS_EMS_PLAN_INTENT_INVALID');
|
|
102
|
+
if (ems.flowSlot !== undefined && (!Number.isInteger(ems.flowSlot) || Number(ems.flowSlot) < 0 || Number(ems.flowSlot) > 10)) {
|
|
103
|
+
throw fail('EOS_EMS_PLAN_INTENT_INVALID');
|
|
104
|
+
}
|
|
105
|
+
const aliases = new Map();
|
|
106
|
+
const metadata = record(row.aliasMeta);
|
|
107
|
+
if (Object.keys(metadata).length > 512)
|
|
108
|
+
throw fail('EOS_EMS_PLAN_ALIAS_LIMIT');
|
|
109
|
+
for (const [key, item] of Object.entries(metadata)) {
|
|
110
|
+
const meta = record(item);
|
|
111
|
+
const id = text(meta.id);
|
|
112
|
+
if (!/^(?:r|ctrl|comm|alarm)\.[A-Za-z0-9_.]+$/.test(key) || id !== `${baseId}.aliases.v1.${key}`)
|
|
113
|
+
continue;
|
|
114
|
+
if (!['number', 'boolean', 'string'].includes(text(meta.type)))
|
|
115
|
+
continue;
|
|
116
|
+
const target = text(meta.targetId);
|
|
117
|
+
if (target.length > 512 || [...target].some(character => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127))
|
|
118
|
+
continue;
|
|
119
|
+
aliases.set(key, { id, type: text(meta.type), unit: text(meta.unit), read: meta.read !== false,
|
|
120
|
+
write: meta.write === true, targetId: target || id });
|
|
121
|
+
}
|
|
122
|
+
return { baseId, devId, name: text(row.name).slice(0, 128) || devId, templateId: text(row.templateId), deviceClass: text(row.deviceClass),
|
|
123
|
+
enabled: row.enabled !== false, aliases, ems, discoveryCode: text(row.discoveryCode) };
|
|
124
|
+
}
|
|
125
|
+
/** @param {Device} dev @param {string[]} keys @param {boolean} [write] @param {string[]} [types] @param {string[]} [units] @returns {string} */
|
|
126
|
+
function alias(dev, keys, write = false, types = ['number'], units = []) {
|
|
127
|
+
for (const key of keys) {
|
|
128
|
+
const meta = dev.aliases.get(key);
|
|
129
|
+
if (!meta || (write ? !meta.write : !meta.read) || !types.includes(meta.type))
|
|
130
|
+
continue;
|
|
131
|
+
if (units.length && !units.includes(meta.unit))
|
|
132
|
+
continue;
|
|
133
|
+
return meta.id;
|
|
134
|
+
}
|
|
135
|
+
return '';
|
|
136
|
+
}
|
|
137
|
+
/** @param {Device} dev @param {string} mode @returns {Dict} */
|
|
138
|
+
function identity(dev, mode) { return { v: 1, baseId: dev.baseId, devId: dev.devId, mode }; }
|
|
139
|
+
/** @param {Dict} row @param {Device} dev @returns {boolean} */
|
|
140
|
+
function belongs(row, dev) {
|
|
141
|
+
const owner = record(row._eosDevice);
|
|
142
|
+
if (owner.v === 1 && owner.baseId === dev.baseId)
|
|
143
|
+
return true;
|
|
144
|
+
return Object.entries(row).some(([key, value]) => /(?:Id|ObjectId)$/.test(key) &&
|
|
145
|
+
typeof value === 'string' && value.startsWith(`${dev.baseId}.`));
|
|
146
|
+
}
|
|
147
|
+
/** @param {Dict} row @param {string} key @param {Json|undefined} value @param {Status} result */
|
|
148
|
+
function fill(row, key, value, result) {
|
|
149
|
+
if (value === undefined || value === '' || !empty(row[key]))
|
|
150
|
+
return;
|
|
151
|
+
row[key] = value;
|
|
152
|
+
result.mappedFields.push(key);
|
|
153
|
+
}
|
|
154
|
+
/** @param {Device} dev @returns {Status} */
|
|
155
|
+
function status(dev) { return { baseId: dev.baseId, devId: dev.devId, status: 'pending', code: 'ALIASES_PENDING', target: '', mappedFields: [], missing: [], optionalMissing: [] }; }
|
|
156
|
+
/** An entered power value is not an object ID. Keep it for correction, never resolve it as a DP. @param {unknown} value */
|
|
157
|
+
function numericReference(value) { return typeof value === 'number' || (typeof value === 'string' && /^[+-]?\d+(?:[.,]\d+)?$/.test(value.trim())); }
|
|
158
|
+
/** Only bounded configuration reference strings, never secrets or values, enter conflict detection. @param {unknown} value @returns {string[]} */
|
|
159
|
+
function mappedIds(value) {
|
|
160
|
+
const found = new Set();
|
|
161
|
+
let visited = 0;
|
|
162
|
+
/** @param {unknown} item @param {number} depth */
|
|
163
|
+
const walk = (item, depth) => {
|
|
164
|
+
if (!item || typeof item !== 'object' || depth > 12 || ++visited > 20000)
|
|
165
|
+
return;
|
|
166
|
+
for (const [key, child] of Object.entries(item)) {
|
|
167
|
+
if (key === '_eosDevice' || key === 'eosDeviceEms')
|
|
168
|
+
continue;
|
|
169
|
+
if (/(?:Id|ObjectId)$/.test(key) && typeof child === 'string' && child.length <= 512 && child && !numericReference(child))
|
|
170
|
+
found.add(child);
|
|
171
|
+
else if (child && typeof child === 'object')
|
|
172
|
+
walk(child, depth + 1);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
walk(value, 0);
|
|
176
|
+
return [...found];
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Exact references needed to resolve ioBroker aliases before planning. Only
|
|
180
|
+
* relevant EMS sections are scanned; the caller never needs an object dump.
|
|
181
|
+
* A split native alias is resolved separately for read and write directions.
|
|
182
|
+
* @param {unknown} value
|
|
183
|
+
* @returns {{read: string[], write: string[]}}
|
|
184
|
+
*/
|
|
185
|
+
function getDeviceEmsReferences(value) {
|
|
186
|
+
const config = copyConfig(value);
|
|
187
|
+
const read = new Set();
|
|
188
|
+
const write = new Set();
|
|
189
|
+
const writeKey = /(?:write|^set|^target|^runObjectId$|^maxChargeObjectId$|^maxDischargeObjectId$|^phaseSwitchId$|^chargeEnableObjectId$|^dischargeEnableObjectId$|^feneconGridSetpoint|^e3dcSetPower|^enableId$)/i;
|
|
190
|
+
/** @param {unknown} item @param {number} depth */
|
|
191
|
+
const walk = (item, depth) => {
|
|
192
|
+
if (!item || typeof item !== 'object' || depth > 12)
|
|
193
|
+
return;
|
|
194
|
+
for (const [key, child] of Object.entries(item)) {
|
|
195
|
+
if (key === '_eosDevice' || key === 'eosDeviceEms')
|
|
196
|
+
continue;
|
|
197
|
+
if (/(?:Id|ObjectId)$/.test(key) && typeof child === 'string' && child.length <= 512 && child && !numericReference(child)) {
|
|
198
|
+
(writeKey.test(key) ? write : read).add(child);
|
|
199
|
+
}
|
|
200
|
+
else if (child && typeof child === 'object')
|
|
201
|
+
walk(child, depth + 1);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
for (const item of [record(config.settingsConfig).evcsList, config.storage, config.storageFarm,
|
|
205
|
+
config.gridConstraints, config.thermalControl, config.dynamicGridConnection])
|
|
206
|
+
walk(item, 0);
|
|
207
|
+
for (const [key, id] of Object.entries(record(config.datapoints))) {
|
|
208
|
+
if (/^(?:pvPower|producer\d+Power|consumer\d+Power|gridPointPower)$/.test(key) && typeof id === 'string' && id.length <= 512 && id)
|
|
209
|
+
read.add(id);
|
|
210
|
+
}
|
|
211
|
+
if (read.size + write.size > 1024)
|
|
212
|
+
throw fail('EOS_EMS_PLAN_REFERENCE_LIMIT');
|
|
213
|
+
return { read: [...read].sort(), write: [...write].sort() };
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* @param {{config: unknown, devices: unknown, limits?: {chargePoints?: unknown, batteries?: unknown}, writeTargets?: Record<string,string>, readTargets?: Record<string,string>}} input
|
|
217
|
+
* @returns {{config: Dict, patch: Dict, changed: boolean, statuses: Status[]}}
|
|
218
|
+
*/
|
|
219
|
+
function planDeviceEms(input) {
|
|
220
|
+
const before = copyConfig(input.config);
|
|
221
|
+
const config = copyConfig(before);
|
|
222
|
+
if (!Array.isArray(input.devices) || input.devices.length > MAX_DEVICES)
|
|
223
|
+
throw fail('EOS_EMS_PLAN_DEVICE_LIMIT');
|
|
224
|
+
const devices = input.devices.map(device).sort((a, b) => a.baseId.localeCompare(b.baseId, 'en'));
|
|
225
|
+
if (new Set(devices.map(dev => dev.baseId)).size !== devices.length)
|
|
226
|
+
throw fail('EOS_EMS_PLAN_DEVICE_DUPLICATE');
|
|
227
|
+
const canonical = new Map(Object.entries(input.writeTargets || {}).filter(([id, target]) => typeof id === 'string' && id.length <= 512 && typeof target === 'string' && target.length <= 512));
|
|
228
|
+
const canonicalRead = new Map(Object.entries(input.readTargets || {}).filter(([id, target]) => typeof id === 'string' && id.length <= 512 && typeof target === 'string' && target.length <= 512));
|
|
229
|
+
for (const dev of devices)
|
|
230
|
+
for (const meta of dev.aliases.values())
|
|
231
|
+
canonical.set(meta.id, meta.targetId);
|
|
232
|
+
for (const dev of devices)
|
|
233
|
+
for (const meta of dev.aliases.values())
|
|
234
|
+
if (meta.read)
|
|
235
|
+
canonicalRead.set(meta.id, meta.targetId);
|
|
236
|
+
/** @param {string} id */
|
|
237
|
+
const targetOf = id => canonical.get(id) || id;
|
|
238
|
+
/** @param {string} id */
|
|
239
|
+
const readTargetOf = id => canonicalRead.get(id) || id;
|
|
240
|
+
/** @param {unknown} value @param {number} hard */
|
|
241
|
+
const limit = (value, hard) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? Math.min(value, hard) : 0;
|
|
242
|
+
const evLimit = limit(input.limits?.chargePoints, 50);
|
|
243
|
+
const storageLimit = limit(input.limits?.batteries, MAX_ROWS);
|
|
244
|
+
/** @type {Status[]} */
|
|
245
|
+
const statuses = [];
|
|
246
|
+
/** @param {Dict} row @param {Device} dev @param {string} mode @param {string} target */
|
|
247
|
+
const remember = (row, dev, mode, target) => {
|
|
248
|
+
if (!row._eosDevice)
|
|
249
|
+
row._eosDevice = identity(dev, mode);
|
|
250
|
+
const registry = section(config, 'eosDeviceEms');
|
|
251
|
+
if (registry.v !== undefined && registry.v !== 1)
|
|
252
|
+
throw fail('EOS_EMS_PLAN_BINDING_VERSION');
|
|
253
|
+
registry.v = 1;
|
|
254
|
+
const bindings = section(registry, 'bindings');
|
|
255
|
+
const next = { target, mode, ...(dev.ems.scope ? { scope: dev.ems.scope } : {}),
|
|
256
|
+
...(dev.ems.flowSlot !== undefined ? { flowSlot: dev.ems.flowSlot } : {}) };
|
|
257
|
+
bindings[dev.baseId] = next;
|
|
258
|
+
};
|
|
259
|
+
/** @param {Device} dev @param {Dict} candidate @param {unknown[]} competing @returns {boolean} */
|
|
260
|
+
const conflict = (dev, candidate, competing) => {
|
|
261
|
+
const writes = new Set([...dev.aliases.values()].filter(meta => meta.write).map(meta => targetOf(meta.id)));
|
|
262
|
+
const candidateWrites = mappedIds(candidate).map(targetOf).filter(id => writes.has(id));
|
|
263
|
+
return competing.some(other => mappedIds(other).some(id => candidateWrites.includes(targetOf(id))));
|
|
264
|
+
};
|
|
265
|
+
/** @param {Device} dev @param {Status} result */
|
|
266
|
+
const ev = (dev, result) => {
|
|
267
|
+
const settings = section(config, 'settingsConfig');
|
|
268
|
+
const list = rows(settings, 'evcsList', 50);
|
|
269
|
+
const found = list.filter(row => belongs(row, dev));
|
|
270
|
+
if (found.length > 1) {
|
|
271
|
+
result.status = 'conflict';
|
|
272
|
+
result.code = 'DUPLICATE_DEVICE_MAPPING';
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (found.length && mappedIds(found[0]).some(id => !id.startsWith(`${dev.baseId}.`))) {
|
|
276
|
+
result.status = 'conflict';
|
|
277
|
+
result.code = 'MIXED_MANUAL_MAPPING';
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (!found.length && list.length >= evLimit) {
|
|
281
|
+
result.status = 'conflict';
|
|
282
|
+
result.code = 'LICENSE_LIMIT';
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const row = found[0] || { enabled: false };
|
|
286
|
+
const next = copyConfig(row);
|
|
287
|
+
fill(next, 'name', dev.name, result);
|
|
288
|
+
const fields = {
|
|
289
|
+
powerId: alias(dev, ['r.power'], false, ['number'], ['W']),
|
|
290
|
+
energyTotalId: alias(dev, ['r.energyTotal'], false, ['number'], ['Wh', 'kWh']),
|
|
291
|
+
statusId: alias(dev, ['r.mode3State', 'r.mode3Code', 'r.evState', 'r.statusText', 'r.statusCode'], false, ['string', 'number']),
|
|
292
|
+
vehicleConnectedId: alias(dev, ['r.vehicleConnected'], false, ['boolean']),
|
|
293
|
+
chargeDemandId: alias(dev, ['r.chargeDemand', 'r.vehicleDemand', 'r.readyToCharge', 'r.chargingRequested'], false, ['boolean']),
|
|
294
|
+
heartbeatId: alias(dev, ['r.heartbeat', 'r.lastSeenMs']),
|
|
295
|
+
onlineId: alias(dev, ['r.online', 'comm.connected'], false, ['boolean']),
|
|
296
|
+
setCurrentAId: alias(dev, ['ctrl.targetCurrentA', 'ctrl.currentLimitA', 'ctrl.setCurrentA'], true, ['number'], ['A']),
|
|
297
|
+
setPowerWId: alias(dev, ['ctrl.targetPowerW', 'ctrl.powerLimitW', 'ctrl.setPowerW'], true, ['number'], ['W']),
|
|
298
|
+
enableWriteId: alias(dev, ['ctrl.run', 'ctrl.enable', 'ctrl.enabled'], true, ['boolean']),
|
|
299
|
+
};
|
|
300
|
+
if (!Object.values(fields).some(Boolean)) {
|
|
301
|
+
result.code = 'ALIASES_PENDING';
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
for (const [key, value] of Object.entries(fields))
|
|
305
|
+
fill(next, key, value, result);
|
|
306
|
+
if (fields.energyTotalId && empty(row.energyTotalId)) {
|
|
307
|
+
const meta = [...dev.aliases.values()].find(item => item.id === fields.energyTotalId);
|
|
308
|
+
fill(next, 'energyTotalInputIsWh', meta?.unit === 'Wh', result);
|
|
309
|
+
}
|
|
310
|
+
if (conflict(dev, next, [list.filter(item => item !== row), config.storage, config.storageFarm, config.gridConstraints, config.thermalControl])) {
|
|
311
|
+
result.status = 'conflict';
|
|
312
|
+
result.code = 'CONTROL_TARGET_ALREADY_ASSIGNED';
|
|
313
|
+
result.mappedFields = [];
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (!next.powerId)
|
|
317
|
+
result.missing.push('powerId');
|
|
318
|
+
if (!next.setCurrentAId && !next.setPowerWId)
|
|
319
|
+
result.missing.push('setCurrentAId|setPowerWId');
|
|
320
|
+
if (!next.onlineId && !next.heartbeatId)
|
|
321
|
+
result.missing.push('onlineId|heartbeatId');
|
|
322
|
+
remember(next, dev, 'auto', 'evcs');
|
|
323
|
+
if (found.length)
|
|
324
|
+
list[list.indexOf(row)] = next;
|
|
325
|
+
else
|
|
326
|
+
list.push(next);
|
|
327
|
+
const count = settings.evcsCount;
|
|
328
|
+
if (count !== undefined && (typeof count !== 'number' || !Number.isSafeInteger(count) || count < 0 || count > 50)) {
|
|
329
|
+
throw fail('EOS_EMS_PLAN_EVCS_COUNT_INVALID');
|
|
330
|
+
}
|
|
331
|
+
settings.evcsCount = Math.max(typeof count === 'number' ? count : 0, list.length);
|
|
332
|
+
result.target = 'settingsConfig.evcsList';
|
|
333
|
+
result.status = 'mapped';
|
|
334
|
+
result.code = result.missing.length ? 'MAPPING_INCOMPLETE' : next.enabled === false ? 'COMMISSIONING_REQUIRED' : 'MAPPED';
|
|
335
|
+
};
|
|
336
|
+
/** @param {Device} dev @param {Status} result @param {boolean} farm */
|
|
337
|
+
const storage = (dev, result, farm) => {
|
|
338
|
+
if (dev.ems.scope === 'M1') {
|
|
339
|
+
result.code = 'MANUAL_TOPOLOGY_REQUIRED';
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const single = record(config.storage);
|
|
343
|
+
const farmConfig = record(config.storageFarm);
|
|
344
|
+
const farmRows = Array.isArray(farmConfig.storages) ? farmConfig.storages.filter(isRecord) : [];
|
|
345
|
+
const singleAssigned = mappedIds(single).some(Boolean);
|
|
346
|
+
const existingSameSingle = belongs(record(single.datapoints), dev) || belongs(single, dev);
|
|
347
|
+
const existingSameFarm = farmRows.filter(row => belongs(row, dev));
|
|
348
|
+
if ((farm && existingSameSingle) || (!farm && existingSameFarm.length) || existingSameFarm.length > 1) {
|
|
349
|
+
result.status = 'conflict';
|
|
350
|
+
result.code = 'STORAGE_CONTROLLER_ALREADY_ASSIGNED';
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (!farm && singleAssigned && !existingSameSingle) {
|
|
354
|
+
result.status = 'conflict';
|
|
355
|
+
result.code = 'MANUAL_MAPPING_PRESERVED';
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const existing = farm ? existingSameFarm[0] : existingSameSingle ? single : undefined;
|
|
359
|
+
if (existing && mappedIds(existing).some(id => !id.startsWith(`${dev.baseId}.`))) {
|
|
360
|
+
result.status = 'conflict';
|
|
361
|
+
result.code = 'MIXED_MANUAL_MAPPING';
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (!existing && farmRows.length + (singleAssigned ? 1 : 0) >= storageLimit) {
|
|
365
|
+
result.status = 'conflict';
|
|
366
|
+
result.code = 'LICENSE_LIMIT';
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
// A preconfigured, as-yet-unassigned single-storage section can contain
|
|
370
|
+
// customer limits and vendor settings. Keep these when adding aliases.
|
|
371
|
+
// A new assignment still needs commissioning even if its empty section
|
|
372
|
+
// had enabled=true from an earlier installer selection.
|
|
373
|
+
const row = existing ? copyConfig(existing) : farm ? { enabled: false } : { ...copyConfig(single), enabled: false };
|
|
374
|
+
const destination = farm ? row : section(row, 'datapoints');
|
|
375
|
+
fill(row, 'name', dev.name, result);
|
|
376
|
+
const feneconHome = dev.templateId === 'ess.fenecon.FeneconHomeEssImpl';
|
|
377
|
+
/** Exact known Home source; an arbitrary alias with a familiar name is not sufficient. @param {string[]} names @param {string} source @param {boolean} [write] */
|
|
378
|
+
const homePower = (names, source, write = false) => {
|
|
379
|
+
for (const name of names) {
|
|
380
|
+
const id = alias(dev, [name], write, ['number'], ['W']);
|
|
381
|
+
if (id && dev.aliases.get(name)?.targetId === `${dev.baseId}.${source}`)
|
|
382
|
+
return id;
|
|
383
|
+
}
|
|
384
|
+
return '';
|
|
385
|
+
};
|
|
386
|
+
const homeFeedback = feneconHome ? homePower(['r.essActivePower'], 'eSS0_ACTIVE_POWER') : '';
|
|
387
|
+
const keys = farm ? {
|
|
388
|
+
socId: ['r.soc'], signedPowerId: feneconHome ? [] : ['r.essActivePower', 'r.powerAc', 'r.power'],
|
|
389
|
+
chargePowerId: ['r.powerCharge'], dischargePowerId: ['r.powerDischarge'],
|
|
390
|
+
availableId: ['r.online', 'comm.connected'], faultId: ['alarm.fault'],
|
|
391
|
+
chargeAllowedId: ['r.allowCharge'], dischargeAllowedId: ['r.allowDischarge'],
|
|
392
|
+
} : {
|
|
393
|
+
socObjectId: ['r.soc'], batteryPowerObjectId: feneconHome ? [] : ['r.essActivePower', 'r.powerAc', 'r.power'],
|
|
394
|
+
};
|
|
395
|
+
for (const [key, names] of Object.entries(keys)) {
|
|
396
|
+
const booleanField = ['availableId', 'faultId', 'chargeAllowedId', 'dischargeAllowedId'].includes(key);
|
|
397
|
+
fill(destination, key, alias(dev, names, false, booleanField ? ['boolean'] : ['number'], key.startsWith('soc') ? ['%'] : booleanField ? [] : ['W']), result);
|
|
398
|
+
}
|
|
399
|
+
const signed = feneconHome ? homePower(['ctrl.powerSetpointW'], 'sET_ACTIVE_POWER', true)
|
|
400
|
+
: alias(dev, ['ctrl.powerSetpointW'], true, ['number'], ['W']);
|
|
401
|
+
const charge = alias(dev, ['ctrl.chargePowerW'], true, ['number'], ['W']);
|
|
402
|
+
const discharge = alias(dev, ['ctrl.dischargePowerW'], true, ['number'], ['W']);
|
|
403
|
+
const commandKeys = farm ? ['setSignedPowerId', 'setChargePowerId', 'setDischargePowerId', 'feneconGridSetpointId']
|
|
404
|
+
: ['targetPowerObjectId', 'targetChargePowerObjectId', 'targetDischargePowerObjectId', 'feneconGridSetpointObjectId', 'e3dcSetPowerModeObjectId', 'e3dcSetPowerValueObjectId'];
|
|
405
|
+
const hadCommand = commandKeys.some(key => !empty(destination[key]));
|
|
406
|
+
if (feneconHome) {
|
|
407
|
+
if (!existing || row.enabled === false || !hadCommand) {
|
|
408
|
+
fill(row, 'vendorProfile', 'fenecon-openems', result);
|
|
409
|
+
fill(row, 'coupling', 'dc', result);
|
|
410
|
+
}
|
|
411
|
+
// Detection does not switch a commissioned FEMS controller into a
|
|
412
|
+
// different command family. New Home rows use the verified direct
|
|
413
|
+
// ESS path; the optional native target is exposed separately.
|
|
414
|
+
fill(row, 'feneconControlMode', existing && hadCommand ? 'auto' : 'direct-ess', result);
|
|
415
|
+
fill(destination, farm ? 'signedPowerId' : 'batteryPowerObjectId', homeFeedback, result);
|
|
416
|
+
/** @type {[string, string[], string][]} */
|
|
417
|
+
const homeFields = [
|
|
418
|
+
['feneconEssActualPower', ['r.essActivePower'], 'eSS0_ACTIVE_POWER'],
|
|
419
|
+
['feneconNvpPower', ['r.nvpPower', 'r.gridPower', 'r.napPower'], 'gRID_POWER'],
|
|
420
|
+
['feneconConsumptionTotal', ['r.consumptionTotal', 'r.loadTotal', 'r.consumptionPower', 'r.loadPower'], 'lOAD_POWER'],
|
|
421
|
+
['feneconMinPower', ['r.minPowerSetpointW'], 'mIN_POWER_SETPOINT'],
|
|
422
|
+
['feneconMaxPower', ['r.maxPowerSetpointW'], 'mAX_POWER_SETPOINT'],
|
|
423
|
+
['feneconPvDc', ['r.pvPowerDc'], 'pV_DC_POWER'],
|
|
424
|
+
['feneconPvAc', ['r.pvPowerAc'], 'pV_AC_POWER'],
|
|
425
|
+
['feneconPvTotal', ['r.pvPowerTotal'], 'pV_POWER_SUM'],
|
|
426
|
+
];
|
|
427
|
+
for (const field of homeFields) {
|
|
428
|
+
const key = `${field[0]}${farm ? 'Id' : 'ObjectId'}`;
|
|
429
|
+
fill(destination, key, homePower(field[1], field[2]), result);
|
|
430
|
+
if (empty(destination[key]) && field[0] !== 'feneconEssActualPower')
|
|
431
|
+
result.optionalMissing.push(key);
|
|
432
|
+
}
|
|
433
|
+
const gridKey = farm ? 'feneconGridSetpointId' : 'feneconGridSetpointObjectId';
|
|
434
|
+
const nativeGrid = homePower(['ctrl.gridSetpointW', 'ctrl.napSetpointW'], 'sET_GRID_ACTIVE_POWER', true);
|
|
435
|
+
// Populate both real target references without changing an existing
|
|
436
|
+
// mode: direct-ess uses 706; fems-grid uses its guarded controller.
|
|
437
|
+
const directMode = row.feneconControlMode === 'direct-ess';
|
|
438
|
+
if (directMode && !commandKeys.slice(0, 3).some(key => !empty(destination[key])) && signed) {
|
|
439
|
+
fill(destination, commandKeys[0], signed, result);
|
|
440
|
+
}
|
|
441
|
+
const preserveAutoDirect = existing && row.enabled !== false && empty(destination[gridKey]) &&
|
|
442
|
+
!['direct-ess', 'fems-grid'].includes(text(row.feneconControlMode)) &&
|
|
443
|
+
commandKeys.slice(0, 3).some(key => !empty(destination[key]));
|
|
444
|
+
if (preserveAutoDirect && nativeGrid)
|
|
445
|
+
result.missing.push(`review:${gridKey}`);
|
|
446
|
+
else {
|
|
447
|
+
fill(destination, gridKey, nativeGrid, result);
|
|
448
|
+
if (empty(destination[gridKey]))
|
|
449
|
+
result.optionalMissing.push(gridKey);
|
|
450
|
+
}
|
|
451
|
+
const readbackKey = farm ? 'feneconActualSetpointId' : 'feneconActualSetpointObjectId';
|
|
452
|
+
const readback = dev.aliases.get('r.powerSetpointReadbackW');
|
|
453
|
+
const actualReadback = readback && readback.read && !readback.write &&
|
|
454
|
+
![`${dev.baseId}.sET_ACTIVE_POWER`, `${dev.baseId}.sET_GRID_ACTIVE_POWER`].includes(readback.targetId)
|
|
455
|
+
? alias(dev, ['r.powerSetpointReadbackW'], false, ['number'], ['W']) : '';
|
|
456
|
+
fill(destination, readbackKey, actualReadback, result);
|
|
457
|
+
if (empty(destination[readbackKey]))
|
|
458
|
+
result.optionalMissing.push(readbackKey);
|
|
459
|
+
if (row.vendorProfile !== 'fenecon-openems')
|
|
460
|
+
result.missing.push('vendorProfile:fenecon-openems');
|
|
461
|
+
if (!homeFeedback && empty(destination[farm ? 'feneconEssActualPowerId' : 'feneconEssActualPowerObjectId'])) {
|
|
462
|
+
result.missing.push(farm ? 'feneconEssActualPowerId' : 'feneconEssActualPowerObjectId');
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (!commandKeys.some(key => !empty(destination[key]))) {
|
|
466
|
+
if (signed)
|
|
467
|
+
fill(destination, commandKeys[0], signed, result);
|
|
468
|
+
else if (charge && discharge) {
|
|
469
|
+
fill(destination, commandKeys[1], charge, result);
|
|
470
|
+
fill(destination, commandKeys[2], discharge, result);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if (!hadCommand && commandKeys.some(key => !empty(destination[key])))
|
|
474
|
+
row.enabled = false;
|
|
475
|
+
if (!farm) {
|
|
476
|
+
fill(destination, 'runObjectId', alias(dev, ['ctrl.run'], true, ['boolean']), result);
|
|
477
|
+
fill(destination, 'maxChargeObjectId', alias(dev, ['ctrl.maxChargePowerW'], true, ['number'], ['W']), result);
|
|
478
|
+
fill(destination, 'maxDischargeObjectId', alias(dev, ['ctrl.maxDischargePowerW'], true, ['number'], ['W']), result);
|
|
479
|
+
fill(destination, 'chargeEnableObjectId', alias(dev, ['ctrl.chargeEnable'], true, ['boolean']), result);
|
|
480
|
+
fill(destination, 'dischargeEnableObjectId', alias(dev, ['ctrl.dischargeEnable'], true, ['boolean']), result);
|
|
481
|
+
}
|
|
482
|
+
const dcPv = feneconHome ? homePower(['r.pvPowerDc'], 'pV_DC_POWER') : alias(dev, ['r.pvPowerDc'], false, ['number'], ['W']);
|
|
483
|
+
const acPv = feneconHome ? homePower(['r.pvPowerAc'], 'pV_AC_POWER') : alias(dev, ['r.pvPowerAc'], false, ['number'], ['W']);
|
|
484
|
+
if (dcPv && empty(row.coupling) && (!existing || row.enabled === false || !hadCommand))
|
|
485
|
+
fill(row, 'coupling', 'dc', result);
|
|
486
|
+
if (row.coupling === 'dc')
|
|
487
|
+
fill(destination, farm ? 'pvPowerId' : 'dcPvPowerObjectId', dcPv, result);
|
|
488
|
+
else if (farm && row.coupling === 'ac')
|
|
489
|
+
fill(destination, 'pvPowerId', acPv, result);
|
|
490
|
+
if (!mappedIds(destination).length) {
|
|
491
|
+
result.code = 'ALIASES_PENDING';
|
|
492
|
+
result.mappedFields = [];
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
const competing = [farm ? [single, ...farmRows.filter(item => item !== existing)] : farmRows,
|
|
496
|
+
record(config.settingsConfig).evcsList, config.gridConstraints, config.thermalControl];
|
|
497
|
+
if (conflict(dev, row, competing)) {
|
|
498
|
+
result.status = 'conflict';
|
|
499
|
+
result.code = 'CONTROL_TARGET_ALREADY_ASSIGNED';
|
|
500
|
+
result.mappedFields = [];
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
const socKey = farm ? 'socId' : 'socObjectId';
|
|
504
|
+
const powerKey = farm ? 'signedPowerId' : 'batteryPowerObjectId';
|
|
505
|
+
if (!destination[socKey])
|
|
506
|
+
result.missing.push(socKey);
|
|
507
|
+
if (!destination[powerKey])
|
|
508
|
+
result.missing.push(powerKey);
|
|
509
|
+
const controlKeys = feneconHome && row.feneconControlMode === 'direct-ess' ? commandKeys.slice(0, 3)
|
|
510
|
+
: feneconHome && row.feneconControlMode === 'fems-grid' ? [farm ? 'feneconGridSetpointId' : 'feneconGridSetpointObjectId'] : commandKeys;
|
|
511
|
+
if (!controlKeys.some(key => !empty(destination[key]) && !numericReference(destination[key])))
|
|
512
|
+
result.missing.push('storageControl');
|
|
513
|
+
for (const [key, value] of Object.entries(destination)) {
|
|
514
|
+
if (/(?:Id|ObjectId)$/.test(key) && numericReference(value))
|
|
515
|
+
result.missing.push(`invalid:${key}`);
|
|
516
|
+
}
|
|
517
|
+
remember(row, dev, farm ? 'storageFarm' : 'singleStorage', farm ? 'storageFarm' : 'storage');
|
|
518
|
+
if (farm) {
|
|
519
|
+
const list = rows(section(config, 'storageFarm'), 'storages');
|
|
520
|
+
if (existing)
|
|
521
|
+
list[list.findIndex(item => belongs(item, dev))] = row;
|
|
522
|
+
else
|
|
523
|
+
list.push(row);
|
|
524
|
+
}
|
|
525
|
+
else
|
|
526
|
+
config.storage = row;
|
|
527
|
+
result.target = farm ? 'storageFarm.storages' : 'storage';
|
|
528
|
+
result.status = 'mapped';
|
|
529
|
+
result.code = result.missing.length ? 'MAPPING_INCOMPLETE' : row.enabled === false ? 'COMMISSIONING_REQUIRED' : 'MAPPED';
|
|
530
|
+
};
|
|
531
|
+
/** @param {Device} dev @param {Status} result @param {string} mode */
|
|
532
|
+
const measurement = (dev, result, mode) => {
|
|
533
|
+
const power = alias(dev, mode === 'pvInverter' ? ['r.pvPower', 'r.power'] : ['r.power'], false, ['number'], ['W']);
|
|
534
|
+
if (!power) {
|
|
535
|
+
result.code = 'ALIASES_PENDING';
|
|
536
|
+
result.missing.push('r.power');
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
const powerKeys = /^(?:pvPower|producer\d+Power|consumer\d+Power|gridPointPower)$/;
|
|
540
|
+
/** @param {string} [except] */
|
|
541
|
+
const assignedFlow = except => Object.entries(record(config.datapoints)).some(([key, id]) => key !== except && powerKeys.test(key) &&
|
|
542
|
+
typeof id === 'string' && readTargetOf(id) === readTargetOf(power));
|
|
543
|
+
/** @param {string} [except] */
|
|
544
|
+
const assignedDynamic = except => {
|
|
545
|
+
const points = record(config.dynamicGridConnection).points;
|
|
546
|
+
return Array.isArray(points) && points.some(point => {
|
|
547
|
+
const row = record(point);
|
|
548
|
+
const id = record(row.measurement).stateId;
|
|
549
|
+
return row.id !== except && typeof id === 'string' && readTargetOf(id) === readTargetOf(power);
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
if (mode === 'gridMeter' && dev.ems.scope === 'M1') {
|
|
553
|
+
if (assignedFlow() || assignedDynamic('M1')) {
|
|
554
|
+
result.status = 'conflict';
|
|
555
|
+
result.code = 'MEASUREMENT_ALREADY_ASSIGNED';
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
/** @type {Dict} */
|
|
559
|
+
const dynamic = config.dynamicGridConnection === undefined ? {
|
|
560
|
+
schemaVersion: 1, configVersion: 1, maxSkewMs: 1000, points: [
|
|
561
|
+
{ id: 'M0', source: 'general', importLimitW: null, exportLimitW: null, importReserveW: 0, exportReserveW: 0 },
|
|
562
|
+
{ id: 'M1', source: 'mapped', measurement: { stateId: '', unit: 'W', sign: 1, maxAgeMs: 5000 }, importLimitW: null,
|
|
563
|
+
exportLimitW: null, importReserveW: 0, exportReserveW: 0 },
|
|
564
|
+
], storages: [], pvAssignments: [],
|
|
565
|
+
} : copyConfig(config.dynamicGridConnection);
|
|
566
|
+
const points = rows(dynamic, 'points', 2);
|
|
567
|
+
const point = points.find(item => item.id === 'M1');
|
|
568
|
+
if (!point) {
|
|
569
|
+
result.code = 'MANUAL_TOPOLOGY_REQUIRED';
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const mapping = section(point, 'measurement');
|
|
573
|
+
if (!empty(mapping.stateId) && mapping.stateId !== power) {
|
|
574
|
+
result.status = 'conflict';
|
|
575
|
+
result.code = 'MANUAL_MAPPING_PRESERVED';
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
fill(mapping, 'stateId', power, result);
|
|
579
|
+
fill(mapping, 'unit', 'W', result);
|
|
580
|
+
fill(mapping, 'sign', 1, result);
|
|
581
|
+
fill(mapping, 'maxAgeMs', 5000, result);
|
|
582
|
+
config.dynamicGridConnection = dynamic;
|
|
583
|
+
remember(point, dev, mode, 'M1');
|
|
584
|
+
result.target = 'dynamicGridConnection.points.M1.measurement';
|
|
585
|
+
result.status = 'mapped';
|
|
586
|
+
result.code = 'MEASUREMENT_MAPPED';
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
let key = '';
|
|
590
|
+
let slot = dev.ems.flowSlot;
|
|
591
|
+
let kind = '';
|
|
592
|
+
if (mode === 'gridMeter') {
|
|
593
|
+
if (dev.ems.scope !== 'M0') {
|
|
594
|
+
result.code = 'NEEDS_SELECTION';
|
|
595
|
+
result.missing.push('scope');
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
key = 'gridPointPower';
|
|
599
|
+
}
|
|
600
|
+
else if (mode === 'generationMeter' || mode === 'pvInverter') {
|
|
601
|
+
if (typeof slot !== 'number' || slot < 0 || slot > 5) {
|
|
602
|
+
result.code = 'NEEDS_SELECTION';
|
|
603
|
+
result.missing.push('flowSlot');
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
key = slot === 0 ? 'pvPower' : `producer${slot}Power`;
|
|
607
|
+
kind = 'producers';
|
|
608
|
+
}
|
|
609
|
+
else if (mode === 'consumptionMeter') {
|
|
610
|
+
if (typeof slot !== 'number' || slot < 1 || slot > 10) {
|
|
611
|
+
result.code = 'NEEDS_SELECTION';
|
|
612
|
+
result.missing.push('flowSlot');
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
key = `consumer${slot}Power`;
|
|
616
|
+
kind = 'consumers';
|
|
617
|
+
}
|
|
618
|
+
if (!key) {
|
|
619
|
+
result.code = 'NEEDS_SELECTION';
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
const dp = section(config, 'datapoints');
|
|
623
|
+
if (!empty(dp[key]) && dp[key] !== power) {
|
|
624
|
+
result.status = 'conflict';
|
|
625
|
+
result.code = 'MANUAL_MAPPING_PRESERVED';
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
const duplicated = assignedFlow(key) || assignedDynamic();
|
|
629
|
+
if (duplicated) {
|
|
630
|
+
result.status = 'conflict';
|
|
631
|
+
result.code = 'MEASUREMENT_ALREADY_ASSIGNED';
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
fill(dp, key, power, result);
|
|
635
|
+
// Unit flags are adjusted only together with a new assignment; a manual
|
|
636
|
+
// setting on an existing target is not silently changed.
|
|
637
|
+
if (result.mappedFields.includes(key))
|
|
638
|
+
section(section(config, 'settings'), 'flowPowerDpIsW')[key] = true;
|
|
639
|
+
const fs = section(section(config, 'vis'), 'flowSlots');
|
|
640
|
+
let owner = section(fs, 'core');
|
|
641
|
+
if (kind && typeof slot === 'number' && slot > 0) {
|
|
642
|
+
const list = rows(fs, kind, kind === 'producers' ? 5 : 10);
|
|
643
|
+
while (list.length < slot)
|
|
644
|
+
list.push({});
|
|
645
|
+
owner = list[slot - 1];
|
|
646
|
+
fill(owner, 'name', dev.name, result);
|
|
647
|
+
}
|
|
648
|
+
else if (key === 'pvPower')
|
|
649
|
+
fill(owner, 'pvName', dev.name, result);
|
|
650
|
+
if (mode === 'gridMeter') {
|
|
651
|
+
fill(dp, 'gridPointConnected', alias(dev, ['r.online', 'comm.connected'], false, ['boolean']), result);
|
|
652
|
+
fill(dp, 'gridPointWatchdog', alias(dev, ['r.heartbeat', 'r.lastSeenMs']), result);
|
|
653
|
+
}
|
|
654
|
+
remember(owner, dev, mode, key);
|
|
655
|
+
result.target = `datapoints.${key}`;
|
|
656
|
+
result.status = 'mapped';
|
|
657
|
+
result.code = 'MEASUREMENT_MAPPED';
|
|
658
|
+
};
|
|
659
|
+
// Existing auto-created control rows survive missing/deactivated devices, but
|
|
660
|
+
// are held inactive. Re-adding a device never grants activation by itself.
|
|
661
|
+
const activeBases = new Set(devices.filter(dev => dev.enabled && dev.ems.mode !== 'monitor').map(dev => dev.baseId));
|
|
662
|
+
const controlRows = [
|
|
663
|
+
...(Array.isArray(record(config.settingsConfig).evcsList) ? /** @type {Json[]} */ (record(config.settingsConfig).evcsList) : []),
|
|
664
|
+
...(Array.isArray(record(config.storageFarm).storages) ? /** @type {Json[]} */ (record(config.storageFarm).storages) : []),
|
|
665
|
+
record(config.storage),
|
|
666
|
+
];
|
|
667
|
+
for (const item of controlRows) {
|
|
668
|
+
const row = record(item);
|
|
669
|
+
const owner = record(row._eosDevice);
|
|
670
|
+
if (owner.v === 1 && typeof owner.baseId === 'string' && !activeBases.has(owner.baseId))
|
|
671
|
+
row.enabled = false;
|
|
672
|
+
}
|
|
673
|
+
for (const dev of devices) {
|
|
674
|
+
const result = status(dev);
|
|
675
|
+
statuses.push(result);
|
|
676
|
+
const mode = text(dev.ems.mode) || 'auto';
|
|
677
|
+
if (!dev.enabled) {
|
|
678
|
+
result.status = 'disabled';
|
|
679
|
+
result.code = 'DEVICE_DISABLED';
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
if (mode === 'manual' || mode === 'monitor') {
|
|
683
|
+
result.status = 'manual';
|
|
684
|
+
result.code = mode === 'manual' ? 'MANUAL_MAPPING' : 'MONITOR_ONLY';
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
if (dev.discoveryCode || !dev.aliases.size) {
|
|
688
|
+
result.code = dev.discoveryCode || 'ALIASES_PENDING';
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
const checkpoint = copyConfig(config);
|
|
692
|
+
try {
|
|
693
|
+
if (dev.deviceClass === 'evCharger' && mode === 'auto') {
|
|
694
|
+
ev(dev, result);
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
if (STORAGE_CLASSES.has(dev.deviceClass) && ['singleStorage', 'storageFarm'].includes(mode)) {
|
|
698
|
+
storage(dev, result, mode === 'storageFarm');
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
if (dev.deviceClass === 'meter' && ['gridMeter', 'generationMeter', 'consumptionMeter'].includes(mode)) {
|
|
702
|
+
measurement(dev, result, mode);
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
if (dev.deviceClass === 'pvInverter' && mode === 'pvInverter') {
|
|
706
|
+
measurement(dev, result, mode);
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
if (dev.deviceClass === 'heat' && mode === 'consumptionMeter') {
|
|
710
|
+
measurement(dev, result, mode);
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
if (dev.deviceClass === 'solarCharger' || dev.deviceClass === 'generic') {
|
|
714
|
+
result.status = 'manual';
|
|
715
|
+
result.code = 'MANUAL_MAPPING';
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
result.code = mode === 'auto' ? 'NEEDS_SELECTION' : 'DEVICE_ROLE_MISMATCH';
|
|
719
|
+
}
|
|
720
|
+
finally {
|
|
721
|
+
// Conflicts and unavailable metadata must not leave empty sections,
|
|
722
|
+
// partially added rows or binding records in the committed config.
|
|
723
|
+
if (result.status !== 'mapped') {
|
|
724
|
+
for (const key of Object.keys(config))
|
|
725
|
+
delete config[key];
|
|
726
|
+
Object.assign(config, checkpoint);
|
|
727
|
+
result.mappedFields = [];
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
/** @type {Dict} */
|
|
732
|
+
const patch = {};
|
|
733
|
+
for (const [key, value] of Object.entries(config))
|
|
734
|
+
if (JSON.stringify(value) !== JSON.stringify(before[key]))
|
|
735
|
+
patch[key] = value;
|
|
736
|
+
return { config, patch, changed: Object.keys(patch).length > 0, statuses };
|
|
737
|
+
}
|
|
738
|
+
module.exports = { planDeviceEms, getDeviceEmsReferences };
|
|
739
|
+
//# sourceMappingURL=eosDeviceEmsPlan.js.map
|