@enyo-energy/sunspec-sdk 0.0.96 → 0.0.98
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 +253 -47
- package/dist/cjs/sunspec-devices.d.cts +106 -10
- package/dist/cjs/sunspec-interfaces.cjs +23 -1
- package/dist/cjs/sunspec-interfaces.d.cts +93 -0
- package/dist/cjs/version.cjs +1 -1
- package/dist/cjs/version.d.cts +1 -1
- package/dist/sunspec-devices.d.ts +106 -10
- package/dist/sunspec-devices.js +253 -48
- package/dist/sunspec-interfaces.d.ts +93 -0
- package/dist/sunspec-interfaces.js +22 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* SunSpec block interfaces with block numbers
|
|
3
3
|
*/
|
|
4
4
|
import { EnyoBatteryFeature } from "@enyo-energy/energy-app-sdk/dist/types/enyo-battery-appliance.js";
|
|
5
|
+
import { EnyoBatteryStateEnum, EnyoDataBusInverterValuesV1String, EnyoInverterStateEnum } from "@enyo-energy/energy-app-sdk/dist/types/enyo-data-bus-value.js";
|
|
5
6
|
/**
|
|
6
7
|
* A single phase in the tiered retry schedule
|
|
7
8
|
*/
|
|
@@ -665,6 +666,98 @@ export declare enum SunspecPvPowerSource {
|
|
|
665
666
|
Mppt = "mppt",
|
|
666
667
|
Inverter = "inverter"
|
|
667
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* The concrete register set an inverter's PV power reading was actually derived
|
|
671
|
+
* from — the *resolved* origin, as opposed to {@link SunspecPvPowerSource} which
|
|
672
|
+
* is the *configured* preference. Returned on {@link SunspecInverterReading} so a
|
|
673
|
+
* consumer can see which telemetry produced the number.
|
|
674
|
+
*
|
|
675
|
+
* - `MpptStrings`: summed per-string DC power from Model 160 (battery strings
|
|
676
|
+
* `StCha 3` / `StDisCha 4` excluded). Already pure PV — never battery-adjusted.
|
|
677
|
+
* - `InverterDc`: the inverter's total DC power (Model 101 `DCW`). Pure PV — never
|
|
678
|
+
* battery-adjusted.
|
|
679
|
+
* - `InverterAc`: the inverter's total AC power (Model 101 `W`). On a hybrid this
|
|
680
|
+
* includes battery flow, so `inverterPowerW` backs it out
|
|
681
|
+
* (PV = AC + batteryPowerW) while `inverterPowerWRaw` keeps the uncorrected AC value.
|
|
682
|
+
* - `None`: no strictly-positive inverter total was available; `inverterPowerW` is 0.
|
|
683
|
+
*/
|
|
684
|
+
export declare enum SunspecPvPowerOrigin {
|
|
685
|
+
MpptStrings = "mppt-strings",
|
|
686
|
+
InverterDc = "inverter-dc",
|
|
687
|
+
InverterAc = "inverter-ac",
|
|
688
|
+
None = "none"
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* A decoupled snapshot of an inverter's live telemetry, produced by
|
|
692
|
+
* `SunspecInverter.getInverterReading()`. Contains no data-bus message and is
|
|
693
|
+
* never sent anywhere — the consumer decides whether to publish it. The same
|
|
694
|
+
* data drives the SDK's own `InverterValuesUpdateV1` message when polling is used.
|
|
695
|
+
*/
|
|
696
|
+
export interface SunspecInverterReading {
|
|
697
|
+
/**
|
|
698
|
+
* The auto-calculated PV production (W) to use — the configured source's value
|
|
699
|
+
* (see {@link SunspecPvPowerSource}) with battery charge/discharge backed out of
|
|
700
|
+
* the AC fallback, clamped to ≥ 0. `powerOrigin` says which source produced it.
|
|
701
|
+
* This is the value the SDK publishes as `pvPowerW` when it builds the data-bus
|
|
702
|
+
* message itself.
|
|
703
|
+
*/
|
|
704
|
+
inverterPowerW: number;
|
|
705
|
+
/**
|
|
706
|
+
* The inverter's own total power (W), UNCORRECTED: Model 101 `DCW` when strictly
|
|
707
|
+
* positive, else AC (`W`) when strictly positive, else 0. Clamped to ≥ 0. Always
|
|
708
|
+
* computed and reported independently of `powerOrigin`, so it is available even
|
|
709
|
+
* when {@link inverterPowerW} is sourced from the MPPT strings. Battery flow is
|
|
710
|
+
* NOT backed out here — for the AC branch that is exactly {@link inverterPowerW}
|
|
711
|
+
* minus the battery correction.
|
|
712
|
+
*/
|
|
713
|
+
inverterPowerWRaw: number;
|
|
714
|
+
/**
|
|
715
|
+
* Summed per-string MPPT DC power (W) from Model 160 (battery strings
|
|
716
|
+
* `StCha 3` / `StDisCha 4` excluded), clamped to ≥ 0. Always computed and
|
|
717
|
+
* reported independently of `powerOrigin` — `0` when no PV strings are readable.
|
|
718
|
+
*/
|
|
719
|
+
inverterPowerWDcStrings: number;
|
|
720
|
+
/** Which register set {@link inverterPowerW} was selected from. */
|
|
721
|
+
powerOrigin: SunspecPvPowerOrigin;
|
|
722
|
+
/**
|
|
723
|
+
* The live battery power (W) backed out of the AC fallback, signed
|
|
724
|
+
* (positive = charging, negative = discharging). Only fetched when the AC/DC
|
|
725
|
+
* inverter-total fallback is in use; `undefined` otherwise or when no live
|
|
726
|
+
* battery source is available.
|
|
727
|
+
*/
|
|
728
|
+
batteryPowerW?: number;
|
|
729
|
+
/** Operating state mapped to the Enyo enum. */
|
|
730
|
+
state: EnyoInverterStateEnum;
|
|
731
|
+
/** Raw SunSpec operating state (`St`), unmapped. */
|
|
732
|
+
operatingState?: number;
|
|
733
|
+
voltageL1: number;
|
|
734
|
+
voltageL2?: number;
|
|
735
|
+
voltageL3?: number;
|
|
736
|
+
/**
|
|
737
|
+
* Raw cumulative AC energy (Wh) straight from the register. NOT sanitized —
|
|
738
|
+
* the SDK's acc32 word-boundary guard is applied only on the publish path, so
|
|
739
|
+
* a consumer reading directly should expect the occasional register artifact.
|
|
740
|
+
*/
|
|
741
|
+
acEnergyWh?: number;
|
|
742
|
+
/** Per-string DC telemetry (Model 160), battery strings filtered out. */
|
|
743
|
+
strings: EnyoDataBusInverterValuesV1String[];
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* A decoupled snapshot of a battery's live telemetry, produced by
|
|
747
|
+
* `SunspecBattery.getBatteryReading()`. Contains no data-bus message.
|
|
748
|
+
*/
|
|
749
|
+
export interface SunspecBatteryReading {
|
|
750
|
+
/** State of charge (%). */
|
|
751
|
+
soc: number;
|
|
752
|
+
/**
|
|
753
|
+
* Live battery power (W), signed: positive = charging, negative = discharging.
|
|
754
|
+
* `undefined` when the device exposes no live power source (e.g. a Model
|
|
755
|
+
* 124-only battery with no MPPT battery strings).
|
|
756
|
+
*/
|
|
757
|
+
powerW?: number;
|
|
758
|
+
/** Charge/discharge state mapped to the Enyo enum. */
|
|
759
|
+
state?: EnyoBatteryStateEnum;
|
|
760
|
+
}
|
|
668
761
|
export declare enum SunspecBatteryCapability {
|
|
669
762
|
GridCharging = "grid-charging",
|
|
670
763
|
DischargeLimit = "discharge-limit",
|
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.98';
|
|
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, 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 } 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";
|
|
@@ -122,6 +122,18 @@ export declare abstract class BaseSunspecDevice {
|
|
|
122
122
|
*/
|
|
123
123
|
protected buildSnapshotService<T>(onRestore: (snapshot: CalibrationSnapshot<T>, reason: RestoreReason) => Promise<void>): SnapshotService<T> | undefined;
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* The result of the configured PV-source selection: the picked source's raw and
|
|
127
|
+
* battery-adjusted power plus its resolved origin. Internal to the
|
|
128
|
+
* source-selection helpers (`selectPvPowerW` / `inverterTotalPvPowerW`); the
|
|
129
|
+
* public {@link SunspecInverterReading} exposes an independent breakdown built
|
|
130
|
+
* from these plus the always-computed DC-strings and inverter-total figures.
|
|
131
|
+
*/
|
|
132
|
+
type SunspecPvPower = {
|
|
133
|
+
rawPowerW: number;
|
|
134
|
+
batteryAdjustedPowerW: number;
|
|
135
|
+
origin: SunspecPvPowerOrigin;
|
|
136
|
+
};
|
|
125
137
|
/**
|
|
126
138
|
* Sunspec Inverter implementation using dynamic model discovery
|
|
127
139
|
*/
|
|
@@ -239,6 +251,37 @@ export declare class SunspecInverter extends BaseSunspecDevice {
|
|
|
239
251
|
*/
|
|
240
252
|
getPowerProductionLimit(): Promise<number | null>;
|
|
241
253
|
private mapOperatingState;
|
|
254
|
+
/**
|
|
255
|
+
* Read a decoupled snapshot of the inverter's live telemetry — PV power (raw
|
|
256
|
+
* and battery-adjusted), its resolved origin, operating state, voltages, AC
|
|
257
|
+
* energy and per-string DC data — WITHOUT constructing or sending any data-bus
|
|
258
|
+
* message. The consumer decides whether and how to publish it.
|
|
259
|
+
*
|
|
260
|
+
* This is the clean read primitive the SDK's own polling (`readData`) is built
|
|
261
|
+
* on, so a direct caller gets exactly the same numbers the bus would carry
|
|
262
|
+
* (except `acEnergyWh`, which is returned raw here and sanitized only on the
|
|
263
|
+
* publish path — see {@link SunspecInverterReading.acEnergyWh}).
|
|
264
|
+
*
|
|
265
|
+
* Returns `null` when not connected (after a reconnect attempt) or when the
|
|
266
|
+
* device exposes no readable inverter model.
|
|
267
|
+
*/
|
|
268
|
+
getInverterReading(): Promise<SunspecInverterReading | null>;
|
|
269
|
+
/**
|
|
270
|
+
* Fetch the live battery power (signed: positive = charging, negative =
|
|
271
|
+
* discharging) that {@link inverterTotalPvPowerW} backs out of the AC fallback.
|
|
272
|
+
* Only fetched when the inverter-total fallback will actually be used — the
|
|
273
|
+
* correction is irrelevant for the MPPT-string path — so a device with working
|
|
274
|
+
* strings never pays the extra battery read. Prefers the Model 160
|
|
275
|
+
* `StCha`/`StDisCha` strings, falling back to Model 124/802. `undefined` when
|
|
276
|
+
* no correction is needed or no live battery source exists.
|
|
277
|
+
*/
|
|
278
|
+
private fetchAcCorrectionBatteryPowerW;
|
|
279
|
+
/**
|
|
280
|
+
* Assemble a {@link SunspecInverterReading} from an already-read register set.
|
|
281
|
+
* Pure (no I/O, no side effects) so both `getInverterReading` and the polling
|
|
282
|
+
* `readData` produce identical readings from a single shared code path.
|
|
283
|
+
*/
|
|
284
|
+
private buildInverterReading;
|
|
242
285
|
/**
|
|
243
286
|
* PV production in Watt, sourced according to the configured `pvPowerSource`:
|
|
244
287
|
*
|
|
@@ -255,19 +298,38 @@ export declare class SunspecInverter extends BaseSunspecDevice {
|
|
|
255
298
|
* Both inverter-total steps require a strictly positive value, so NOT_IMPLEMENTED
|
|
256
299
|
* DCW (decodes to 0) falls through to AC, and a negative AC reading (e.g. a hybrid
|
|
257
300
|
* importing from grid) falls through to 0 rather than reporting negative production.
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
301
|
+
*
|
|
302
|
+
* The AC fallback backs out battery power via `batteryPowerW` (signed: positive =
|
|
303
|
+
* charging, negative = discharging). A hybrid's AC total is PV − charge + discharge,
|
|
304
|
+
* so real PV = AC + batteryPowerW. Without this, a battery discharging at night while
|
|
305
|
+
* the MPPT is unreadable would be reported as phantom PV production. `batteryPowerW`
|
|
306
|
+
* is undefined when no live battery source is available, in which case AC is used
|
|
307
|
+
* uncorrected (still better than reporting 0).
|
|
308
|
+
*
|
|
309
|
+
* The returned `pvPowerW` is always clamped to ≥ 0 — PV production is non-negative by
|
|
310
|
+
* definition and must never surface as a negative value on the data bus.
|
|
261
311
|
*/
|
|
262
|
-
protected selectPvPowerW(dcStrings: EnyoDataBusInverterValuesV1String[], inverterData: SunspecInverterData):
|
|
263
|
-
pvPowerW: number;
|
|
264
|
-
source: string;
|
|
265
|
-
};
|
|
312
|
+
protected selectPvPowerW(dcStrings: EnyoDataBusInverterValuesV1String[], inverterData: SunspecInverterData, batteryPowerW?: number): SunspecPvPower;
|
|
266
313
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
314
|
+
* Whether {@link selectPvPowerW} will source PV from the inverter total (rather than
|
|
315
|
+
* the summed MPPT strings) for the given string count. Mppt never does; Inverter
|
|
316
|
+
* always does; Auto does only when there are no strings. Exposed so `readData` can
|
|
317
|
+
* decide up front whether it needs to fetch battery power for the AC correction.
|
|
318
|
+
*/
|
|
319
|
+
private wouldUseInverterTotal;
|
|
320
|
+
/**
|
|
321
|
+
* Inverter total PV power from Model 101: DCW when strictly positive, else AC (with
|
|
322
|
+
* battery power backed out) when the result is strictly positive, else 0. See
|
|
323
|
+
* {@link selectPvPowerW} for the battery correction and why positivity matters.
|
|
269
324
|
*/
|
|
270
325
|
private inverterTotalPvPowerW;
|
|
326
|
+
/**
|
|
327
|
+
* Summed per-string MPPT DC power (Model 160), battery strings already filtered
|
|
328
|
+
* out by {@link mapMPPTToStrings}. finiteOr per-string so one NaN/Infinity powerW
|
|
329
|
+
* cannot poison the sum; clamped to ≥ 0. Feeds both the MPPT-source selection and
|
|
330
|
+
* the always-reported {@link SunspecInverterReading.inverterPowerWDcStrings}.
|
|
331
|
+
*/
|
|
332
|
+
private sumDcStringsW;
|
|
271
333
|
/**
|
|
272
334
|
* Map MPPT data to DC string structure for data bus
|
|
273
335
|
* Filters out battery-related strings (StCha 3, StDisCha 4)
|
|
@@ -346,6 +408,20 @@ export declare function detectFeaturesFromRegisters(batteryData: SunspecBatteryD
|
|
|
346
408
|
* Exported as a free function so the preference logic can be unit-tested
|
|
347
409
|
* without the full `SunspecBattery` scaffold.
|
|
348
410
|
*/
|
|
411
|
+
/**
|
|
412
|
+
* Sum battery charge/discharge power from Model 160 MPPT strings.
|
|
413
|
+
*
|
|
414
|
+
* - `StCha 3` → charging power (added, positive)
|
|
415
|
+
* - `StDisCha 4` → discharging power (subtracted)
|
|
416
|
+
*
|
|
417
|
+
* The result follows the battery-power sign convention used across this file:
|
|
418
|
+
* positive = charging, negative = discharging. Returns `undefined` when neither
|
|
419
|
+
* battery string is present, so callers can fall through to another source.
|
|
420
|
+
*
|
|
421
|
+
* Exported as a free function so it can be unit-tested and reused by both the
|
|
422
|
+
* SunspecBattery live-power path and the SunspecInverter AC-fallback correction.
|
|
423
|
+
*/
|
|
424
|
+
export declare function sumMpptBatteryPowerW(mpptDataList: SunspecMPPTData[]): number | undefined;
|
|
349
425
|
export declare function selectLiveBatteryPowerW(mpptBatteryPowerW: number | undefined, batteryData: SunspecBatteryData | null): number | undefined;
|
|
350
426
|
export declare function filterFeaturesByCalibrationResult(detected: EnyoBatteryFeature[], result: CalibrationResult | undefined, controllable: readonly EnyoBatteryFeature[]): EnyoBatteryFeature[];
|
|
351
427
|
/**
|
|
@@ -411,6 +487,25 @@ export declare class SunspecBattery extends BaseSunspecDevice {
|
|
|
411
487
|
* Map SunSpec battery charge state to Enyo battery state
|
|
412
488
|
*/
|
|
413
489
|
private mapToEnyoBatteryState;
|
|
490
|
+
/**
|
|
491
|
+
* Read a decoupled snapshot of the battery's live telemetry — state of charge,
|
|
492
|
+
* signed power (positive = charging, negative = discharging) and charge state —
|
|
493
|
+
* WITHOUT constructing or sending any data-bus message. The consumer decides
|
|
494
|
+
* whether and how to publish it.
|
|
495
|
+
*
|
|
496
|
+
* This is the clean read primitive the SDK's own polling (`readData`) is built
|
|
497
|
+
* on, so a direct caller gets exactly the same numbers the bus would carry.
|
|
498
|
+
* Returns `null` when not connected (after a reconnect attempt) or when the
|
|
499
|
+
* device exposes no readable battery model.
|
|
500
|
+
*/
|
|
501
|
+
getBatteryReading(): Promise<SunspecBatteryReading | null>;
|
|
502
|
+
/**
|
|
503
|
+
* Assemble a {@link SunspecBatteryReading} from an already-read register set.
|
|
504
|
+
* Pure (no I/O, no side effects) so both `getBatteryReading` and the polling
|
|
505
|
+
* `readData` produce identical readings from a single shared code path. See
|
|
506
|
+
* {@link selectLiveBatteryPowerW} for the power source-preference rationale.
|
|
507
|
+
*/
|
|
508
|
+
private buildBatteryReading;
|
|
414
509
|
/**
|
|
415
510
|
* Update battery data and return data bus messages
|
|
416
511
|
*/
|
|
@@ -577,3 +672,4 @@ export declare class SunspecMeter extends BaseSunspecDevice {
|
|
|
577
672
|
*/
|
|
578
673
|
readData(clockId: string, resolution: EnyoDataBusMessageResolution): Promise<EnyoDataBusMessage[]>;
|
|
579
674
|
}
|
|
675
|
+
export {};
|