@enyo-energy/sunspec-sdk 0.0.100 → 0.0.102
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/dist/cjs/sunspec-devices.cjs +486 -18
- package/dist/cjs/sunspec-devices.d.cts +144 -1
- package/dist/cjs/sunspec-interfaces.d.cts +81 -0
- package/dist/cjs/sunspec-modbus-client.cjs +172 -49
- package/dist/cjs/sunspec-modbus-client.d.cts +43 -1
- package/dist/cjs/version.cjs +1 -1
- package/dist/cjs/version.d.cts +1 -1
- package/dist/sunspec-devices.d.ts +144 -1
- package/dist/sunspec-devices.js +484 -17
- package/dist/sunspec-interfaces.d.ts +81 -0
- package/dist/sunspec-modbus-client.d.ts +43 -1
- package/dist/sunspec-modbus-client.js +172 -49
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/cjs/version.cjs
CHANGED
|
@@ -9,7 +9,7 @@ exports.getSdkVersion = getSdkVersion;
|
|
|
9
9
|
/**
|
|
10
10
|
* Current version of the enyo Energy App SDK.
|
|
11
11
|
*/
|
|
12
|
-
exports.SDK_VERSION = '0.0.
|
|
12
|
+
exports.SDK_VERSION = '0.0.102';
|
|
13
13
|
/**
|
|
14
14
|
* Gets the current SDK version.
|
|
15
15
|
* @returns The semantic version string of the SDK
|
package/dist/cjs/version.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IRetryConfig, type SunspecBatteryBaseData, SunspecBatteryCapability, type SunspecBatteryControls, type SunspecBatteryData, type SunspecBatteryFeatureMode, type SunspecInverterData, SunspecInverterCapability, SunspecPvPowerSource, SunspecPvPowerOrigin, type SunspecInverterReading, type SunspecBatteryReading, SunspecMeterCapability, type SunspecMPPTData, SunspecStorageMode } from "./sunspec-interfaces.js";
|
|
1
|
+
import { type IRetryConfig, type SunspecBatteryBaseData, SunspecBatteryCapability, type SunspecBatteryControls, type SunspecBatteryData, type SunspecBatteryFeatureMode, type SunspecInverterData, SunspecInverterCapability, SunspecPvPowerSource, SunspecPvPowerOrigin, type SunspecInverterReading, type SunspecBatteryReading, SunspecMeterCapability, type SunspecMPPTData, SunspecStorageMode, type SunspecCustomDeviceConfig } from "./sunspec-interfaces.js";
|
|
2
2
|
import { ApplianceManager, EnergyApp } from "@enyo-energy/energy-app-sdk";
|
|
3
3
|
import { type EnyoAppliance, type EnyoApplianceErrorCode, EnyoApplianceName } from "@enyo-energy/energy-app-sdk/dist/types/enyo-appliance.js";
|
|
4
4
|
import { EnyoNetworkDevice } from "@enyo-energy/energy-app-sdk/dist/types/enyo-network-device.js";
|
|
@@ -68,12 +68,55 @@ export declare abstract class BaseSunspecDevice {
|
|
|
68
68
|
* Ensure the Sunspec client is connected and models are discovered
|
|
69
69
|
*/
|
|
70
70
|
protected ensureConnected(): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Populate the per-unit model directory after the socket opens. Default: run SunSpec model
|
|
73
|
+
* discovery. Devices that read a hand-defined static register map instead of a discovered SunSpec
|
|
74
|
+
* directory (see {@link SunspecCustomDevice}) override this to a no-op.
|
|
75
|
+
*/
|
|
76
|
+
protected discoverAfterConnect(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Validate that a just-completed reconnect actually restored a usable device. Default: re-run
|
|
79
|
+
* SunSpec discovery and check it against {@link getRequiredModelIds} (a socket that opens but comes
|
|
80
|
+
* back with no usable models means the gateway accepted the connection before it was ready to
|
|
81
|
+
* answer the scan). Returns false to treat the reconnect as failed so the backoff schedule keeps
|
|
82
|
+
* running. Discovery-less devices override this to just confirm the socket is open.
|
|
83
|
+
*/
|
|
84
|
+
protected revalidateAfterReconnect(): Promise<boolean>;
|
|
71
85
|
/**
|
|
72
86
|
* Attempt a reconnection if the tiered retry schedule allows it.
|
|
73
87
|
* Called from readData() when the device is disconnected.
|
|
74
88
|
* Returns true if reconnection succeeded.
|
|
75
89
|
*/
|
|
76
90
|
protected tryReconnect(): Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* Model IDs this device needs to produce a reading; presence of ANY one means a
|
|
93
|
+
* discovery is usable (one-of semantics — devices expose mutually-exclusive
|
|
94
|
+
* encoding/phase variants, e.g. int+SF vs float, single- vs three-phase). Empty
|
|
95
|
+
* (the base default) means no specific requirement, so any model present
|
|
96
|
+
* suffices. Concrete devices override with their acceptable set — this is the
|
|
97
|
+
* single per-device source of truth reused by both the reconnect discovery gate
|
|
98
|
+
* ({@link isDiscoveryUsable}) and the connect-time presence gate
|
|
99
|
+
* ({@link hasRequiredModels}).
|
|
100
|
+
*/
|
|
101
|
+
protected getRequiredModelIds(): readonly number[];
|
|
102
|
+
/**
|
|
103
|
+
* True if the current per-unit discovered-model map satisfies this device's
|
|
104
|
+
* requirement. The connect-time twin of {@link isDiscoveryUsable}: it inspects
|
|
105
|
+
* the already-populated map via findModel() rather than a freshly-returned one.
|
|
106
|
+
* Only meaningful for devices that declare a non-empty required set.
|
|
107
|
+
*/
|
|
108
|
+
protected hasRequiredModels(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Decide whether a post-reconnect model discovery is usable. A reconnect that
|
|
111
|
+
* establishes the TCP socket but comes back empty (or with only a Common block)
|
|
112
|
+
* means the device accepted the connection before it was ready to answer the
|
|
113
|
+
* SunSpec scan; the discovered-model map is now missing this device's data
|
|
114
|
+
* model, so trusting the reconnect would leave every read finding no model.
|
|
115
|
+
* Validated generically against {@link getRequiredModelIds}: with a declared
|
|
116
|
+
* set, at least one of those ids must be present; with none declared, fall back
|
|
117
|
+
* to "any model present".
|
|
118
|
+
*/
|
|
119
|
+
protected isDiscoveryUsable(models: Map<number, SunspecModel>): boolean;
|
|
77
120
|
/**
|
|
78
121
|
* Hook for subclasses to react to a failed reconnect attempt. Called once
|
|
79
122
|
* per failed attempt with the running consecutive-failure count.
|
|
@@ -142,6 +185,13 @@ export declare class SunspecInverter extends BaseSunspecDevice {
|
|
|
142
185
|
private readonly pvPowerSource;
|
|
143
186
|
/** Emit a connection-lost faulted status after this many consecutive failed reconnect attempts. */
|
|
144
187
|
private static readonly CONNECTION_FAULT_THRESHOLD;
|
|
188
|
+
/**
|
|
189
|
+
* The inverter data models this device can read (int+SF 101/103 and IEEE-754
|
|
190
|
+
* float 111/112/113). A post-reconnect discovery that finds none of these has
|
|
191
|
+
* not really recovered the inverter, so {@link isDiscoveryUsable} rejects it —
|
|
192
|
+
* see the override below.
|
|
193
|
+
*/
|
|
194
|
+
private static readonly INVERTER_MODEL_IDS;
|
|
145
195
|
/**
|
|
146
196
|
* Require this many consecutive operatingState=7 (FAULT) reads before
|
|
147
197
|
* reporting Faulted. Debounces transient single-poll FAULT reads (e.g. a
|
|
@@ -218,6 +268,14 @@ export declare class SunspecInverter extends BaseSunspecDevice {
|
|
|
218
268
|
private hasErrorSetChanged;
|
|
219
269
|
private buildStatusMessage;
|
|
220
270
|
private detectAndEmitStatusTransition;
|
|
271
|
+
/**
|
|
272
|
+
* A reconnect has only recovered the inverter if discovery finds one of its
|
|
273
|
+
* data models. An SE gateway can accept the new socket and answer a partial
|
|
274
|
+
* scan (e.g. only the Common block) before the inverter map is ready — the
|
|
275
|
+
* base size>0 rule would accept that, but every inverter read would then find
|
|
276
|
+
* no 101/103/111/112/113 model and report 0 W. Require an actual inverter model.
|
|
277
|
+
*/
|
|
278
|
+
protected getRequiredModelIds(): readonly number[];
|
|
221
279
|
protected onConnectionFailure(consecutiveFailures: number): Promise<void>;
|
|
222
280
|
protected onConnectionRestored(): Promise<void>;
|
|
223
281
|
/**
|
|
@@ -430,6 +488,13 @@ export declare function filterFeaturesByCalibrationResult(detected: EnyoBatteryF
|
|
|
430
488
|
export declare class SunspecBattery extends BaseSunspecDevice {
|
|
431
489
|
private readonly featureMode;
|
|
432
490
|
private readonly capabilities;
|
|
491
|
+
/**
|
|
492
|
+
* Battery data models this device can read: Battery (124, full decode) and
|
|
493
|
+
* BatteryBase (802, derived decode). BatteryControl (803) is intentionally
|
|
494
|
+
* excluded — it is a decode stub that yields no telemetry — so a rediscovery
|
|
495
|
+
* that returns only 803 is treated as unrecovered, matching the connect() gate.
|
|
496
|
+
*/
|
|
497
|
+
private static readonly BATTERY_MODEL_IDS;
|
|
433
498
|
private snapshotService?;
|
|
434
499
|
private calibrationDriver?;
|
|
435
500
|
private batteryCalibrator?;
|
|
@@ -478,6 +543,7 @@ export declare class SunspecBattery extends BaseSunspecDevice {
|
|
|
478
543
|
* `CalibrationTrigger`.
|
|
479
544
|
*/
|
|
480
545
|
getBatteryCalibrator(): BatteryCalibrator<SunspecBatteryControls> | undefined;
|
|
546
|
+
protected getRequiredModelIds(): readonly number[];
|
|
481
547
|
/**
|
|
482
548
|
* Connect to the battery and create/update the appliance
|
|
483
549
|
*/
|
|
@@ -646,6 +712,12 @@ export declare class SunspecBattery extends BaseSunspecDevice {
|
|
|
646
712
|
*/
|
|
647
713
|
export declare class SunspecMeter extends BaseSunspecDevice {
|
|
648
714
|
private readonly capabilities;
|
|
715
|
+
/**
|
|
716
|
+
* Meter data models this device can read, across int+SF (201/203/204) and
|
|
717
|
+
* IEEE-754 float (211/212/213/214) encodings and single/split/three-phase
|
|
718
|
+
* variants. Used when the meter is not bound to a specific instance.
|
|
719
|
+
*/
|
|
720
|
+
private static readonly METER_MODEL_IDS;
|
|
649
721
|
constructor(energyApp: EnergyApp, name: EnyoApplianceName[], networkDevice: EnyoNetworkDevice, sunspecClient: SunspecModbusClient, applianceManager: ApplianceManager, unitId?: number, port?: number, baseAddress?: number, capabilities?: SunspecMeterCapability[], retryConfig?: IRetryConfig, appliance?: EnyoAppliance, useTls?: boolean);
|
|
650
722
|
/**
|
|
651
723
|
* The specific meter model instance this meter reads, when its unit hosts more than one
|
|
@@ -659,6 +731,11 @@ export declare class SunspecMeter extends BaseSunspecDevice {
|
|
|
659
731
|
* {@link SunspecModbusClient.findModels}). Call before {@link connect}.
|
|
660
732
|
*/
|
|
661
733
|
bindMeterModel(model: SunspecModel): void;
|
|
734
|
+
/**
|
|
735
|
+
* A bound meter requires ITS own pinned model id to reappear after a
|
|
736
|
+
* rediscovery; an unbound meter accepts any meter model on its unit.
|
|
737
|
+
*/
|
|
738
|
+
protected getRequiredModelIds(): readonly number[];
|
|
662
739
|
/**
|
|
663
740
|
* Connect to the meter and create/update the appliance
|
|
664
741
|
*/
|
|
@@ -672,4 +749,70 @@ export declare class SunspecMeter extends BaseSunspecDevice {
|
|
|
672
749
|
*/
|
|
673
750
|
readData(clockId: string, resolution: EnyoDataBusMessageResolution): Promise<EnyoDataBusMessage[]>;
|
|
674
751
|
}
|
|
752
|
+
/**
|
|
753
|
+
* A generic, pre-configured Modbus device that plugs into the exact same resilient lifecycle as the
|
|
754
|
+
* SunSpec devices — the per-device {@link ConnectionRetryManager}, {@link tryReconnect} tiered backoff,
|
|
755
|
+
* {@link markOffline}/{@link reassertConnectedIfRecovered} shared-socket healing, and the client's
|
|
756
|
+
* per-transaction timeout/poison/staleness guards — but reads a **hand-defined static register map**
|
|
757
|
+
* instead of a discovered SunSpec model directory.
|
|
758
|
+
*
|
|
759
|
+
* It emulates a configurable {@link SunspecCustomDeviceConfig.role} (`meter` | `inverter` | `battery`):
|
|
760
|
+
* the role selects the appliance type created on connect and which EnyoDataBus values message
|
|
761
|
+
* {@link readData} publishes, and each {@link SunspecCustomRegister} maps onto one numeric field of
|
|
762
|
+
* that message. Supports FC03 holding registers (default), FC04 input registers, and writes.
|
|
763
|
+
*
|
|
764
|
+
* Discovery is fully bypassed: {@link connect} opens the socket only, and the reconnect path is
|
|
765
|
+
* validated by socket liveness rather than a SunSpec scan.
|
|
766
|
+
*/
|
|
767
|
+
export declare class SunspecCustomDevice extends BaseSunspecDevice {
|
|
768
|
+
private readonly config;
|
|
769
|
+
/** Read plan derived once from the static register map (see {@link planBlocks}). */
|
|
770
|
+
private plannedBlocks?;
|
|
771
|
+
constructor(energyApp: EnergyApp, name: EnyoApplianceName[], networkDevice: EnyoNetworkDevice, sunspecClient: SunspecModbusClient, applianceManager: ApplianceManager, config: SunspecCustomDeviceConfig, unitId?: number, port?: number, baseAddress?: number, retryConfig?: IRetryConfig, appliance?: EnyoAppliance, useTls?: boolean);
|
|
772
|
+
/**
|
|
773
|
+
* No SunSpec model directory to build — this device reads pre-defined static addresses. Overriding
|
|
774
|
+
* the base discovery hook to a no-op is what lets {@link ensureConnected}/{@link connect} open the
|
|
775
|
+
* socket without a SunS scan.
|
|
776
|
+
*/
|
|
777
|
+
protected discoverAfterConnect(): Promise<void>;
|
|
778
|
+
/**
|
|
779
|
+
* A reconnect is usable as soon as the socket is open again — there is no model map to revalidate.
|
|
780
|
+
* Without this override the base default would run SunSpec discovery, find nothing, and treat every
|
|
781
|
+
* reconnect as a permanent failure.
|
|
782
|
+
*/
|
|
783
|
+
protected revalidateAfterReconnect(): Promise<boolean>;
|
|
784
|
+
/**
|
|
785
|
+
* Connect the underlying socket (no discovery) and create/update the appliance for the configured
|
|
786
|
+
* role. Identity metadata comes from {@link SunspecCustomDeviceConfig.identity} since there is no
|
|
787
|
+
* SunSpec Common block to read it from.
|
|
788
|
+
*/
|
|
789
|
+
connect(): Promise<void>;
|
|
790
|
+
disconnect(): Promise<void>;
|
|
791
|
+
readData(clockId: string, resolution: EnyoDataBusMessageResolution): Promise<EnyoDataBusMessage[]>;
|
|
792
|
+
/**
|
|
793
|
+
* Write a value to a pre-configured writable register. Delegates to the client's resilient
|
|
794
|
+
* {@link SunspecModbusClient.writeRegisterValue}.
|
|
795
|
+
*/
|
|
796
|
+
writeCustomRegister(name: string, value: number | number[]): Promise<boolean>;
|
|
797
|
+
/**
|
|
798
|
+
* Read every configured register as a small number of block reads and extract each register from
|
|
799
|
+
* its block buffer by offset (mirroring the SunSpec model-block read). Applies the fixed decimal
|
|
800
|
+
* scaling and returns a field → value map. Non-numeric reads (e.g. a `string` dataType that can't
|
|
801
|
+
* populate a numeric databus field) are skipped with a warning.
|
|
802
|
+
*/
|
|
803
|
+
private readConfiguredRegisters;
|
|
804
|
+
/** Lazily compute and cache the block read plan; the register map is static per device. */
|
|
805
|
+
private getPlannedBlocks;
|
|
806
|
+
/**
|
|
807
|
+
* Group the configured registers (separately per function code) sorted by address, coalescing them
|
|
808
|
+
* — across gaps — into blocks no wider than {@link SunspecCustomDeviceConfig.blockSize}. A new block
|
|
809
|
+
* starts whenever adding the next register would exceed that span. Each block records its members'
|
|
810
|
+
* offsets so a single read can be sliced into all of them.
|
|
811
|
+
*/
|
|
812
|
+
private planBlocks;
|
|
813
|
+
private buildRoleMessage;
|
|
814
|
+
private buildMeterMessage;
|
|
815
|
+
private buildInverterMessage;
|
|
816
|
+
private buildBatteryMessage;
|
|
817
|
+
}
|
|
675
818
|
export {};
|