iobroker.eos-admin 9.0.17 → 9.0.19
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 +11 -14
- package/README.md +7 -3
- package/START_HIER_9.0.18.md +47 -0
- package/START_HIER_9.0.19.md +52 -0
- package/adminWww/.vite/manifest.json +114 -114
- package/adminWww/NEXOWATT_EOS_FRONTEND_MANIFEST.json +13759 -13759
- package/adminWww/assets/{AdapterUpdateDialog-Cpo3dAfY.js → AdapterUpdateDialog-JOf2z4Vg.js} +1 -1
- package/adminWww/assets/{Adapters-n2ukPDdC.js → Adapters-C9fcSdWm.js} +1 -1
- package/adminWww/assets/{ConfigManager-BVZ6_Ebo.js → ConfigManager-BeeLlT6D.js} +1 -1
- package/adminWww/assets/{Enums-CQ6yHG2W.js → Enums-FqnXWl8U.js} +1 -1
- package/adminWww/assets/{Fields-CaJqzoW-.js → Fields-DMgrt5Pi.js} +1 -1
- package/adminWww/assets/{Files-DfvpKGa3.js → Files-CIHtt12g.js} +1 -1
- package/adminWww/assets/{Hosts-3xLBsdG6.js → Hosts-fPLBzvTy.js} +1 -1
- package/adminWww/assets/{Instances-B7hKEhyw.js → Instances-4XaVQlrT.js} +1 -1
- package/adminWww/assets/{Intro-BV4kYZdT.js → Intro-5TKriiLO.js} +1 -1
- package/adminWww/assets/{Logs-DpL9eY69.js → Logs-33zcIds-.js} +1 -1
- package/adminWww/assets/{Objects-dN06jhQk.js → Objects-CNQPVbNG.js} +1 -1
- package/adminWww/assets/{Overview-Lip63_ej.js → Overview-BskXGOc8.js} +1 -1
- package/adminWww/assets/{State-BSO2X_xN.js → State-C8SJ_Iqo.js} +1 -1
- package/adminWww/assets/{UsedResources-DvqzszKI.js → UsedResources-CgqRa9ei.js} +1 -1
- package/adminWww/assets/{Users-Csqd1xA-.js → Users-0JVYWR9u.js} +1 -1
- package/adminWww/assets/{bootstrap-C3HM8kNL.js → bootstrap-D16lu6rd.js} +3 -3
- package/adminWww/assets/{hostInit-DdxBUeXQ.js → hostInit-C8YZJuzi.js} +1 -1
- package/adminWww/assets/{icons-material-D1Tb_725.js → icons-material-CiNJ_6Ur.js} +1 -1
- package/adminWww/assets/{index-BOujTMyH.js → index-DA9Sphgh.js} +2 -2
- package/adminWww/assets/{installSVGRenderer-BZyrUVAo.js → installSVGRenderer-DPdkRa_d.js} +1 -1
- package/adminWww/assets/{mf-entry-bootstrap-0-3418586b.js → mf-entry-bootstrap-0-a7ab91de.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.17.js → remoteEntry-eos-9.0.19.js} +1 -1
- package/adminWww/remoteEntry.js +1 -1
- package/build/lib/eosCookieNamespace.js +12 -2
- package/build/lib/eosCookieNamespace.js.map +1 -1
- package/build/lib/eosDeviceEmsPlan.js +1147 -0
- package/build/lib/eosDeviceEmsPlan.js.map +1 -0
- package/build/lib/eosDeviceEmsService.js +473 -0
- package/build/lib/eosDeviceEmsService.js.map +1 -0
- package/build/lib/eosModuleHost.js +227 -51
- 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 +31 -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/docs/reports/unified-9.0.19/ALIAS_MESSWERTFRISCHE.md +31 -0
- package/docs/reports/unified-9.0.19/COMMISSIONING_PLAN_REVIEW.md +56 -0
- package/docs/reports/unified-9.0.19/EMS_ABSCHLUSSREVIEW.md +43 -0
- package/docs/reports/unified-9.0.19/EMS_KATEGORIEN_ABDECKUNG.md +66 -0
- package/docs/reports/unified-9.0.19/EMS_VERGLEICH_UND_KOPPLUNG.md +25 -0
- package/docs/reports/unified-9.0.19/EVCS_STATE_OBJECTS.md +47 -0
- package/docs/reports/unified-9.0.19/GERAETE_EMS_EINRICHTUNG.md +100 -0
- package/docs/reports/unified-9.0.19/GERAETE_STARTAUSFALL.md +37 -0
- package/docs/reports/unified-9.0.19/INSTALLER_LIFECYCLE_REVIEW.md +59 -0
- package/docs/reports/unified-9.0.19/LEGACY_REGRESSION_REVIEW.md +42 -0
- package/docs/reports/unified-9.0.19/MODBUS_AUTHORIZATION_READS.md +25 -0
- package/docs/reports/unified-9.0.19/PRUEFBERICHT.md +56 -0
- package/docs/reports/unified-9.0.19/RUNTIME_START_UEBERNAHME.md +33 -0
- package/docs/reports/unified-9.0.19/SMA_RECEIVER_LIFECYCLE.md +42 -0
- package/docs/reports/unified-9.0.19/STATIC_REVIEW_DE.md +11 -0
- package/docs/reports/unified-9.0.19/TARIFF_PRICE_VALUES_REVIEW.md +31 -0
- package/docs/reports/unified-9.0.19/TARIF_VIERTELSTUNDEN_RUNTIME.md +17 -0
- package/docs/reports/unified-9.0.19/UNABHAENGIGER_REVIEW.md +49 -0
- package/docs/reports/unified-9.0.19/raw/INDEX.json +751 -0
- package/docs/reports/unified-9.0.19/raw/audit-full.log +345 -0
- package/docs/reports/unified-9.0.19/raw/audit-full.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/audit-runtime.log +23 -0
- package/docs/reports/unified-9.0.19/raw/audit-runtime.result.json +15 -0
- package/docs/reports/unified-9.0.19/raw/backend-final.log +5 -0
- package/docs/reports/unified-9.0.19/raw/backend-final.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/devices-hosted-typecheck-node22.log +0 -0
- package/docs/reports/unified-9.0.19/raw/devices-hosted-typecheck-node22.result.json +15 -0
- package/docs/reports/unified-9.0.19/raw/devices-hosted-typecheck-node24.log +0 -0
- package/docs/reports/unified-9.0.19/raw/devices-hosted-typecheck-node24.result.json +15 -0
- package/docs/reports/unified-9.0.19/raw/devices-incident-build.log +5 -0
- package/docs/reports/unified-9.0.19/raw/devices-incident-host-final.log +70 -0
- package/docs/reports/unified-9.0.19/raw/devices-incident-lease-918-before.log +26 -0
- package/docs/reports/unified-9.0.19/raw/devices-incident-lease-after.log +9 -0
- package/docs/reports/unified-9.0.19/raw/devices-incident-metadata-after.log +11 -0
- package/docs/reports/unified-9.0.19/raw/devices-incident-metadata-before.log +28 -0
- package/docs/reports/unified-9.0.19/raw/devices-incident-web-pipeline.log +22 -0
- package/docs/reports/unified-9.0.19/raw/frontend-build.log +152 -0
- package/docs/reports/unified-9.0.19/raw/frontend-build.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/installer-build.log +26 -0
- package/docs/reports/unified-9.0.19/raw/installer-build.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/keygen-source.json +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-auto-pv.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-auto-pv.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-charging-grid-cap-clamp.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-charging-grid-cap-clamp.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-charging-grid-cap-safe.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-charging-grid-cap-safe.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-charging-mode-recovery.log +539 -0
- package/docs/reports/unified-9.0.19/raw/legacy-charging-mode-recovery.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-core-limits-phase1.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-core-limits-phase1.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-core-limits-phase2.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-core-limits-phase2.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-core-limits-tariff-final.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-core-limits-tariff-final.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-energy-wallet-final.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-energy-wallet-final.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-farm-dispatch-loader-current.log +2 -0
- package/docs/reports/unified-9.0.19/raw/legacy-farm-dispatch-loader-current.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-final-write-envelope.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-final-write-envelope.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-history-http.log +39 -0
- package/docs/reports/unified-9.0.19/raw/legacy-history-http.result.json +15 -0
- package/docs/reports/unified-9.0.19/raw/legacy-import-grid-budget.log +30 -0
- package/docs/reports/unified-9.0.19/raw/legacy-import-grid-budget.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-import-grid-contract-current.log +2 -0
- package/docs/reports/unified-9.0.19/raw/legacy-import-grid-contract-current.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-live-mode-loader-current.log +203 -0
- package/docs/reports/unified-9.0.19/raw/legacy-live-mode-loader-current.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-load-grid-sanity.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-load-grid-sanity.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-ocpp-stability.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-ocpp-stability.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-ocpp21-storage-safety.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-ocpp21-storage-safety.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-permanent-grid-protection.log +18 -0
- package/docs/reports/unified-9.0.19/raw/legacy-permanent-grid-protection.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-storage-dp-persistence.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-storage-dp-persistence.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-storage-farm-dispatch-recovery.log +16 -0
- package/docs/reports/unified-9.0.19/raw/legacy-storage-farm-dispatch-recovery.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-storage-functional-safety.log +6 -0
- package/docs/reports/unified-9.0.19/raw/legacy-storage-functional-safety.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-storage-topology-loader-current.log +2 -0
- package/docs/reports/unified-9.0.19/raw/legacy-storage-topology-loader-current.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/legacy-test-loader.cjs +47 -0
- package/docs/reports/unified-9.0.19/raw/lint-final.log +16 -0
- package/docs/reports/unified-9.0.19/raw/lint-final.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/modules-build.log +5 -0
- package/docs/reports/unified-9.0.19/raw/modules-build.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/node22-tests-final.log +10719 -0
- package/docs/reports/unified-9.0.19/raw/node22-tests-final.result.json +13 -0
- package/docs/reports/unified-9.0.19/raw/node22-typecheck-final.log +7 -0
- package/docs/reports/unified-9.0.19/raw/node22-typecheck-final.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/node22-version.log +1 -0
- package/docs/reports/unified-9.0.19/raw/node24-tests-final.log +1805 -0
- package/docs/reports/unified-9.0.19/raw/node24-tests-final.result.json +13 -0
- package/docs/reports/unified-9.0.19/raw/node24-typecheck-final.log +5 -0
- package/docs/reports/unified-9.0.19/raw/node24-typecheck-final.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/node24-version.log +1 -0
- package/docs/reports/unified-9.0.19/raw/sbom-runtime.log +7 -0
- package/docs/reports/unified-9.0.19/raw/sbom-runtime.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/sbom-vendor-check.log +1 -0
- package/docs/reports/unified-9.0.19/raw/sbom-vendor-check.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/tariff-price-chain-919.log +11 -0
- package/docs/reports/unified-9.0.19/raw/tariff-price-chain-919.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/tariff-price-chain-old-918.log +68 -0
- package/docs/reports/unified-9.0.19/raw/tariff-price-chain-old-918.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/ui-docs-check.log +6 -0
- package/docs/reports/unified-9.0.19/raw/ui-docs-check.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/ui-runtime-final.log +7 -0
- package/docs/reports/unified-9.0.19/raw/ui-runtime-final.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/ui-runtime-sync.log +6 -0
- package/docs/reports/unified-9.0.19/raw/ui-runtime-sync.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/ui-sbom-check.log +6 -0
- package/docs/reports/unified-9.0.19/raw/ui-sbom-check.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/ui-sbom-final.log +6 -0
- package/docs/reports/unified-9.0.19/raw/ui-sbom-final.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/ui-secret-final.log +6 -0
- package/docs/reports/unified-9.0.19/raw/ui-secret-final.result.json +14 -0
- package/docs/reports/unified-9.0.19/raw/ui-security-final.log +8 -0
- package/docs/reports/unified-9.0.19/raw/ui-security-final.result.json +14 -0
- package/io-package.json +12 -12
- package/modules/devices/admin/alias-contract-v1.json +189 -0
- package/modules/devices/admin/ems-assignment.d.ts +16 -0
- package/modules/devices/admin/ems-assignment.js +356 -0
- package/modules/devices/admin/host-bridge.js +76 -4
- package/modules/devices/admin/index.html +40 -1
- package/modules/devices/admin/index_m.js +158 -2
- package/modules/devices/admin/style.css +32 -4
- package/modules/devices/checks/emsAssignment.check.js +132 -0
- package/modules/devices/contracts.d.ts +1 -1
- package/modules/devices/eslint.hosted.config.mjs +1 -1
- package/modules/devices/index.js +64 -16
- 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/deviceAliasFreshness.js +65 -0
- package/modules/devices/lib/deviceAliasSemantics.js +109 -0
- package/modules/devices/lib/deviceRuntime.js +204 -127
- package/modules/devices/lib/drivers/modbus.js +18 -3
- package/modules/devices/lib/drivers/speedwire.js +42 -22
- package/modules/devices/test/aliasContractV1.test.js +1 -1
- package/modules/devices/test/deviceAliasFreshness.test.js +149 -0
- package/modules/devices/test/deviceAliasSemantics.test.js +163 -0
- package/modules/devices/test/emsAssignmentUi.test.js +298 -0
- package/modules/devices/test/modbusAuthorizationReads.test.js +112 -0
- package/modules/devices/test/runtimeLiveness.test.js +1 -1
- package/modules/devices/test/speedwireLifecycle.test.js +118 -0
- package/modules/devices/tsconfig.alias-semantics.json +17 -0
- package/modules/devices/tsconfig.ems-ui.json +9 -0
- package/modules/devices/tsconfig.hosted.json +1 -1
- package/package.json +11 -7
- package/release-manifests/unified/build-environment.cdx.json +1483 -7370
- package/release-manifests/unified/files.json +392 -121
- package/release-manifests/unified/frontend.cdx.json +2688 -5952
- package/release-manifests/unified/installer.cdx.json +2053 -821
- package/release-manifests/unified/obsolete-admin-assets.json +172 -6
- package/release-manifests/unified/runtime.cdx.json +40 -3283
- 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/engine.js +54 -7
- package/ui/ems/module-manager.js +44 -21
- package/ui/ems/modules/core-limits.js +5 -3
- package/ui/ems/modules/energy-wallet.js +31 -32
- package/ui/ems/modules/storage-control.js +5 -4
- package/ui/ems/modules/tarif-vis.js +36 -24
- package/ui/ems/modules/tariff-provider.js +259 -59
- package/ui/ems/services/tariff-provider-registry.js +11 -8
- package/ui/io-package.json +5 -1
- package/ui/lib/customer-tariff.js +245 -0
- package/ui/lib/installer-lifecycle.js +220 -0
- package/ui/lib/storage-farm-overview.js +115 -0
- package/ui/lib/tariff-price.js +115 -0
- package/ui/main.js +400 -163
- package/ui/package.json +14 -4
- package/ui/www/app.js +47 -134
- package/ui/www/customer-tariff.css +21 -0
- package/ui/www/customer-tariff.js +333 -0
- package/ui/www/ems-apps.html +2 -0
- package/ui/www/ems-apps.js +29 -7
- package/ui/www/index.html +2 -0
- package/ui/www/licenses/smarthome-markdown-components.json +156 -156
- package/ui/www/manifest.webmanifest +2 -2
- package/ui/www/power-measurements.js +62 -0
- package/ui/www/settings.html +47 -0
- package/ui/www/storagefarm-summary.css +17 -0
- package/ui/www/storagefarm-summary.js +136 -0
- package/ui/www/storagefarm.html +16 -1
- package/ui/www/storagefarm.js +10 -22
- package/ui/www/tariff-display.js +161 -0
|
@@ -0,0 +1,1147 @@
|
|
|
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 or writes device states. Explicit one-shot
|
|
13
|
+
* commissioning intents may enable validated rows/apps in the returned plan.
|
|
14
|
+
* Its output must pass the normal versioned configuration save.
|
|
15
|
+
* Existing non-empty installer assignments are authoritative.
|
|
16
|
+
* @typedef {import('./eosDeviceEmsPlan').Json} Json
|
|
17
|
+
* @typedef {{[key: string]: Json}} Dict
|
|
18
|
+
* @typedef {{id: string, type: string, unit: string, read: boolean, write: boolean, targetId: string}} Alias
|
|
19
|
+
* @typedef {{baseId: string, devId: string, name: string, templateId: string, protocol: string, deviceClass: string, enabled: boolean, aliases: Map<string, Alias>, ems: Dict, discoveryCode: string}} Device
|
|
20
|
+
* @typedef {{baseId: string, devId: string, status: string, code: string, target: string, mappedFields: string[], missing: string[], optionalMissing: string[], activationRequestId: string, activationApplied: boolean, corrections:string[]}} Status
|
|
21
|
+
*/
|
|
22
|
+
const MODES = new Set(['auto', 'monitor', 'manual', 'singleStorage', 'storageFarm', 'gridMeter', 'generationMeter', 'consumptionMeter', 'pvInverter']);
|
|
23
|
+
const STORAGE_CLASSES = new Set(['storageSystem', 'battery', 'batteryInverter']);
|
|
24
|
+
const MAX_DEVICES = 256;
|
|
25
|
+
const MAX_CONFIG_BYTES = 2 * 1024 * 1024;
|
|
26
|
+
const MAX_ROWS = 100;
|
|
27
|
+
const { Buffer } = require('node:buffer');
|
|
28
|
+
const { createHash } = require('node:crypto');
|
|
29
|
+
/** @param {unknown} value @returns {value is Dict} */
|
|
30
|
+
function isRecord(value) {
|
|
31
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) &&
|
|
32
|
+
[Object.prototype, null].includes(Object.getPrototypeOf(value));
|
|
33
|
+
}
|
|
34
|
+
/** @param {unknown} value @returns {Dict} */
|
|
35
|
+
function record(value) { return isRecord(value) ? value : {}; }
|
|
36
|
+
/** @param {unknown} value @returns {string} */
|
|
37
|
+
function text(value) { return typeof value === 'string' ? value.trim() : ''; }
|
|
38
|
+
/** @param {unknown} value @returns {boolean} */
|
|
39
|
+
function empty(value) { return value === undefined || value === null || value === ''; }
|
|
40
|
+
/** @param {string} code @returns {Error & {code: string}} */
|
|
41
|
+
function fail(code) { return Object.assign(new Error(code), { code }); }
|
|
42
|
+
/** Reject malformed/hostile config, rather than substituting an empty config. @param {unknown} value @returns {Dict} */
|
|
43
|
+
function copyConfig(value) {
|
|
44
|
+
if (!isRecord(value))
|
|
45
|
+
throw fail('EOS_EMS_PLAN_CONFIG_INVALID');
|
|
46
|
+
let nodes = 0;
|
|
47
|
+
/** @param {unknown} item @param {number} depth */
|
|
48
|
+
const visit = (item, depth) => {
|
|
49
|
+
if (++nodes > 100000 || depth > 24)
|
|
50
|
+
throw fail('EOS_EMS_PLAN_CONFIG_SIZE');
|
|
51
|
+
if (item === null || typeof item === 'boolean' || typeof item === 'string')
|
|
52
|
+
return;
|
|
53
|
+
if (typeof item === 'number' && Number.isFinite(item))
|
|
54
|
+
return;
|
|
55
|
+
if (Array.isArray(item)) {
|
|
56
|
+
for (const child of item)
|
|
57
|
+
visit(child, depth + 1);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!isRecord(item))
|
|
61
|
+
throw fail('EOS_EMS_PLAN_CONFIG_INVALID');
|
|
62
|
+
for (const [key, child] of Object.entries(item)) {
|
|
63
|
+
if (['__proto__', 'constructor', 'prototype'].includes(key))
|
|
64
|
+
throw fail('EOS_EMS_PLAN_CONFIG_KEY');
|
|
65
|
+
visit(child, depth + 1);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
visit(value, 0);
|
|
69
|
+
const serialized = JSON.stringify(value);
|
|
70
|
+
if (Buffer.byteLength(serialized) > MAX_CONFIG_BYTES)
|
|
71
|
+
throw fail('EOS_EMS_PLAN_CONFIG_SIZE');
|
|
72
|
+
return /** @type {Dict} */ (JSON.parse(serialized));
|
|
73
|
+
}
|
|
74
|
+
/** @param {Dict} parent @param {string} key @returns {Dict} */
|
|
75
|
+
function section(parent, key) {
|
|
76
|
+
if (!empty(parent[key]) && !isRecord(parent[key]))
|
|
77
|
+
throw fail('EOS_EMS_PLAN_SECTION_INVALID');
|
|
78
|
+
if (!isRecord(parent[key]))
|
|
79
|
+
parent[key] = {};
|
|
80
|
+
return /** @type {Dict} */ (parent[key]);
|
|
81
|
+
}
|
|
82
|
+
/** @param {Dict} parent @param {string} key @param {number} [max] @returns {Dict[]} */
|
|
83
|
+
function rows(parent, key, max = MAX_ROWS) {
|
|
84
|
+
if (parent[key] === undefined)
|
|
85
|
+
parent[key] = [];
|
|
86
|
+
const value = parent[key];
|
|
87
|
+
if (!Array.isArray(value) || value.length > max || value.some(row => !isRecord(row)))
|
|
88
|
+
throw fail('EOS_EMS_PLAN_ROWS_INVALID');
|
|
89
|
+
return /** @type {Dict[]} */ (value);
|
|
90
|
+
}
|
|
91
|
+
/** Only actual Alias V1 objects verified by the caller are accepted. @param {unknown} raw @returns {Device} */
|
|
92
|
+
function device(raw) {
|
|
93
|
+
const row = record(raw);
|
|
94
|
+
const baseId = text(row.baseId);
|
|
95
|
+
const devId = text(row.devId || row.deviceId);
|
|
96
|
+
if (!/^(?:eos-admin|nexowatt-devices)\.\d+\.devices\.[A-Za-z0-9_.-]+$/.test(baseId) || baseId.length > 450 ||
|
|
97
|
+
!devId || devId.length > 128 || !baseId.endsWith(`.devices.${devId}`))
|
|
98
|
+
throw fail('EOS_EMS_PLAN_DEVICE_INVALID');
|
|
99
|
+
const ems = record(row.ems);
|
|
100
|
+
if (ems.mode !== undefined && !MODES.has(text(ems.mode)))
|
|
101
|
+
throw fail('EOS_EMS_PLAN_INTENT_INVALID');
|
|
102
|
+
if (ems.scope !== undefined && !['M0', 'M1'].includes(text(ems.scope)))
|
|
103
|
+
throw fail('EOS_EMS_PLAN_INTENT_INVALID');
|
|
104
|
+
if (ems.flowSlot !== undefined && (!Number.isInteger(ems.flowSlot) || Number(ems.flowSlot) < 0 || Number(ems.flowSlot) > 10)) {
|
|
105
|
+
throw fail('EOS_EMS_PLAN_INTENT_INVALID');
|
|
106
|
+
}
|
|
107
|
+
if (ems.activation !== undefined) {
|
|
108
|
+
const activation = record(ems.activation);
|
|
109
|
+
if (typeof activation.requested !== 'boolean' || !/^[A-Za-z0-9][A-Za-z0-9_-]{15,127}$/.test(text(activation.requestId))) {
|
|
110
|
+
throw fail('EOS_EMS_PLAN_ACTIVATION_INVALID');
|
|
111
|
+
}
|
|
112
|
+
if (activation.limits !== undefined && !isRecord(activation.limits))
|
|
113
|
+
throw fail('EOS_EMS_PLAN_ACTIVATION_INVALID');
|
|
114
|
+
const numericLimits = new Set(['maxChargeW', 'maxDischargeW', 'capacityKWh', 'minCurrentA', 'maxCurrentA', 'minPowerW', 'maxPowerW']);
|
|
115
|
+
for (const [key, value] of Object.entries(record(activation.limits))) {
|
|
116
|
+
if (numericLimits.has(key)) {
|
|
117
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0 || value > 1000000000)
|
|
118
|
+
throw fail('EOS_EMS_PLAN_ACTIVATION_INVALID');
|
|
119
|
+
}
|
|
120
|
+
else if (key === 'coupling' || key === 'chargerType') {
|
|
121
|
+
if (value !== 'ac' && value !== 'dc')
|
|
122
|
+
throw fail('EOS_EMS_PLAN_ACTIVATION_INVALID');
|
|
123
|
+
}
|
|
124
|
+
else if (key === 'phases') {
|
|
125
|
+
if (value !== 1 && value !== 3)
|
|
126
|
+
throw fail('EOS_EMS_PLAN_ACTIVATION_INVALID');
|
|
127
|
+
}
|
|
128
|
+
else
|
|
129
|
+
throw fail('EOS_EMS_PLAN_ACTIVATION_INVALID');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const aliases = new Map();
|
|
133
|
+
const metadata = record(row.aliasMeta);
|
|
134
|
+
if (Object.keys(metadata).length > 512)
|
|
135
|
+
throw fail('EOS_EMS_PLAN_ALIAS_LIMIT');
|
|
136
|
+
for (const [key, item] of Object.entries(metadata)) {
|
|
137
|
+
const meta = record(item);
|
|
138
|
+
const id = text(meta.id);
|
|
139
|
+
if (!/^(?:r|ctrl|comm|alarm)\.[A-Za-z0-9_.]+$/.test(key) || id !== `${baseId}.aliases.v1.${key}`)
|
|
140
|
+
continue;
|
|
141
|
+
if (!['number', 'boolean', 'string'].includes(text(meta.type)))
|
|
142
|
+
continue;
|
|
143
|
+
const target = text(meta.targetId);
|
|
144
|
+
if (target.length > 512 || [...target].some(character => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127))
|
|
145
|
+
continue;
|
|
146
|
+
aliases.set(key, { id, type: text(meta.type), unit: text(meta.unit), read: meta.read !== false,
|
|
147
|
+
write: meta.write === true, targetId: target || id });
|
|
148
|
+
}
|
|
149
|
+
return { baseId, devId, name: text(row.name).slice(0, 128) || devId, templateId: text(row.templateId), protocol: text(row.protocol), deviceClass: text(row.deviceClass),
|
|
150
|
+
enabled: row.enabled !== false, aliases, ems, discoveryCode: text(row.discoveryCode) };
|
|
151
|
+
}
|
|
152
|
+
/** @param {Device} dev @param {string[]} keys @param {boolean} [write] @param {string[]} [types] @param {string[]} [units] @returns {string} */
|
|
153
|
+
function alias(dev, keys, write = false, types = ['number'], units = []) {
|
|
154
|
+
for (const key of keys) {
|
|
155
|
+
const meta = dev.aliases.get(key);
|
|
156
|
+
if (!meta || (write ? !meta.write : !meta.read) || !types.includes(meta.type))
|
|
157
|
+
continue;
|
|
158
|
+
if (units.length && !units.includes(meta.unit))
|
|
159
|
+
continue;
|
|
160
|
+
return meta.id;
|
|
161
|
+
}
|
|
162
|
+
return '';
|
|
163
|
+
}
|
|
164
|
+
/** @param {Device} dev @param {string} mode @returns {Dict} */
|
|
165
|
+
function identity(dev, mode) { return { v: 1, baseId: dev.baseId, devId: dev.devId, mode }; }
|
|
166
|
+
/** @param {Dict} row @param {Device} dev @returns {boolean} */
|
|
167
|
+
function belongs(row, dev) {
|
|
168
|
+
const owner = record(row._eosDevice);
|
|
169
|
+
if (owner.v === 1)
|
|
170
|
+
return owner.baseId === dev.baseId;
|
|
171
|
+
return Object.entries(row).some(([key, value]) => /(?:Id|ObjectId)$/.test(key) &&
|
|
172
|
+
typeof value === 'string' && value.startsWith(`${dev.baseId}.`));
|
|
173
|
+
}
|
|
174
|
+
/** @param {Dict} row @param {string} key @param {Json|undefined} value @param {Status} result */
|
|
175
|
+
function fill(row, key, value, result) {
|
|
176
|
+
if (value === undefined || value === '' || !empty(row[key]))
|
|
177
|
+
return;
|
|
178
|
+
row[key] = value;
|
|
179
|
+
result.mappedFields.push(key);
|
|
180
|
+
}
|
|
181
|
+
/** @param {Device} dev @returns {Status} */
|
|
182
|
+
function status(dev) { return { baseId: dev.baseId, devId: dev.devId, status: 'pending', code: 'ALIASES_PENDING', target: '', mappedFields: [], missing: [], optionalMissing: [], activationRequestId: text(record(dev.ems.activation).requestId), activationApplied: false, corrections: [] }; }
|
|
183
|
+
/** An entered power value is not an object ID. Keep it for correction, never resolve it as a DP. @param {unknown} value */
|
|
184
|
+
function numericReference(value) { return typeof value === 'number' || (typeof value === 'string' && /^[+-]?\d+(?:[.,]\d+)?$/.test(value.trim())); }
|
|
185
|
+
/** Only bounded configuration reference strings, never secrets or values, enter conflict detection. @param {unknown} value @returns {string[]} */
|
|
186
|
+
function mappedIds(value) {
|
|
187
|
+
const found = new Set();
|
|
188
|
+
let visited = 0;
|
|
189
|
+
/** @param {unknown} item @param {number} depth */
|
|
190
|
+
const walk = (item, depth) => {
|
|
191
|
+
if (!item || typeof item !== 'object' || depth > 12 || ++visited > 20000)
|
|
192
|
+
return;
|
|
193
|
+
for (const [key, child] of Object.entries(item)) {
|
|
194
|
+
if (key === '_eosDevice' || key === 'eosDeviceEms')
|
|
195
|
+
continue;
|
|
196
|
+
if (/(?:Id|ObjectId)$/.test(key) && typeof child === 'string' && child.length <= 512 && child && !numericReference(child))
|
|
197
|
+
found.add(child);
|
|
198
|
+
else if (child && typeof child === 'object')
|
|
199
|
+
walk(child, depth + 1);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
walk(value, 0);
|
|
203
|
+
return [...found];
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Exact references needed to resolve ioBroker aliases before planning. Only
|
|
207
|
+
* relevant EMS sections are scanned; the caller never needs an object dump.
|
|
208
|
+
* A split native alias is resolved separately for read and write directions.
|
|
209
|
+
* @param {unknown} value
|
|
210
|
+
* @returns {{read: string[], write: string[]}}
|
|
211
|
+
*/
|
|
212
|
+
function getDeviceEmsReferences(value) {
|
|
213
|
+
const config = copyConfig(value);
|
|
214
|
+
const read = new Set();
|
|
215
|
+
const write = new Set();
|
|
216
|
+
const writeKey = /(?:write|^set|^target|^output(?:Object)?Id$|^(?:pv)?feedInLimit|^pvLimit|^runObjectId$|^maxChargeObjectId$|^maxDischargeObjectId$|^phaseSwitchId$|^chargeEnableObjectId$|^dischargeEnableObjectId$|^feneconGridSetpoint|^e3dcSetPower|^enableId$)/i;
|
|
217
|
+
/** @param {unknown} item @param {number} depth */
|
|
218
|
+
const walk = (item, depth) => {
|
|
219
|
+
if (!item || typeof item !== 'object' || depth > 12)
|
|
220
|
+
return;
|
|
221
|
+
for (const [key, child] of Object.entries(item)) {
|
|
222
|
+
if (key === '_eosDevice' || key === 'eosDeviceEms')
|
|
223
|
+
continue;
|
|
224
|
+
if (/(?:Id|ObjectId)$/.test(key) && typeof child === 'string' && child.length <= 512 && child && !numericReference(child)) {
|
|
225
|
+
(writeKey.test(key) ? write : read).add(child);
|
|
226
|
+
}
|
|
227
|
+
else if (child && typeof child === 'object')
|
|
228
|
+
walk(child, depth + 1);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
for (const item of [record(config.settingsConfig).evcsList, config.storage, config.storageFarm,
|
|
232
|
+
config.gridConstraints, config.thermalControl, config.thermal, config.vis, config.heatingRod, config.threshold,
|
|
233
|
+
config.generator, config.bhkw, config.dynamicGridConnection])
|
|
234
|
+
walk(item, 0);
|
|
235
|
+
for (const [key, id] of Object.entries(record(config.datapoints))) {
|
|
236
|
+
if (/^(?:pvPower|producer\d+Power|consumer\d+Power|gridPointPower|consumptionEvcs|batteryPower|storageSoc)$/.test(key) && typeof id === 'string' && id.length <= 512 && id)
|
|
237
|
+
read.add(id);
|
|
238
|
+
}
|
|
239
|
+
if (read.size + write.size > 1024)
|
|
240
|
+
throw fail('EOS_EMS_PLAN_REFERENCE_LIMIT');
|
|
241
|
+
return { read: [...read].sort(), write: [...write].sort() };
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* @param {{config: unknown, devices: unknown, limits?: {chargePoints?: unknown, batteries?: unknown}, writeTargets?: Record<string,string>, readTargets?: Record<string,string>, referenceMeta?: Record<string,{type?:unknown,unit?:unknown,read?:unknown,write?:unknown}>, allowedApps?:string[]}} input
|
|
245
|
+
* @returns {{config: Dict, patch: Dict, changed: boolean, statuses: Status[]}}
|
|
246
|
+
*/
|
|
247
|
+
function planDeviceEms(input) {
|
|
248
|
+
const before = copyConfig(input.config);
|
|
249
|
+
const config = copyConfig(before);
|
|
250
|
+
if (!Array.isArray(input.devices) || input.devices.length > MAX_DEVICES)
|
|
251
|
+
throw fail('EOS_EMS_PLAN_DEVICE_LIMIT');
|
|
252
|
+
const devices = input.devices.map(device).sort((a, b) => a.baseId.localeCompare(b.baseId, 'en'));
|
|
253
|
+
if (new Set(devices.map(dev => dev.baseId)).size !== devices.length)
|
|
254
|
+
throw fail('EOS_EMS_PLAN_DEVICE_DUPLICATE');
|
|
255
|
+
const canonical = new Map(Object.entries(input.writeTargets || {}).filter(([id, target]) => typeof id === 'string' && id.length <= 512 && typeof target === 'string' && target.length <= 512));
|
|
256
|
+
const canonicalRead = new Map(Object.entries(input.readTargets || {}).filter(([id, target]) => typeof id === 'string' && id.length <= 512 && typeof target === 'string' && target.length <= 512));
|
|
257
|
+
for (const dev of devices)
|
|
258
|
+
for (const meta of dev.aliases.values())
|
|
259
|
+
canonical.set(meta.id, meta.targetId);
|
|
260
|
+
for (const dev of devices)
|
|
261
|
+
for (const meta of dev.aliases.values())
|
|
262
|
+
if (meta.read)
|
|
263
|
+
canonicalRead.set(meta.id, meta.targetId);
|
|
264
|
+
/** @param {string} id */
|
|
265
|
+
const targetOf = id => canonical.get(id) || id;
|
|
266
|
+
/** @param {string} id */
|
|
267
|
+
const readTargetOf = id => canonicalRead.get(id) || id;
|
|
268
|
+
/** @param {unknown} value @param {number} hard */
|
|
269
|
+
const limit = (value, hard) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? Math.min(value, hard) : 0;
|
|
270
|
+
const evLimit = limit(input.limits?.chargePoints, 50);
|
|
271
|
+
const storageLimit = limit(input.limits?.batteries, MAX_ROWS);
|
|
272
|
+
/** @type {Status[]} */
|
|
273
|
+
const statuses = [];
|
|
274
|
+
/** Existing live rows are restored if explicit commissioning cannot complete. @type {Map<string, Dict>} */
|
|
275
|
+
const activeOriginals = new Map();
|
|
276
|
+
/** @param {Device} dev @returns {Dict} */
|
|
277
|
+
const binding = dev => record(record(record(config.eosDeviceEms).bindings)[dev.baseId]);
|
|
278
|
+
/** @param {Device} dev */
|
|
279
|
+
const explicitApply = dev => record(dev.ems.activation).requested === true &&
|
|
280
|
+
text(record(dev.ems.activation).requestId) !== text(binding(dev).activationRequestId);
|
|
281
|
+
/** @param {Device} dev */
|
|
282
|
+
const requestFingerprint = dev => {
|
|
283
|
+
const activation = record(dev.ems.activation);
|
|
284
|
+
const bounds = record(activation.limits);
|
|
285
|
+
return createHash('sha256').update(JSON.stringify({ requested: activation.requested, mode: dev.ems.mode || 'auto',
|
|
286
|
+
scope: dev.ems.scope || '', flowSlot: dev.ems.flowSlot ?? null, templateId: dev.templateId, protocol: dev.protocol, deviceClass: dev.deviceClass,
|
|
287
|
+
limits: Object.fromEntries(Object.keys(bounds).sort().map(key => [key, bounds[key]])) })).digest('hex');
|
|
288
|
+
};
|
|
289
|
+
/** @param {string} id @param {Device} dev */
|
|
290
|
+
const belongsReference = (id, dev) => id.startsWith(`${dev.baseId}.`) || [...dev.aliases.values()].some(meta => meta.read && readTargetOf(id) === readTargetOf(meta.id) || meta.write && targetOf(id) === targetOf(meta.id));
|
|
291
|
+
/** Only identity-bearing measurement/command fields may adopt a legacy row. @param {Dict} row @returns {string[]} */
|
|
292
|
+
const primaryIds = row => Object.entries(row).flatMap(([key, value]) => {
|
|
293
|
+
if (key === 'datapoints' && isRecord(value))
|
|
294
|
+
return primaryIds(value);
|
|
295
|
+
return /^(?:socId|socObjectId|signedPowerId|batteryPowerObjectId|powerId|energyTotalId|chargePowerId|dischargePowerId|setSignedPowerId|setChargePowerId|setDischargePowerId|targetPowerObjectId|targetChargePowerObjectId|targetDischargePowerObjectId|setCurrentAId|setPowerWId|feneconEssActualPowerId|feneconEssActualPowerObjectId)$/.test(key)
|
|
296
|
+
&& typeof value === 'string' && value && !numericReference(value) ? [value] : [];
|
|
297
|
+
});
|
|
298
|
+
/** @param {Dict} row @param {Device} dev */
|
|
299
|
+
const belongsDevice = (row, dev) => record(row._eosDevice).v === 1 ? record(row._eosDevice).baseId === dev.baseId
|
|
300
|
+
: belongs(row, dev) || explicitApply(dev) && primaryIds(row).some(id => belongsReference(id, dev));
|
|
301
|
+
/** @param {Dict} row @param {Device} dev */
|
|
302
|
+
const mixedIdentity = (row, dev) => primaryIds(row).some(id => !belongsReference(id, dev));
|
|
303
|
+
/** @param {Dict} row @param {Device} dev @param {string} mode @param {string} target */
|
|
304
|
+
const remember = (row, dev, mode, target) => {
|
|
305
|
+
if (!row._eosDevice)
|
|
306
|
+
row._eosDevice = identity(dev, mode);
|
|
307
|
+
const registry = section(config, 'eosDeviceEms');
|
|
308
|
+
if (registry.v !== undefined && registry.v !== 1)
|
|
309
|
+
throw fail('EOS_EMS_PLAN_BINDING_VERSION');
|
|
310
|
+
registry.v = 1;
|
|
311
|
+
const bindings = section(registry, 'bindings');
|
|
312
|
+
const next = { target, mode, ...(dev.ems.scope ? { scope: dev.ems.scope } : {}),
|
|
313
|
+
...(dev.ems.flowSlot !== undefined ? { flowSlot: dev.ems.flowSlot } : {}) };
|
|
314
|
+
bindings[dev.baseId] = { ...record(bindings[dev.baseId]), ...next };
|
|
315
|
+
};
|
|
316
|
+
/** @param {Device} dev @param {Dict} candidate @param {unknown[]} competing @returns {boolean} */
|
|
317
|
+
const conflict = (dev, candidate, competing) => {
|
|
318
|
+
const writes = new Set([...dev.aliases.values()].filter(meta => meta.write).map(meta => targetOf(meta.id)));
|
|
319
|
+
const candidateWrites = mappedIds(candidate).map(targetOf).filter(id => writes.has(id));
|
|
320
|
+
return competing.some(other => mappedIds(other).some(id => candidateWrites.includes(targetOf(id))));
|
|
321
|
+
};
|
|
322
|
+
/** @param {Device} dev @param {Status} result */
|
|
323
|
+
const ev = (dev, result) => {
|
|
324
|
+
const settings = section(config, 'settingsConfig');
|
|
325
|
+
const list = rows(settings, 'evcsList', 50);
|
|
326
|
+
const found = list.filter(row => belongsDevice(row, dev));
|
|
327
|
+
if (found.length > 1) {
|
|
328
|
+
result.status = 'conflict';
|
|
329
|
+
result.code = 'DUPLICATE_DEVICE_MAPPING';
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (found.length && mixedIdentity(found[0], dev)) {
|
|
333
|
+
result.status = 'conflict';
|
|
334
|
+
result.code = 'MIXED_MANUAL_MAPPING';
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (!found.length && list.length >= evLimit) {
|
|
338
|
+
result.status = 'conflict';
|
|
339
|
+
result.code = 'LICENSE_LIMIT';
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const row = found[0] || { enabled: false };
|
|
343
|
+
if (found.length && row.enabled !== false && explicitApply(dev))
|
|
344
|
+
activeOriginals.set(dev.baseId, copyConfig(row));
|
|
345
|
+
const next = copyConfig(row);
|
|
346
|
+
fill(next, 'name', dev.name, result);
|
|
347
|
+
const fields = {
|
|
348
|
+
powerId: alias(dev, ['r.power'], false, ['number'], ['W']),
|
|
349
|
+
energyTotalId: alias(dev, ['r.energyTotal'], false, ['number'], ['Wh', 'kWh']),
|
|
350
|
+
statusId: alias(dev, ['r.mode3State', 'r.mode3Code', 'r.evState', 'r.statusText', 'r.statusCode'], false, ['string', 'number']),
|
|
351
|
+
vehicleConnectedId: alias(dev, ['r.vehicleConnected'], false, ['boolean']),
|
|
352
|
+
chargeDemandId: alias(dev, ['r.chargeDemand', 'r.vehicleDemand', 'r.readyToCharge', 'r.chargingRequested'], false, ['boolean']),
|
|
353
|
+
heartbeatId: alias(dev, ['r.heartbeat', 'r.lastSeenMs']),
|
|
354
|
+
onlineId: alias(dev, ['r.online', 'comm.connected'], false, ['boolean']),
|
|
355
|
+
setCurrentAId: alias(dev, ['ctrl.targetCurrentA', 'ctrl.currentLimitA', 'ctrl.setCurrentA'], true, ['number'], ['A']),
|
|
356
|
+
setPowerWId: alias(dev, ['ctrl.targetPowerW', 'ctrl.powerLimitW', 'ctrl.setPowerW'], true, ['number'], ['W']),
|
|
357
|
+
enableWriteId: alias(dev, ['ctrl.run', 'ctrl.enable', 'ctrl.enabled'], true, ['boolean']),
|
|
358
|
+
};
|
|
359
|
+
if (!Object.values(fields).some(Boolean)) {
|
|
360
|
+
result.code = 'ALIASES_PENDING';
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
for (const [key, value] of Object.entries(fields))
|
|
364
|
+
fill(next, key, value, result);
|
|
365
|
+
if (fields.energyTotalId && empty(row.energyTotalId)) {
|
|
366
|
+
const meta = [...dev.aliases.values()].find(item => item.id === fields.energyTotalId);
|
|
367
|
+
fill(next, 'energyTotalInputIsWh', meta?.unit === 'Wh', result);
|
|
368
|
+
}
|
|
369
|
+
if (conflict(dev, next, [list.filter(item => item !== row), config.storage, config.storageFarm, config.gridConstraints,
|
|
370
|
+
config.thermalControl, config.thermal, config.vis, config.heatingRod, config.threshold, config.generator, config.bhkw])) {
|
|
371
|
+
result.status = 'conflict';
|
|
372
|
+
result.code = 'CONTROL_TARGET_ALREADY_ASSIGNED';
|
|
373
|
+
result.mappedFields = [];
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (!next.powerId)
|
|
377
|
+
result.missing.push('powerId');
|
|
378
|
+
if (!next.setCurrentAId && !next.setPowerWId)
|
|
379
|
+
result.missing.push('setCurrentAId|setPowerWId');
|
|
380
|
+
if (!next.onlineId && !next.heartbeatId)
|
|
381
|
+
result.missing.push('onlineId|heartbeatId');
|
|
382
|
+
remember(next, dev, 'auto', 'evcs');
|
|
383
|
+
if (found.length)
|
|
384
|
+
list[list.indexOf(row)] = next;
|
|
385
|
+
else
|
|
386
|
+
list.push(next);
|
|
387
|
+
const count = settings.evcsCount;
|
|
388
|
+
if (count !== undefined && (typeof count !== 'number' || !Number.isSafeInteger(count) || count < 0 || count > 50)) {
|
|
389
|
+
throw fail('EOS_EMS_PLAN_EVCS_COUNT_INVALID');
|
|
390
|
+
}
|
|
391
|
+
settings.evcsCount = Math.max(typeof count === 'number' ? count : 0, list.length);
|
|
392
|
+
result.target = 'settingsConfig.evcsList';
|
|
393
|
+
result.status = 'mapped';
|
|
394
|
+
result.code = result.missing.length ? 'MAPPING_INCOMPLETE' : next.enabled === false ? 'COMMISSIONING_REQUIRED' : 'MAPPED';
|
|
395
|
+
};
|
|
396
|
+
/** @param {Device} dev @param {Status} result @param {boolean} farm */
|
|
397
|
+
const storage = (dev, result, farm) => {
|
|
398
|
+
if (dev.ems.scope === 'M1') {
|
|
399
|
+
result.code = 'MANUAL_TOPOLOGY_REQUIRED';
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const single = record(config.storage);
|
|
403
|
+
const farmConfig = record(config.storageFarm);
|
|
404
|
+
const farmRows = Array.isArray(farmConfig.storages) ? farmConfig.storages.filter(isRecord) : [];
|
|
405
|
+
const singleAssigned = mappedIds(single).some(Boolean);
|
|
406
|
+
const existingSameSingle = belongsDevice(single, dev);
|
|
407
|
+
const existingSameFarm = farmRows.filter(row => belongsDevice(row, dev));
|
|
408
|
+
if ((farm && existingSameSingle) || (!farm && existingSameFarm.length) || existingSameFarm.length > 1) {
|
|
409
|
+
result.status = 'conflict';
|
|
410
|
+
result.code = 'STORAGE_CONTROLLER_ALREADY_ASSIGNED';
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (!farm && singleAssigned && !existingSameSingle) {
|
|
414
|
+
result.status = 'conflict';
|
|
415
|
+
result.code = 'MANUAL_MAPPING_PRESERVED';
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const existing = farm ? existingSameFarm[0] : existingSameSingle ? single : undefined;
|
|
419
|
+
if (existing && mixedIdentity(existing, dev)) {
|
|
420
|
+
result.status = 'conflict';
|
|
421
|
+
result.code = 'MIXED_MANUAL_MAPPING';
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (!existing && farmRows.length + (singleAssigned ? 1 : 0) >= storageLimit) {
|
|
425
|
+
result.status = 'conflict';
|
|
426
|
+
result.code = 'LICENSE_LIMIT';
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
// A preconfigured, as-yet-unassigned single-storage section can contain
|
|
430
|
+
// customer limits and vendor settings. Keep these when adding aliases.
|
|
431
|
+
// A new assignment still needs commissioning even if its empty section
|
|
432
|
+
// had enabled=true from an earlier installer selection.
|
|
433
|
+
const row = existing ? copyConfig(existing) : farm ? { enabled: false } : { ...copyConfig(single), enabled: false };
|
|
434
|
+
if (existing && existing.enabled !== false && explicitApply(dev))
|
|
435
|
+
activeOriginals.set(dev.baseId, copyConfig(existing));
|
|
436
|
+
if (existing && !existing._eosDevice && explicitApply(dev))
|
|
437
|
+
result.corrections.push('LEGACY_ROW_ADOPTED');
|
|
438
|
+
const destination = farm ? row : section(row, 'datapoints');
|
|
439
|
+
fill(row, 'name', dev.name, result);
|
|
440
|
+
const feneconHome = dev.templateId === 'ess.fenecon.FeneconHomeEssImpl';
|
|
441
|
+
/** Exact known Home source; an arbitrary alias with a familiar name is not sufficient. @param {string[]} names @param {string} source @param {boolean} [write] */
|
|
442
|
+
const homePower = (names, source, write = false) => {
|
|
443
|
+
for (const name of names) {
|
|
444
|
+
const id = alias(dev, [name], write, ['number'], ['W']);
|
|
445
|
+
if (id && dev.aliases.get(name)?.targetId === `${dev.baseId}.${source}`)
|
|
446
|
+
return id;
|
|
447
|
+
}
|
|
448
|
+
return '';
|
|
449
|
+
};
|
|
450
|
+
const homeFeedback = feneconHome ? homePower(['r.essActivePower'], 'eSS0_ACTIVE_POWER') : '';
|
|
451
|
+
if (feneconHome && homeFeedback && explicitApply(dev)) {
|
|
452
|
+
const old = text(destination[farm ? 'signedPowerId' : 'batteryPowerObjectId']);
|
|
453
|
+
const oldActor = text(destination[farm ? 'feneconEssActualPowerId' : 'feneconEssActualPowerObjectId']);
|
|
454
|
+
/** @param {string} value */
|
|
455
|
+
const isWrongFeedback = value => value && (['r.power', 'r.powerAc', 'r.powerBalance'].some(key => value === `${dev.baseId}.aliases.${key}` || value === `${dev.baseId}.aliases.v1.${key}`) ||
|
|
456
|
+
[`${dev.baseId}.bATTERY_AC_POWER`, `${dev.baseId}.bATTERY_POWER`].includes(readTargetOf(value)));
|
|
457
|
+
if (isWrongFeedback(old)) {
|
|
458
|
+
destination[farm ? 'signedPowerId' : 'batteryPowerObjectId'] = homeFeedback;
|
|
459
|
+
result.corrections.push('FENECON_ACTOR_FEEDBACK_CORRECTED');
|
|
460
|
+
}
|
|
461
|
+
if (isWrongFeedback(oldActor)) {
|
|
462
|
+
destination[farm ? 'feneconEssActualPowerId' : 'feneconEssActualPowerObjectId'] = homeFeedback;
|
|
463
|
+
if (!result.corrections.includes('FENECON_ACTOR_FEEDBACK_CORRECTED'))
|
|
464
|
+
result.corrections.push('FENECON_ACTOR_FEEDBACK_CORRECTED');
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
const keys = farm ? {
|
|
468
|
+
socId: ['r.soc'], signedPowerId: feneconHome ? [] : ['r.essActivePower', 'r.powerAc', 'r.power'],
|
|
469
|
+
chargePowerId: ['r.powerCharge'], dischargePowerId: ['r.powerDischarge'],
|
|
470
|
+
availableId: ['r.online', 'comm.connected'], faultId: ['alarm.fault'],
|
|
471
|
+
chargeAllowedId: ['r.allowCharge'], dischargeAllowedId: ['r.allowDischarge'],
|
|
472
|
+
} : {
|
|
473
|
+
socObjectId: ['r.soc'], batteryPowerObjectId: feneconHome ? [] : ['r.essActivePower', 'r.powerAc', 'r.power'],
|
|
474
|
+
};
|
|
475
|
+
for (const [key, names] of Object.entries(keys)) {
|
|
476
|
+
const booleanField = ['availableId', 'faultId', 'chargeAllowedId', 'dischargeAllowedId'].includes(key);
|
|
477
|
+
fill(destination, key, alias(dev, names, false, booleanField ? ['boolean'] : ['number'], key.startsWith('soc') ? ['%'] : booleanField ? [] : ['W']), result);
|
|
478
|
+
}
|
|
479
|
+
const signed = feneconHome ? homePower(['ctrl.powerSetpointW'], 'sET_ACTIVE_POWER', true)
|
|
480
|
+
: alias(dev, ['ctrl.powerSetpointW'], true, ['number'], ['W']);
|
|
481
|
+
const charge = alias(dev, ['ctrl.chargePowerW'], true, ['number'], ['W']);
|
|
482
|
+
const discharge = alias(dev, ['ctrl.dischargePowerW'], true, ['number'], ['W']);
|
|
483
|
+
const commandKeys = farm ? ['setSignedPowerId', 'setChargePowerId', 'setDischargePowerId', 'feneconGridSetpointId']
|
|
484
|
+
: ['targetPowerObjectId', 'targetChargePowerObjectId', 'targetDischargePowerObjectId', 'feneconGridSetpointObjectId', 'e3dcSetPowerModeObjectId', 'e3dcSetPowerValueObjectId'];
|
|
485
|
+
const hadCommand = commandKeys.some(key => !empty(destination[key]));
|
|
486
|
+
if (feneconHome) {
|
|
487
|
+
if (!existing || row.enabled === false || !hadCommand) {
|
|
488
|
+
fill(row, 'vendorProfile', 'fenecon-openems', result);
|
|
489
|
+
fill(row, 'coupling', 'dc', result);
|
|
490
|
+
}
|
|
491
|
+
// Detection does not switch a commissioned FEMS controller into a
|
|
492
|
+
// different command family. New Home rows use the verified direct
|
|
493
|
+
// ESS path; the optional native target is exposed separately.
|
|
494
|
+
fill(row, 'feneconControlMode', existing && hadCommand ? 'auto' : 'direct-ess', result);
|
|
495
|
+
fill(destination, farm ? 'signedPowerId' : 'batteryPowerObjectId', homeFeedback, result);
|
|
496
|
+
/** @type {[string, string[], string][]} */
|
|
497
|
+
const homeFields = [
|
|
498
|
+
['feneconEssActualPower', ['r.essActivePower'], 'eSS0_ACTIVE_POWER'],
|
|
499
|
+
['feneconNvpPower', ['r.nvpPower', 'r.gridPower', 'r.napPower'], 'gRID_POWER'],
|
|
500
|
+
['feneconConsumptionTotal', ['r.consumptionTotal', 'r.loadTotal', 'r.consumptionPower', 'r.loadPower'], 'lOAD_POWER'],
|
|
501
|
+
['feneconMinPower', ['r.minPowerSetpointW'], 'mIN_POWER_SETPOINT'],
|
|
502
|
+
['feneconMaxPower', ['r.maxPowerSetpointW'], 'mAX_POWER_SETPOINT'],
|
|
503
|
+
['feneconPvDc', ['r.pvPowerDc'], 'pV_DC_POWER'],
|
|
504
|
+
['feneconPvAc', ['r.pvPowerAc'], 'pV_AC_POWER'],
|
|
505
|
+
['feneconPvTotal', ['r.pvPowerTotal'], 'pV_POWER_SUM'],
|
|
506
|
+
];
|
|
507
|
+
for (const field of homeFields) {
|
|
508
|
+
const key = `${field[0]}${farm ? 'Id' : 'ObjectId'}`;
|
|
509
|
+
fill(destination, key, homePower(field[1], field[2]), result);
|
|
510
|
+
if (empty(destination[key]) && field[0] !== 'feneconEssActualPower')
|
|
511
|
+
result.optionalMissing.push(key);
|
|
512
|
+
}
|
|
513
|
+
const gridKey = farm ? 'feneconGridSetpointId' : 'feneconGridSetpointObjectId';
|
|
514
|
+
const nativeGrid = homePower(['ctrl.gridSetpointW', 'ctrl.napSetpointW'], 'sET_GRID_ACTIVE_POWER', true);
|
|
515
|
+
const oldGrid = text(destination[gridKey]);
|
|
516
|
+
if (explicitApply(dev) && oldGrid && (oldGrid === `${dev.baseId}.aliases.ctrl.powerSetpointW` ||
|
|
517
|
+
oldGrid === `${dev.baseId}.aliases.v1.ctrl.powerSetpointW` || targetOf(oldGrid) === `${dev.baseId}.sET_ACTIVE_POWER`)) {
|
|
518
|
+
destination[gridKey] = nativeGrid;
|
|
519
|
+
result.corrections.push('FENECON_NATIVE_TARGET_CORRECTED');
|
|
520
|
+
}
|
|
521
|
+
const multipleFarm = farm && devices.filter(item => item.enabled && item.ems.mode === 'storageFarm').length > 1;
|
|
522
|
+
if (explicitApply(dev) && signed && homeFeedback && multipleFarm && row.feneconControlMode !== 'direct-ess') {
|
|
523
|
+
row.feneconControlMode = 'direct-ess';
|
|
524
|
+
result.corrections.push('FENECON_DIRECT_ESS_SELECTED');
|
|
525
|
+
}
|
|
526
|
+
// Populate both real target references without changing an existing
|
|
527
|
+
// mode: direct-ess uses 706; fems-grid uses its guarded controller.
|
|
528
|
+
const directMode = row.feneconControlMode === 'direct-ess';
|
|
529
|
+
if (directMode && !commandKeys.slice(0, 3).some(key => !empty(destination[key])) && signed) {
|
|
530
|
+
fill(destination, commandKeys[0], signed, result);
|
|
531
|
+
}
|
|
532
|
+
const preserveAutoDirect = !explicitApply(dev) && existing && row.enabled !== false && empty(destination[gridKey]) &&
|
|
533
|
+
!['direct-ess', 'fems-grid'].includes(text(row.feneconControlMode)) &&
|
|
534
|
+
commandKeys.slice(0, 3).some(key => !empty(destination[key]));
|
|
535
|
+
if (preserveAutoDirect && nativeGrid)
|
|
536
|
+
result.missing.push(`review:${gridKey}`);
|
|
537
|
+
else {
|
|
538
|
+
fill(destination, gridKey, nativeGrid, result);
|
|
539
|
+
if (empty(destination[gridKey]))
|
|
540
|
+
result.optionalMissing.push(gridKey);
|
|
541
|
+
}
|
|
542
|
+
const readbackKey = farm ? 'feneconActualSetpointId' : 'feneconActualSetpointObjectId';
|
|
543
|
+
const readback = dev.aliases.get('r.powerSetpointReadbackW');
|
|
544
|
+
const actualReadback = readback && readback.read && !readback.write &&
|
|
545
|
+
![`${dev.baseId}.sET_ACTIVE_POWER`, `${dev.baseId}.sET_GRID_ACTIVE_POWER`].includes(readback.targetId)
|
|
546
|
+
? alias(dev, ['r.powerSetpointReadbackW'], false, ['number'], ['W']) : '';
|
|
547
|
+
fill(destination, readbackKey, actualReadback, result);
|
|
548
|
+
if (empty(destination[readbackKey]))
|
|
549
|
+
result.optionalMissing.push(readbackKey);
|
|
550
|
+
if (row.vendorProfile !== 'fenecon-openems')
|
|
551
|
+
result.missing.push('vendorProfile:fenecon-openems');
|
|
552
|
+
if (!homeFeedback && empty(destination[farm ? 'feneconEssActualPowerId' : 'feneconEssActualPowerObjectId'])) {
|
|
553
|
+
result.missing.push(farm ? 'feneconEssActualPowerId' : 'feneconEssActualPowerObjectId');
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
if (!commandKeys.some(key => !empty(destination[key]))) {
|
|
557
|
+
if (signed)
|
|
558
|
+
fill(destination, commandKeys[0], signed, result);
|
|
559
|
+
else if (charge && discharge) {
|
|
560
|
+
fill(destination, commandKeys[1], charge, result);
|
|
561
|
+
fill(destination, commandKeys[2], discharge, result);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (!hadCommand && commandKeys.some(key => !empty(destination[key])))
|
|
565
|
+
row.enabled = false;
|
|
566
|
+
if (!farm) {
|
|
567
|
+
fill(destination, 'runObjectId', alias(dev, ['ctrl.run'], true, ['boolean']), result);
|
|
568
|
+
fill(destination, 'maxChargeObjectId', alias(dev, ['ctrl.maxChargePowerW'], true, ['number'], ['W']), result);
|
|
569
|
+
fill(destination, 'maxDischargeObjectId', alias(dev, ['ctrl.maxDischargePowerW'], true, ['number'], ['W']), result);
|
|
570
|
+
fill(destination, 'chargeEnableObjectId', alias(dev, ['ctrl.chargeEnable'], true, ['boolean']), result);
|
|
571
|
+
fill(destination, 'dischargeEnableObjectId', alias(dev, ['ctrl.dischargeEnable'], true, ['boolean']), result);
|
|
572
|
+
}
|
|
573
|
+
const dcPv = feneconHome ? homePower(['r.pvPowerDc'], 'pV_DC_POWER') : alias(dev, ['r.pvPowerDc'], false, ['number'], ['W']);
|
|
574
|
+
const acPv = feneconHome ? homePower(['r.pvPowerAc'], 'pV_AC_POWER') : alias(dev, ['r.pvPowerAc'], false, ['number'], ['W']);
|
|
575
|
+
if (dcPv && empty(row.coupling) && (!existing || row.enabled === false || !hadCommand))
|
|
576
|
+
fill(row, 'coupling', 'dc', result);
|
|
577
|
+
if (row.coupling === 'dc')
|
|
578
|
+
fill(destination, farm ? 'pvPowerId' : 'dcPvPowerObjectId', dcPv, result);
|
|
579
|
+
else if (farm && row.coupling === 'ac')
|
|
580
|
+
fill(destination, 'pvPowerId', acPv, result);
|
|
581
|
+
const pvKey = farm ? 'pvPowerId' : 'dcPvPowerObjectId';
|
|
582
|
+
if (explicitApply(dev) && numericReference(destination[pvKey]) && row.coupling === 'dc' && dcPv) {
|
|
583
|
+
destination[pvKey] = dcPv;
|
|
584
|
+
result.corrections.push('PV_POWER_REFERENCE_CORRECTED');
|
|
585
|
+
}
|
|
586
|
+
// The Home ESS actuator channel 604 is deliberately separate from the
|
|
587
|
+
// physical battery/display channel 415. Never feed its DC-PV component
|
|
588
|
+
// into the home's displayed battery discharge a second time.
|
|
589
|
+
const batteryFlow = feneconHome ? alias(dev, ['r.powerAc', 'r.power'], false, ['number'], ['W']) : '';
|
|
590
|
+
if (farm && batteryFlow)
|
|
591
|
+
fill(row, 'batteryFlowPowerId', batteryFlow, result);
|
|
592
|
+
if (!farm && batteryFlow) {
|
|
593
|
+
const globalDp = section(config, 'datapoints');
|
|
594
|
+
if (empty(globalDp.batteryPower)) {
|
|
595
|
+
fill(globalDp, 'batteryPower', batteryFlow, result);
|
|
596
|
+
section(section(config, 'settings'), 'flowPowerDpIsW').batteryPower = true;
|
|
597
|
+
}
|
|
598
|
+
fill(globalDp, 'storageSoc', alias(dev, ['r.soc'], false, ['number'], ['%']), result);
|
|
599
|
+
}
|
|
600
|
+
if (!mappedIds(destination).length) {
|
|
601
|
+
result.code = 'ALIASES_PENDING';
|
|
602
|
+
result.mappedFields = [];
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const competing = [farm ? [single, ...farmRows.filter(item => item !== existing)] : farmRows,
|
|
606
|
+
record(config.settingsConfig).evcsList, config.gridConstraints, config.thermalControl, config.thermal, config.vis,
|
|
607
|
+
config.heatingRod, config.threshold, config.generator, config.bhkw];
|
|
608
|
+
if (conflict(dev, row, competing)) {
|
|
609
|
+
result.status = 'conflict';
|
|
610
|
+
result.code = 'CONTROL_TARGET_ALREADY_ASSIGNED';
|
|
611
|
+
result.mappedFields = [];
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const socKey = farm ? 'socId' : 'socObjectId';
|
|
615
|
+
const powerKey = farm ? 'signedPowerId' : 'batteryPowerObjectId';
|
|
616
|
+
if (!destination[socKey])
|
|
617
|
+
result.missing.push(socKey);
|
|
618
|
+
if (!destination[powerKey])
|
|
619
|
+
result.missing.push(powerKey);
|
|
620
|
+
const controlKeys = feneconHome && row.feneconControlMode === 'direct-ess' ? commandKeys.slice(0, 3)
|
|
621
|
+
: feneconHome && row.feneconControlMode === 'fems-grid' ? [farm ? 'feneconGridSetpointId' : 'feneconGridSetpointObjectId'] : commandKeys;
|
|
622
|
+
if (!controlKeys.some(key => !empty(destination[key]) && !numericReference(destination[key])))
|
|
623
|
+
result.missing.push('storageControl');
|
|
624
|
+
for (const [key, value] of Object.entries(destination)) {
|
|
625
|
+
if (/(?:Id|ObjectId)$/.test(key) && numericReference(value))
|
|
626
|
+
result.missing.push(`invalid:${key}`);
|
|
627
|
+
}
|
|
628
|
+
remember(row, dev, farm ? 'storageFarm' : 'singleStorage', farm ? 'storageFarm' : 'storage');
|
|
629
|
+
if (farm) {
|
|
630
|
+
const list = rows(section(config, 'storageFarm'), 'storages');
|
|
631
|
+
if (existing)
|
|
632
|
+
list[list.findIndex(item => belongsDevice(item, dev))] = row;
|
|
633
|
+
else
|
|
634
|
+
list.push(row);
|
|
635
|
+
}
|
|
636
|
+
else
|
|
637
|
+
config.storage = row;
|
|
638
|
+
result.target = farm ? 'storageFarm.storages' : 'storage';
|
|
639
|
+
result.status = 'mapped';
|
|
640
|
+
result.code = result.missing.length ? 'MAPPING_INCOMPLETE' : row.enabled === false ? 'COMMISSIONING_REQUIRED' : 'MAPPED';
|
|
641
|
+
};
|
|
642
|
+
/** @param {Device} dev @param {Status} result @param {string} mode */
|
|
643
|
+
const measurement = (dev, result, mode) => {
|
|
644
|
+
const power = alias(dev, mode === 'pvInverter' ? ['r.pvPower', 'r.power'] : ['r.power'], false, ['number'], ['W']);
|
|
645
|
+
if (!power) {
|
|
646
|
+
result.code = 'ALIASES_PENDING';
|
|
647
|
+
result.missing.push('r.power');
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
const powerKeys = /^(?:pvPower|producer\d+Power|consumer\d+Power|gridPointPower)$/;
|
|
651
|
+
/** @param {string} [except] */
|
|
652
|
+
const assignedFlow = except => Object.entries(record(config.datapoints)).some(([key, id]) => key !== except && powerKeys.test(key) &&
|
|
653
|
+
typeof id === 'string' && readTargetOf(id) === readTargetOf(power));
|
|
654
|
+
/** @param {string} [except] */
|
|
655
|
+
const assignedDynamic = except => {
|
|
656
|
+
const points = record(config.dynamicGridConnection).points;
|
|
657
|
+
return Array.isArray(points) && points.some(point => {
|
|
658
|
+
const row = record(point);
|
|
659
|
+
const id = record(row.measurement).stateId;
|
|
660
|
+
return row.id !== except && typeof id === 'string' && readTargetOf(id) === readTargetOf(power);
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
if (mode === 'gridMeter' && dev.ems.scope === 'M1') {
|
|
664
|
+
if (assignedFlow() || assignedDynamic('M1')) {
|
|
665
|
+
result.status = 'conflict';
|
|
666
|
+
result.code = 'MEASUREMENT_ALREADY_ASSIGNED';
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
/** @type {Dict} */
|
|
670
|
+
const dynamic = config.dynamicGridConnection === undefined ? {
|
|
671
|
+
schemaVersion: 1, configVersion: 1, maxSkewMs: 1000, points: [
|
|
672
|
+
{ id: 'M0', source: 'general', importLimitW: null, exportLimitW: null, importReserveW: 0, exportReserveW: 0 },
|
|
673
|
+
{ id: 'M1', source: 'mapped', measurement: { stateId: '', unit: 'W', sign: 1, maxAgeMs: 5000 }, importLimitW: null,
|
|
674
|
+
exportLimitW: null, importReserveW: 0, exportReserveW: 0 },
|
|
675
|
+
], storages: [], pvAssignments: [],
|
|
676
|
+
} : copyConfig(config.dynamicGridConnection);
|
|
677
|
+
const points = rows(dynamic, 'points', 2);
|
|
678
|
+
const point = points.find(item => item.id === 'M1');
|
|
679
|
+
if (!point) {
|
|
680
|
+
result.code = 'MANUAL_TOPOLOGY_REQUIRED';
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const mapping = section(point, 'measurement');
|
|
684
|
+
if (!empty(mapping.stateId) && mapping.stateId !== power) {
|
|
685
|
+
result.status = 'conflict';
|
|
686
|
+
result.code = 'MANUAL_MAPPING_PRESERVED';
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
fill(mapping, 'stateId', power, result);
|
|
690
|
+
fill(mapping, 'unit', 'W', result);
|
|
691
|
+
fill(mapping, 'sign', 1, result);
|
|
692
|
+
fill(mapping, 'maxAgeMs', 5000, result);
|
|
693
|
+
config.dynamicGridConnection = dynamic;
|
|
694
|
+
remember(point, dev, mode, 'M1');
|
|
695
|
+
result.target = 'dynamicGridConnection.points.M1.measurement';
|
|
696
|
+
result.status = 'mapped';
|
|
697
|
+
result.code = 'MEASUREMENT_MAPPED';
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
let key = '';
|
|
701
|
+
let slot = dev.ems.flowSlot;
|
|
702
|
+
let kind = '';
|
|
703
|
+
if (mode === 'gridMeter') {
|
|
704
|
+
if (dev.ems.scope !== 'M0') {
|
|
705
|
+
result.code = 'NEEDS_SELECTION';
|
|
706
|
+
result.missing.push('scope');
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
key = 'gridPointPower';
|
|
710
|
+
}
|
|
711
|
+
else if (mode === 'generationMeter' || mode === 'pvInverter') {
|
|
712
|
+
if (typeof slot !== 'number' || slot < 0 || slot > 5) {
|
|
713
|
+
result.code = 'NEEDS_SELECTION';
|
|
714
|
+
result.missing.push('flowSlot');
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
key = slot === 0 ? 'pvPower' : `producer${slot}Power`;
|
|
718
|
+
kind = 'producers';
|
|
719
|
+
}
|
|
720
|
+
else if (mode === 'consumptionMeter') {
|
|
721
|
+
if (typeof slot !== 'number' || slot < 1 || slot > 10) {
|
|
722
|
+
result.code = 'NEEDS_SELECTION';
|
|
723
|
+
result.missing.push('flowSlot');
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
key = `consumer${slot}Power`;
|
|
727
|
+
kind = 'consumers';
|
|
728
|
+
}
|
|
729
|
+
if (!key) {
|
|
730
|
+
result.code = 'NEEDS_SELECTION';
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
const dp = section(config, 'datapoints');
|
|
734
|
+
if (!empty(dp[key]) && dp[key] !== power) {
|
|
735
|
+
result.status = 'conflict';
|
|
736
|
+
result.code = 'MANUAL_MAPPING_PRESERVED';
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
const duplicated = assignedFlow(key) || assignedDynamic();
|
|
740
|
+
if (duplicated) {
|
|
741
|
+
result.status = 'conflict';
|
|
742
|
+
result.code = 'MEASUREMENT_ALREADY_ASSIGNED';
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
fill(dp, key, power, result);
|
|
746
|
+
// Unit flags are adjusted only together with a new assignment; a manual
|
|
747
|
+
// setting on an existing target is not silently changed.
|
|
748
|
+
if (result.mappedFields.includes(key))
|
|
749
|
+
section(section(config, 'settings'), 'flowPowerDpIsW')[key] = true;
|
|
750
|
+
const fs = section(section(config, 'vis'), 'flowSlots');
|
|
751
|
+
let owner = section(fs, 'core');
|
|
752
|
+
if (kind && typeof slot === 'number' && slot > 0) {
|
|
753
|
+
const list = rows(fs, kind, kind === 'producers' ? 5 : 10);
|
|
754
|
+
while (list.length < slot)
|
|
755
|
+
list.push({});
|
|
756
|
+
owner = list[slot - 1];
|
|
757
|
+
fill(owner, 'name', dev.name, result);
|
|
758
|
+
}
|
|
759
|
+
else if (key === 'pvPower')
|
|
760
|
+
fill(owner, 'pvName', dev.name, result);
|
|
761
|
+
if (mode === 'gridMeter') {
|
|
762
|
+
const connected = alias(dev, ['comm.connected', 'r.online'], false, ['boolean']);
|
|
763
|
+
if (explicitApply(dev) && connected && [`${dev.baseId}.aliases.r.online`, `${dev.baseId}.aliases.v1.r.online`].includes(text(dp.gridPointConnected)) && dp.gridPointConnected !== connected) {
|
|
764
|
+
dp.gridPointConnected = connected;
|
|
765
|
+
result.corrections.push('NVP_TRANSPORT_STATUS_SELECTED');
|
|
766
|
+
}
|
|
767
|
+
fill(dp, 'gridPointConnected', connected, result);
|
|
768
|
+
fill(dp, 'gridPointWatchdog', alias(dev, ['r.heartbeat', 'r.lastSeenMs']), result);
|
|
769
|
+
}
|
|
770
|
+
remember(owner, dev, mode, key);
|
|
771
|
+
result.target = `datapoints.${key}`;
|
|
772
|
+
result.status = 'mapped';
|
|
773
|
+
result.code = 'MEASUREMENT_MAPPED';
|
|
774
|
+
};
|
|
775
|
+
// Existing auto-created control rows survive missing/deactivated devices, but
|
|
776
|
+
// are held inactive. Re-adding a device never grants activation by itself.
|
|
777
|
+
const activeBases = new Set(devices.filter(dev => dev.enabled && dev.ems.mode !== 'monitor').map(dev => dev.baseId));
|
|
778
|
+
const disableSingleApp = () => {
|
|
779
|
+
const root = section(config, 'emsApps');
|
|
780
|
+
if (root.schemaVersion === undefined)
|
|
781
|
+
root.schemaVersion = 1;
|
|
782
|
+
section(section(root, 'apps'), 'storage').enabled = false;
|
|
783
|
+
};
|
|
784
|
+
const controlRows = [
|
|
785
|
+
...(Array.isArray(record(config.settingsConfig).evcsList) ? /** @type {Json[]} */ (record(config.settingsConfig).evcsList) : []),
|
|
786
|
+
...(Array.isArray(record(config.storageFarm).storages) ? /** @type {Json[]} */ (record(config.storageFarm).storages) : []),
|
|
787
|
+
record(config.storage),
|
|
788
|
+
];
|
|
789
|
+
for (const item of controlRows) {
|
|
790
|
+
const row = record(item);
|
|
791
|
+
const owner = record(row._eosDevice);
|
|
792
|
+
if (owner.v === 1 && typeof owner.baseId === 'string' && !activeBases.has(owner.baseId)) {
|
|
793
|
+
row.enabled = false;
|
|
794
|
+
if (row === config.storage)
|
|
795
|
+
disableSingleApp();
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
for (const dev of devices) {
|
|
799
|
+
const result = status(dev);
|
|
800
|
+
statuses.push(result);
|
|
801
|
+
const mode = text(dev.ems.mode) || 'auto';
|
|
802
|
+
const previousBinding = binding(dev);
|
|
803
|
+
const profileChanged = typeof previousBinding.deviceTemplateId === 'string' &&
|
|
804
|
+
(previousBinding.deviceTemplateId !== dev.templateId || typeof previousBinding.deviceProtocol === 'string' && previousBinding.deviceProtocol !== dev.protocol ||
|
|
805
|
+
!dev.discoveryCode && previousBinding.deviceClass !== dev.deviceClass);
|
|
806
|
+
if (profileChanged) {
|
|
807
|
+
// Reusing a device ID is not permission to transfer a commissioned
|
|
808
|
+
// controller to another hardware profile. Preserve the assignment
|
|
809
|
+
// for review, but never restore an active old-profile row on a
|
|
810
|
+
// failed attempt to commission its replacement.
|
|
811
|
+
let incompatibleVendor = false;
|
|
812
|
+
for (const item of controlRows) {
|
|
813
|
+
const row = record(item);
|
|
814
|
+
const owner = record(row._eosDevice);
|
|
815
|
+
if (owner.v === 1 && owner.baseId === dev.baseId) {
|
|
816
|
+
row.enabled = false;
|
|
817
|
+
if (row === config.storage)
|
|
818
|
+
disableSingleApp();
|
|
819
|
+
if (row.vendorProfile === 'fenecon-openems' && dev.templateId !== 'ess.fenecon.FeneconHomeEssImpl')
|
|
820
|
+
incompatibleVendor = true;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
if (!explicitApply(dev) || incompatibleVendor) {
|
|
824
|
+
result.code = 'ACTIVATION_PROFILE_CHANGED';
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
if (!dev.enabled) {
|
|
829
|
+
result.status = 'disabled';
|
|
830
|
+
result.code = 'DEVICE_DISABLED';
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
if (mode === 'manual' || mode === 'monitor') {
|
|
834
|
+
result.status = 'manual';
|
|
835
|
+
result.code = mode === 'manual' ? 'MANUAL_MAPPING' : 'MONITOR_ONLY';
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
if (dev.discoveryCode || !dev.aliases.size) {
|
|
839
|
+
result.code = dev.discoveryCode || 'ALIASES_PENDING';
|
|
840
|
+
continue;
|
|
841
|
+
}
|
|
842
|
+
if (result.activationRequestId && binding(dev).activationRequestId === result.activationRequestId &&
|
|
843
|
+
binding(dev).activationFingerprint !== requestFingerprint(dev)) {
|
|
844
|
+
result.status = 'conflict';
|
|
845
|
+
result.code = 'ACTIVATION_REQUEST_CHANGED';
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
const checkpoint = copyConfig(config);
|
|
849
|
+
try {
|
|
850
|
+
if (dev.deviceClass === 'evCharger' && mode === 'auto') {
|
|
851
|
+
ev(dev, result);
|
|
852
|
+
continue;
|
|
853
|
+
}
|
|
854
|
+
if (STORAGE_CLASSES.has(dev.deviceClass) && ['singleStorage', 'storageFarm'].includes(mode)) {
|
|
855
|
+
storage(dev, result, mode === 'storageFarm');
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
if (dev.deviceClass === 'meter' && ['gridMeter', 'generationMeter', 'consumptionMeter'].includes(mode)) {
|
|
859
|
+
measurement(dev, result, mode);
|
|
860
|
+
continue;
|
|
861
|
+
}
|
|
862
|
+
if (dev.deviceClass === 'pvInverter' && mode === 'pvInverter') {
|
|
863
|
+
measurement(dev, result, mode);
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
if (dev.deviceClass === 'heat' && mode === 'consumptionMeter') {
|
|
867
|
+
measurement(dev, result, mode);
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
if (dev.deviceClass === 'solarCharger' || dev.deviceClass === 'generic') {
|
|
871
|
+
result.status = 'manual';
|
|
872
|
+
result.code = 'MANUAL_MAPPING';
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
result.code = mode === 'auto' ? 'NEEDS_SELECTION' : 'DEVICE_ROLE_MISMATCH';
|
|
876
|
+
}
|
|
877
|
+
finally {
|
|
878
|
+
// Conflicts and unavailable metadata must not leave empty sections,
|
|
879
|
+
// partially added rows or binding records in the committed config.
|
|
880
|
+
if (result.status !== 'mapped') {
|
|
881
|
+
for (const key of Object.keys(config))
|
|
882
|
+
delete config[key];
|
|
883
|
+
Object.assign(config, checkpoint);
|
|
884
|
+
result.mappedFields = [];
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
// Commission only explicit, unconsumed installer requests. These records are
|
|
889
|
+
// persisted with the exact same versioned patch as the row/app changes, so a
|
|
890
|
+
// restart or a later background inventory refresh cannot replay activation.
|
|
891
|
+
const grantedApps = new Set(Array.isArray(input.allowedApps) ? input.allowedApps : []);
|
|
892
|
+
const references = new Map(Object.entries(input.referenceMeta || {}));
|
|
893
|
+
for (const dev of devices)
|
|
894
|
+
for (const meta of dev.aliases.values())
|
|
895
|
+
references.set(meta.id, meta);
|
|
896
|
+
/** @param {unknown} value @returns {number|null} */
|
|
897
|
+
const number = value => typeof value === 'number' && Number.isFinite(value) ? value
|
|
898
|
+
: typeof value === 'string' && /^[+-]?\d+(?:\.\d+)?$/.test(value.trim()) ? Number(value) : null;
|
|
899
|
+
/** @param {unknown} id @param {boolean} write @param {string} type @param {string[]} units */
|
|
900
|
+
const validReference = (id, write, type, units) => {
|
|
901
|
+
if (typeof id !== 'string' || !id || numericReference(id))
|
|
902
|
+
return false;
|
|
903
|
+
const meta = references.get(id);
|
|
904
|
+
return !!meta && meta.type === type && (write ? meta.write === true : meta.read === true) &&
|
|
905
|
+
(!units.length || units.includes(text(meta.unit)));
|
|
906
|
+
};
|
|
907
|
+
/** @param {Device} dev @returns {Dict|undefined} */
|
|
908
|
+
const managedRow = dev => {
|
|
909
|
+
const target = text(binding(dev).target);
|
|
910
|
+
if (target === 'storage')
|
|
911
|
+
return isRecord(config.storage) ? config.storage : undefined;
|
|
912
|
+
const list = target === 'storageFarm' ? record(config.storageFarm).storages : target === 'evcs' ? record(config.settingsConfig).evcsList : undefined;
|
|
913
|
+
return Array.isArray(list) ? list.filter(isRecord).find(row => record(row._eosDevice).baseId === dev.baseId) : undefined;
|
|
914
|
+
};
|
|
915
|
+
for (let index = 0; index < devices.length; index++) {
|
|
916
|
+
const dev = devices[index];
|
|
917
|
+
const result = statuses[index];
|
|
918
|
+
const activation = record(dev.ems.activation);
|
|
919
|
+
const requestId = text(activation.requestId);
|
|
920
|
+
if (!requestId || !dev.enabled || result.status === 'conflict' || result.code === 'ACTIVATION_PROFILE_CHANGED')
|
|
921
|
+
continue;
|
|
922
|
+
const mode = text(dev.ems.mode) || 'auto';
|
|
923
|
+
const appId = dev.deviceClass === 'evCharger' && mode === 'auto' ? 'charging'
|
|
924
|
+
: mode === 'singleStorage' ? 'storage' : mode === 'storageFarm' ? 'storagefarm' : '';
|
|
925
|
+
const row = managedRow(dev);
|
|
926
|
+
if (binding(dev).activationRequestId === requestId) {
|
|
927
|
+
// A consumed request records a previous successful save, not proof
|
|
928
|
+
// that today's device metadata is available and still usable.
|
|
929
|
+
if (result.status !== 'mapped')
|
|
930
|
+
continue;
|
|
931
|
+
result.activationApplied = true;
|
|
932
|
+
const app = record(record(record(config.emsApps).apps)[appId]);
|
|
933
|
+
if (activation.requested === false)
|
|
934
|
+
result.code = 'ACTIVATION_DISABLED';
|
|
935
|
+
else if (appId && (row?.enabled === false || app.enabled !== true || app.installed !== true))
|
|
936
|
+
result.code = 'APP_DISABLED';
|
|
937
|
+
else if (!result.missing.length)
|
|
938
|
+
result.code = 'ACTIVATION_APPLIED';
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
if (result.status !== 'mapped')
|
|
942
|
+
continue;
|
|
943
|
+
/** @type {Dict} */
|
|
944
|
+
const proposedBounds = {};
|
|
945
|
+
const limits = record(activation.limits);
|
|
946
|
+
/** Keep existing valid customer limits authoritative; populate missing finite bounds. @param {string} key @param {number} max @param {boolean} [zeroAllowed] */
|
|
947
|
+
const requireBound = (key, max, zeroAllowed = false) => {
|
|
948
|
+
const current = number(row?.[key]);
|
|
949
|
+
const supplied = number(limits[key]);
|
|
950
|
+
const value = current !== null && (zeroAllowed ? current >= 0 : current > 0) && current <= max ? current : supplied;
|
|
951
|
+
if (value === null || !Number.isFinite(value) || (zeroAllowed ? value < 0 : value <= 0) || value > max) {
|
|
952
|
+
result.missing.push(`limit:${key}`);
|
|
953
|
+
return null;
|
|
954
|
+
}
|
|
955
|
+
if (current !== value)
|
|
956
|
+
proposedBounds[key] = value;
|
|
957
|
+
return value;
|
|
958
|
+
};
|
|
959
|
+
/** @param {string} key @param {boolean} write @param {string} type @param {string[]} units */
|
|
960
|
+
const requireReference = (key, write, type, units) => {
|
|
961
|
+
const target = mode === 'singleStorage' ? record(row?.datapoints) : record(row);
|
|
962
|
+
if (!validReference(target[key], write, type, units))
|
|
963
|
+
result.missing.push(`reference:${key}`);
|
|
964
|
+
};
|
|
965
|
+
if (activation.requested === true && appId) {
|
|
966
|
+
if (!row)
|
|
967
|
+
result.missing.push('deviceRow');
|
|
968
|
+
if (!grantedApps.has(appId))
|
|
969
|
+
result.missing.push(`license:${appId}`);
|
|
970
|
+
const gridId = record(config.datapoints).gridPointPower;
|
|
971
|
+
const gridMeta = typeof gridId === 'string' ? references.get(gridId) : undefined;
|
|
972
|
+
const perDpW = record(record(config.settings).flowPowerDpIsW).gridPointPower;
|
|
973
|
+
const gridUnit = text(gridMeta?.unit);
|
|
974
|
+
if (!validReference(gridId, false, 'number', ['W', 'kW']) || gridUnit === 'W' && perDpW === false || gridUnit === 'kW' && perDpW !== false) {
|
|
975
|
+
result.missing.push('gridPointPower');
|
|
976
|
+
}
|
|
977
|
+
if (appId === 'charging') {
|
|
978
|
+
requireReference('powerId', false, 'number', ['W']);
|
|
979
|
+
const chargerType = text(row?.chargerType) || text(limits.chargerType);
|
|
980
|
+
if (!['ac', 'dc'].includes(chargerType))
|
|
981
|
+
result.missing.push('limit:chargerType');
|
|
982
|
+
else if (empty(row?.chargerType))
|
|
983
|
+
proposedBounds.chargerType = chargerType;
|
|
984
|
+
if (chargerType === 'ac') {
|
|
985
|
+
const phases = number(row?.phases) ?? number(limits.phases);
|
|
986
|
+
if (phases !== 1 && phases !== 3)
|
|
987
|
+
result.missing.push('limit:phases');
|
|
988
|
+
else if (number(row?.phases) !== phases)
|
|
989
|
+
proposedBounds.phases = phases;
|
|
990
|
+
const min = requireBound('minCurrentA', 1000);
|
|
991
|
+
const max = requireBound('maxCurrentA', 1000);
|
|
992
|
+
if (min !== null && max !== null && min > max)
|
|
993
|
+
result.missing.push('limit:minCurrentA|maxCurrentA');
|
|
994
|
+
if (empty(row?.setCurrentAId))
|
|
995
|
+
requireReference('setPowerWId', true, 'number', ['W']);
|
|
996
|
+
else
|
|
997
|
+
requireReference('setCurrentAId', true, 'number', ['A']);
|
|
998
|
+
}
|
|
999
|
+
else if (chargerType === 'dc') {
|
|
1000
|
+
const min = requireBound('minPowerW', 1000000000);
|
|
1001
|
+
const max = requireBound('maxPowerW', 1000000000);
|
|
1002
|
+
if (min !== null && max !== null && min > max)
|
|
1003
|
+
result.missing.push('limit:minPowerW|maxPowerW');
|
|
1004
|
+
requireReference('setPowerWId', true, 'number', ['W']);
|
|
1005
|
+
}
|
|
1006
|
+
if (!empty(row?.enableWriteId))
|
|
1007
|
+
requireReference('enableWriteId', true, 'boolean', []);
|
|
1008
|
+
}
|
|
1009
|
+
else {
|
|
1010
|
+
const farm = appId === 'storagefarm';
|
|
1011
|
+
requireReference(farm ? 'socId' : 'socObjectId', false, 'number', ['%']);
|
|
1012
|
+
requireReference(farm ? 'signedPowerId' : 'batteryPowerObjectId', false, 'number', ['W']);
|
|
1013
|
+
const destination = farm ? record(row) : record(row?.datapoints);
|
|
1014
|
+
const native = row?.vendorProfile === 'fenecon-openems' && row?.feneconControlMode === 'fems-grid';
|
|
1015
|
+
if (native)
|
|
1016
|
+
requireReference(farm ? 'feneconGridSetpointId' : 'feneconGridSetpointObjectId', true, 'number', ['W']);
|
|
1017
|
+
else if (!empty(destination[farm ? 'setSignedPowerId' : 'targetPowerObjectId']))
|
|
1018
|
+
requireReference(farm ? 'setSignedPowerId' : 'targetPowerObjectId', true, 'number', ['W']);
|
|
1019
|
+
else {
|
|
1020
|
+
requireReference(farm ? 'setChargePowerId' : 'targetChargePowerObjectId', true, 'number', ['W']);
|
|
1021
|
+
requireReference(farm ? 'setDischargePowerId' : 'targetDischargePowerObjectId', true, 'number', ['W']);
|
|
1022
|
+
}
|
|
1023
|
+
const charge = requireBound('maxChargeW', 1000000000, farm);
|
|
1024
|
+
const discharge = requireBound('maxDischargeW', 1000000000, farm);
|
|
1025
|
+
if (charge === 0 && discharge === 0)
|
|
1026
|
+
result.missing.push('limit:storagePower');
|
|
1027
|
+
const coupling = text(row?.coupling) || text(limits.coupling);
|
|
1028
|
+
if (!['ac', 'dc'].includes(coupling))
|
|
1029
|
+
result.missing.push('limit:coupling');
|
|
1030
|
+
else if (empty(row?.coupling))
|
|
1031
|
+
proposedBounds.coupling = coupling;
|
|
1032
|
+
if (!empty(limits.capacityKWh) && empty(row?.capacityKWh))
|
|
1033
|
+
requireBound('capacityKWh', 10000000);
|
|
1034
|
+
const otherApp = record(record(record(config.emsApps).apps)[farm ? 'storage' : 'storagefarm']);
|
|
1035
|
+
const otherRows = farm ? [record(config.storage)] : (Array.isArray(record(config.storageFarm).storages) ? /** @type {Json[]} */ (record(config.storageFarm).storages) : []);
|
|
1036
|
+
if (otherApp.enabled === true && otherRows.some(item => record(item).enabled !== false && mappedIds(item).length))
|
|
1037
|
+
result.missing.push('otherStorageController');
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
if (activation.requested === true && result.missing.length) {
|
|
1041
|
+
result.missing = [...new Set(result.missing)];
|
|
1042
|
+
result.status = 'pending';
|
|
1043
|
+
result.code = 'ACTIVATION_PENDING';
|
|
1044
|
+
const original = activeOriginals.get(dev.baseId);
|
|
1045
|
+
if (row && original) {
|
|
1046
|
+
for (const key of Object.keys(row))
|
|
1047
|
+
delete row[key];
|
|
1048
|
+
Object.assign(row, original);
|
|
1049
|
+
result.corrections = [];
|
|
1050
|
+
result.mappedFields = [];
|
|
1051
|
+
}
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
if (row && appId) {
|
|
1055
|
+
Object.assign(row, proposedBounds);
|
|
1056
|
+
row.enabled = activation.requested === true;
|
|
1057
|
+
if (appId === 'storage' && activation.requested === false)
|
|
1058
|
+
disableSingleApp();
|
|
1059
|
+
}
|
|
1060
|
+
if (activation.requested === true && appId) {
|
|
1061
|
+
const registry = section(config, 'emsApps');
|
|
1062
|
+
fill(registry, 'schemaVersion', 1, result);
|
|
1063
|
+
const app = section(section(registry, 'apps'), appId);
|
|
1064
|
+
app.installed = true;
|
|
1065
|
+
app.enabled = true;
|
|
1066
|
+
if (appId === 'charging') {
|
|
1067
|
+
const dp = record(config.datapoints);
|
|
1068
|
+
const oldEv = text(dp.consumptionEvcs);
|
|
1069
|
+
if (oldEv && references.get(oldEv)?.type === 'boolean') {
|
|
1070
|
+
dp.consumptionEvcs = '';
|
|
1071
|
+
result.corrections.push('EV_FLOW_BOOLEAN_OVERRIDE_REMOVED');
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
const registry = section(config, 'eosDeviceEms');
|
|
1076
|
+
registry.v = 1;
|
|
1077
|
+
const bindings = section(registry, 'bindings');
|
|
1078
|
+
bindings[dev.baseId] = { ...record(bindings[dev.baseId]), activationRequestId: requestId,
|
|
1079
|
+
activationFingerprint: requestFingerprint(dev), activationRequested: activation.requested === true,
|
|
1080
|
+
deviceTemplateId: dev.templateId, deviceProtocol: dev.protocol, deviceClass: dev.deviceClass };
|
|
1081
|
+
result.activationApplied = true;
|
|
1082
|
+
result.code = activation.requested === true ? 'ACTIVATION_APPLIED' : 'ACTIVATION_DISABLED';
|
|
1083
|
+
}
|
|
1084
|
+
// Switching on a shared app also switches on every enabled controller row.
|
|
1085
|
+
// Do not implicitly start a dormant manual row or a row whose commissioning
|
|
1086
|
+
// is still incomplete just because another device was added successfully.
|
|
1087
|
+
for (const appId of ['charging', 'storagefarm']) {
|
|
1088
|
+
const oldApp = record(record(record(before.emsApps).apps)[appId]);
|
|
1089
|
+
const app = record(record(record(config.emsApps).apps)[appId]);
|
|
1090
|
+
if (oldApp.installed === true && oldApp.enabled === true || app.enabled !== true)
|
|
1091
|
+
continue;
|
|
1092
|
+
const list = appId === 'charging' ? record(config.settingsConfig).evcsList : record(config.storageFarm).storages;
|
|
1093
|
+
if (!Array.isArray(list))
|
|
1094
|
+
continue;
|
|
1095
|
+
const controllingFields = appId === 'charging' ? ['setCurrentAId', 'setPowerWId', 'enableWriteId']
|
|
1096
|
+
: ['setSignedPowerId', 'setChargePowerId', 'setDischargePowerId', 'feneconGridSetpointId'];
|
|
1097
|
+
const relevant = devices.filter(dev => appId === 'charging' ? dev.deviceClass === 'evCharger' && (dev.ems.mode || 'auto') === 'auto' : dev.ems.mode === 'storageFarm');
|
|
1098
|
+
const approved = new Set(relevant.filter(dev => {
|
|
1099
|
+
const result = statuses.find(item => item.baseId === dev.baseId);
|
|
1100
|
+
return record(dev.ems.activation).requested === true && result?.activationApplied === true && result.code === 'ACTIVATION_APPLIED' &&
|
|
1101
|
+
text(record(record(record(before.eosDeviceEms).bindings)[dev.baseId]).activationRequestId) !== result.activationRequestId;
|
|
1102
|
+
}).map(dev => dev.baseId));
|
|
1103
|
+
const hasDormantController = list.filter(isRecord).some(row => row.enabled !== false && controllingFields.some(key => !empty(row[key])) &&
|
|
1104
|
+
!approved.has(text(record(row._eosDevice).baseId)));
|
|
1105
|
+
if (!hasDormantController)
|
|
1106
|
+
continue;
|
|
1107
|
+
app.enabled = false;
|
|
1108
|
+
for (const dev of relevant) {
|
|
1109
|
+
if (!approved.has(dev.baseId))
|
|
1110
|
+
continue;
|
|
1111
|
+
const result = /** @type {Status} */ (statuses.find(item => item.baseId === dev.baseId));
|
|
1112
|
+
const row = managedRow(dev);
|
|
1113
|
+
const original = activeOriginals.get(dev.baseId);
|
|
1114
|
+
if (row) {
|
|
1115
|
+
if (original) {
|
|
1116
|
+
for (const key of Object.keys(row))
|
|
1117
|
+
delete row[key];
|
|
1118
|
+
Object.assign(row, original);
|
|
1119
|
+
result.corrections = [];
|
|
1120
|
+
result.mappedFields = [];
|
|
1121
|
+
}
|
|
1122
|
+
else
|
|
1123
|
+
row.enabled = false;
|
|
1124
|
+
}
|
|
1125
|
+
const previous = record(record(record(before.eosDeviceEms).bindings)[dev.baseId]);
|
|
1126
|
+
const current = binding(dev);
|
|
1127
|
+
for (const key of ['activationRequestId', 'activationFingerprint', 'activationRequested', 'deviceTemplateId', 'deviceProtocol', 'deviceClass']) {
|
|
1128
|
+
if (previous[key] === undefined)
|
|
1129
|
+
delete current[key];
|
|
1130
|
+
else
|
|
1131
|
+
current[key] = previous[key];
|
|
1132
|
+
}
|
|
1133
|
+
result.activationApplied = false;
|
|
1134
|
+
result.status = 'pending';
|
|
1135
|
+
result.code = 'ACTIVATION_PENDING';
|
|
1136
|
+
result.missing.push('otherUncommissionedController');
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
/** @type {Dict} */
|
|
1140
|
+
const patch = {};
|
|
1141
|
+
for (const [key, value] of Object.entries(config))
|
|
1142
|
+
if (JSON.stringify(value) !== JSON.stringify(before[key]))
|
|
1143
|
+
patch[key] = value;
|
|
1144
|
+
return { config, patch, changed: Object.keys(patch).length > 0, statuses };
|
|
1145
|
+
}
|
|
1146
|
+
module.exports = { planDeviceEms, getDeviceEmsReferences };
|
|
1147
|
+
//# sourceMappingURL=eosDeviceEmsPlan.js.map
|