@enyo-energy/sunspec-sdk 1.12.0 → 1.13.0

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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SunspecCustomDevice = exports.SunspecMeter = exports.SunspecBattery = exports.SunspecInverter = exports.BaseSunspecDevice = void 0;
4
4
  exports.detectFeaturesFromRegisters = detectFeaturesFromRegisters;
5
5
  exports.ratedDischargePowerW = ratedDischargePowerW;
6
+ exports.mpptStorageStringKind = mpptStorageStringKind;
6
7
  exports.sumMpptBatteryPowerW = sumMpptBatteryPowerW;
7
8
  exports.selectLiveBatteryPowerW = selectLiveBatteryPowerW;
8
9
  exports.filterFeaturesByCalibrationResult = filterFeaturesByCalibrationResult;
@@ -525,10 +526,15 @@ class SunspecInverter extends BaseSunspecDevice {
525
526
  * reporting Faulted. Debounces transient single-poll FAULT reads (e.g. a
526
527
  * DC-coupled battery disturbing a string) that would otherwise oscillate
527
528
  * the appliance status. Recovery is immediate (counter resets on the first
528
- * non-fault read).
529
+ * non-fault read). Used when getOperatingFaultGraceMs() returns undefined.
529
530
  */
530
531
  static OPERATING_FAULT_THRESHOLD = 3;
531
532
  consecutiveOperatingFaults = 0;
533
+ // Poll timestamp (ms) of the first read of the current uninterrupted
534
+ // operatingState=FAULT run; undefined while not in FAULT. Cleared on any
535
+ // gap in observation (failed read, offline, reconnect) so unobserved time
536
+ // never counts towards getOperatingFaultGraceMs().
537
+ operatingFaultSinceMs;
532
538
  // In-memory only — never persisted. See SunspecInverterErrorState.
533
539
  errorState = { activeCodes: [], lastStatus: 'healthy' };
534
540
  snapshotService;
@@ -723,6 +729,9 @@ class SunspecInverter extends BaseSunspecDevice {
723
729
  messages.push(inverterMessage);
724
730
  await this.detectAndEmitStatusTransition(inverterData, timestamp);
725
731
  }
732
+ else {
733
+ this.interruptOperatingFaultRun();
734
+ }
726
735
  this.consecutiveReconnectFailures = 0;
727
736
  if (this.applianceId) {
728
737
  const appliance = await this.applianceManager.findApplianceById(this.applianceId);
@@ -876,6 +885,34 @@ class SunspecInverter extends BaseSunspecDevice {
876
885
  }
877
886
  };
878
887
  }
888
+ /**
889
+ * How long operatingState=7 (FAULT) must be reported without interruption
890
+ * before the inverter is reported Faulted, in ms. undefined (the default)
891
+ * keeps the poll-count debounce of OPERATING_FAULT_THRESHOLD consecutive
892
+ * FAULT reads. Override for vendors that report short FAULT phases without
893
+ * an error code while operating normally. Recovery stays immediate, and
894
+ * decoded event-register error bits are not affected.
895
+ */
896
+ getOperatingFaultGraceMs() {
897
+ return undefined;
898
+ }
899
+ interruptOperatingFaultRun() {
900
+ this.operatingFaultSinceMs = undefined;
901
+ }
902
+ isOperatingFaultSustained(operatingFaultRaw, timestamp) {
903
+ if (!operatingFaultRaw) {
904
+ this.consecutiveOperatingFaults = 0;
905
+ this.operatingFaultSinceMs = undefined;
906
+ return false;
907
+ }
908
+ this.consecutiveOperatingFaults++;
909
+ this.operatingFaultSinceMs ??= timestamp.getTime();
910
+ const graceMs = this.getOperatingFaultGraceMs();
911
+ if (graceMs === undefined) {
912
+ return this.consecutiveOperatingFaults >= SunspecInverter.OPERATING_FAULT_THRESHOLD;
913
+ }
914
+ return timestamp.getTime() - this.operatingFaultSinceMs >= graceMs;
915
+ }
879
916
  async detectAndEmitStatusTransition(data, timestamp) {
880
917
  if (!this.applianceId || !this.dataBus)
881
918
  return;
@@ -887,13 +924,13 @@ class SunspecInverter extends BaseSunspecDevice {
887
924
  // no error bits) reports Healthy even if it was previously faulted.
888
925
  //
889
926
  // A single FAULT read is debounced: we only treat it as a fault after
890
- // OPERATING_FAULT_THRESHOLD consecutive FAULT polls, so a transient
891
- // wobble (e.g. a faulted DC-coupled battery on a string) does not
892
- // oscillate the status. Recovery is immediate — the counter resets on
893
- // the first non-fault read. Event-register error bits stay immediate.
927
+ // OPERATING_FAULT_THRESHOLD consecutive FAULT polls (or, if the subclass
928
+ // sets getOperatingFaultGraceMs(), after FAULT has persisted that long),
929
+ // so a transient wobble (e.g. a faulted DC-coupled battery on a string)
930
+ // does not oscillate the status. Recovery is immediate — the debounce
931
+ // resets on the first non-fault read. Event-register error bits stay immediate.
894
932
  const operatingFaultRaw = data.operatingState === sunspec_interfaces_js_1.SunspecInverterOperatingState.FAULT;
895
- this.consecutiveOperatingFaults = operatingFaultRaw ? this.consecutiveOperatingFaults + 1 : 0;
896
- const operatingFault = this.consecutiveOperatingFaults >= SunspecInverter.OPERATING_FAULT_THRESHOLD;
933
+ const operatingFault = this.isOperatingFaultSustained(operatingFaultRaw, timestamp);
897
934
  const newStatus = (codeIds.length > 0 || operatingFault)
898
935
  ? enyo_appliance_js_1.EnyoApplianceStatusEnum.Faulted
899
936
  : enyo_appliance_js_1.EnyoApplianceStatusEnum.Healthy;
@@ -933,7 +970,12 @@ class SunspecInverter extends BaseSunspecDevice {
933
970
  getRequiredModelIds() {
934
971
  return SunspecInverter.INVERTER_MODEL_IDS;
935
972
  }
973
+ async markOffline() {
974
+ this.interruptOperatingFaultRun();
975
+ await super.markOffline();
976
+ }
936
977
  async onConnectionFailure(consecutiveFailures) {
978
+ this.interruptOperatingFaultRun();
937
979
  if (!this.applianceId || !this.dataBus)
938
980
  return;
939
981
  if (consecutiveFailures < SunspecInverter.CONNECTION_FAULT_THRESHOLD)
@@ -956,6 +998,7 @@ class SunspecInverter extends BaseSunspecDevice {
956
998
  };
957
999
  }
958
1000
  async onConnectionRestored() {
1001
+ this.interruptOperatingFaultRun();
959
1002
  if (!this.applianceId || !this.dataBus)
960
1003
  return;
961
1004
  if (this.errorState.lastStatus !== 'connection_lost')
@@ -1203,13 +1246,14 @@ class SunspecInverter extends BaseSunspecDevice {
1203
1246
  }
1204
1247
  /**
1205
1248
  * Map MPPT data to DC string structure for data bus
1206
- * Filters out battery-related strings (StCha 3, StDisCha 4)
1249
+ * Filters out battery-related strings (StCha n, StDisCha n+1; see
1250
+ * {@link mpptStorageStringKind})
1207
1251
  */
1208
1252
  mapMPPTToStrings(mpptDataList) {
1209
1253
  const result = [];
1210
1254
  mpptDataList.forEach((mppt, index) => {
1211
1255
  // Skip battery-related strings - they will be handled separately
1212
- if (mppt.stringId === 'StCha 3' || mppt.stringId === 'StDisCha 4') {
1256
+ if (mpptStorageStringKind(mppt.stringId) !== undefined) {
1213
1257
  return;
1214
1258
  }
1215
1259
  // Only include strings with valid data
@@ -1428,7 +1472,7 @@ function ratedDischargePowerW(batteryData) {
1428
1472
  /**
1429
1473
  * Pick the live battery power, in preference order:
1430
1474
  *
1431
- * 1. Model 160 (MPPT) `StCha 3` / `StDisCha 4` — direct DC-link reading,
1475
+ * 1. Model 160 (MPPT) `StCha n` / `StDisCha n+1` — direct DC-link reading,
1432
1476
  * passed in as the already-summed `mpptBatteryPowerW`.
1433
1477
  * 2. Model 802 `w` (offset 47) — surfaced as `chargePower` / `dischargePower`
1434
1478
  * by the Model 802 path of `SunspecModbusClient.readBatteryData`.
@@ -1442,11 +1486,33 @@ function ratedDischargePowerW(batteryData) {
1442
1486
  * Exported as a free function so the preference logic can be unit-tested
1443
1487
  * without the full `SunspecBattery` scaffold.
1444
1488
  */
1489
+ /**
1490
+ * Classify a Model 160 module by its `IDStr` as a DC-coupled battery string.
1491
+ *
1492
+ * Fronius hybrids list the battery as two extra Model 160 modules after the PV
1493
+ * MPPTs: `StCha <n>` (charge power) and `StDisCha <n+1>` (discharge power). The
1494
+ * number is the module position, so it depends on how many PV trackers the
1495
+ * device has: a GEN24 Plus (2 MPPTs) reports `StCha 3` / `StDisCha 4`, a
1496
+ * Verto (3 MPPTs) `StCha 4` / `StDisCha 5`. Match the prefix, never the full
1497
+ * label, or a battery module is counted as a PV string.
1498
+ *
1499
+ * Returns `undefined` for a PV string.
1500
+ */
1501
+ function mpptStorageStringKind(stringId) {
1502
+ const id = stringId?.trim() ?? '';
1503
+ if (/^StCha\b/i.test(id)) {
1504
+ return 'charge';
1505
+ }
1506
+ if (/^StDisCha\b/i.test(id)) {
1507
+ return 'discharge';
1508
+ }
1509
+ return undefined;
1510
+ }
1445
1511
  /**
1446
1512
  * Sum battery charge/discharge power from Model 160 MPPT strings.
1447
1513
  *
1448
- * - `StCha 3` → charging power (added, positive)
1449
- * - `StDisCha 4` → discharging power (subtracted)
1514
+ * - `StCha n` → charging power (added, positive)
1515
+ * - `StDisCha n+1` → discharging power (subtracted)
1450
1516
  *
1451
1517
  * The result follows the battery-power sign convention used across this file:
1452
1518
  * positive = charging, negative = discharging. Returns `undefined` when neither
@@ -1458,10 +1524,11 @@ function ratedDischargePowerW(batteryData) {
1458
1524
  function sumMpptBatteryPowerW(mpptDataList) {
1459
1525
  let batteryPowerW;
1460
1526
  for (const mppt of mpptDataList) {
1461
- if (mppt.stringId === 'StCha 3' && mppt.dcPower !== undefined) {
1527
+ const kind = mpptStorageStringKind(mppt.stringId);
1528
+ if (kind === 'charge' && mppt.dcPower !== undefined) {
1462
1529
  batteryPowerW = (batteryPowerW ?? 0) + mppt.dcPower;
1463
1530
  }
1464
- else if (mppt.stringId === 'StDisCha 4' && mppt.dcPower !== undefined) {
1531
+ else if (kind === 'discharge' && mppt.dcPower !== undefined) {
1465
1532
  batteryPowerW = (batteryPowerW ?? 0) - mppt.dcPower;
1466
1533
  }
1467
1534
  }
@@ -1972,8 +2039,8 @@ class SunspecBattery extends BaseSunspecDevice {
1972
2039
  }
1973
2040
  /**
1974
2041
  * Extract battery power from MPPT strings with specific IDs
1975
- * StCha 3: Battery charging power (positive)
1976
- * StDisCha 4: Battery discharging power (negative)
2042
+ * StCha n: Battery charging power (positive)
2043
+ * StDisCha n+1: Battery discharging power (negative)
1977
2044
  */
1978
2045
  extractBatteryPowerFromMPPT(mpptDataList) {
1979
2046
  return sumMpptBatteryPowerW(mpptDataList);
@@ -1985,10 +2052,11 @@ class SunspecBattery extends BaseSunspecDevice {
1985
2052
  let hasCharge = false;
1986
2053
  let hasDischarge = false;
1987
2054
  mpptDataList.forEach((mppt) => {
1988
- if (mppt.stringId === 'StCha 3' && mppt.dcPower !== undefined && mppt.dcPower > 0) {
2055
+ const kind = mpptStorageStringKind(mppt.stringId);
2056
+ if (kind === 'charge' && mppt.dcPower !== undefined && mppt.dcPower > 0) {
1989
2057
  hasCharge = true;
1990
2058
  }
1991
- else if (mppt.stringId === 'StDisCha 4' && mppt.dcPower !== undefined && mppt.dcPower > 0) {
2059
+ else if (kind === 'discharge' && mppt.dcPower !== undefined && mppt.dcPower > 0) {
1992
2060
  hasDischarge = true;
1993
2061
  }
1994
2062
  });
@@ -223,10 +223,11 @@ export declare class SunspecInverter extends BaseSunspecDevice {
223
223
  * reporting Faulted. Debounces transient single-poll FAULT reads (e.g. a
224
224
  * DC-coupled battery disturbing a string) that would otherwise oscillate
225
225
  * the appliance status. Recovery is immediate (counter resets on the first
226
- * non-fault read).
226
+ * non-fault read). Used when getOperatingFaultGraceMs() returns undefined.
227
227
  */
228
228
  private static readonly OPERATING_FAULT_THRESHOLD;
229
229
  private consecutiveOperatingFaults;
230
+ private operatingFaultSinceMs?;
230
231
  private errorState;
231
232
  private snapshotService?;
232
233
  private statusReassertedThisSession;
@@ -299,7 +300,18 @@ export declare class SunspecInverter extends BaseSunspecDevice {
299
300
  protected mapVendorEventBit(_registerIndex: 1 | 2 | 3 | 4, _bit: number): EnyoApplianceErrorCode | undefined;
300
301
  private hasErrorSetChanged;
301
302
  private buildStatusMessage;
302
- private detectAndEmitStatusTransition;
303
+ /**
304
+ * How long operatingState=7 (FAULT) must be reported without interruption
305
+ * before the inverter is reported Faulted, in ms. undefined (the default)
306
+ * keeps the poll-count debounce of OPERATING_FAULT_THRESHOLD consecutive
307
+ * FAULT reads. Override for vendors that report short FAULT phases without
308
+ * an error code while operating normally. Recovery stays immediate, and
309
+ * decoded event-register error bits are not affected.
310
+ */
311
+ protected getOperatingFaultGraceMs(): number | undefined;
312
+ private interruptOperatingFaultRun;
313
+ private isOperatingFaultSustained;
314
+ protected detectAndEmitStatusTransition(data: SunspecInverterData, timestamp: Date): Promise<void>;
303
315
  /**
304
316
  * A reconnect has only recovered the inverter if discovery finds one of its
305
317
  * data models. An SE gateway can accept the new socket and answer a partial
@@ -308,6 +320,7 @@ export declare class SunspecInverter extends BaseSunspecDevice {
308
320
  * no 101/103/111/112/113 model and report 0 W. Require an actual inverter model.
309
321
  */
310
322
  protected getRequiredModelIds(): readonly number[];
323
+ protected markOffline(): Promise<void>;
311
324
  protected onConnectionFailure(consecutiveFailures: number): Promise<void>;
312
325
  protected onConnectionRestored(): Promise<void>;
313
326
  /**
@@ -422,7 +435,8 @@ export declare class SunspecInverter extends BaseSunspecDevice {
422
435
  private sumDcStringsW;
423
436
  /**
424
437
  * Map MPPT data to DC string structure for data bus
425
- * Filters out battery-related strings (StCha 3, StDisCha 4)
438
+ * Filters out battery-related strings (StCha n, StDisCha n+1; see
439
+ * {@link mpptStorageStringKind})
426
440
  */
427
441
  protected mapMPPTToStrings(mpptDataList: SunspecMPPTData[]): EnyoDataBusInverterValuesV1String[];
428
442
  private mapMPPTOperatingState;
@@ -494,7 +508,7 @@ export declare function ratedDischargePowerW(batteryData: SunspecBatteryData | n
494
508
  /**
495
509
  * Pick the live battery power, in preference order:
496
510
  *
497
- * 1. Model 160 (MPPT) `StCha 3` / `StDisCha 4` — direct DC-link reading,
511
+ * 1. Model 160 (MPPT) `StCha n` / `StDisCha n+1` — direct DC-link reading,
498
512
  * passed in as the already-summed `mpptBatteryPowerW`.
499
513
  * 2. Model 802 `w` (offset 47) — surfaced as `chargePower` / `dischargePower`
500
514
  * by the Model 802 path of `SunspecModbusClient.readBatteryData`.
@@ -508,11 +522,24 @@ export declare function ratedDischargePowerW(batteryData: SunspecBatteryData | n
508
522
  * Exported as a free function so the preference logic can be unit-tested
509
523
  * without the full `SunspecBattery` scaffold.
510
524
  */
525
+ /**
526
+ * Classify a Model 160 module by its `IDStr` as a DC-coupled battery string.
527
+ *
528
+ * Fronius hybrids list the battery as two extra Model 160 modules after the PV
529
+ * MPPTs: `StCha <n>` (charge power) and `StDisCha <n+1>` (discharge power). The
530
+ * number is the module position, so it depends on how many PV trackers the
531
+ * device has: a GEN24 Plus (2 MPPTs) reports `StCha 3` / `StDisCha 4`, a
532
+ * Verto (3 MPPTs) `StCha 4` / `StDisCha 5`. Match the prefix, never the full
533
+ * label, or a battery module is counted as a PV string.
534
+ *
535
+ * Returns `undefined` for a PV string.
536
+ */
537
+ export declare function mpptStorageStringKind(stringId: string | undefined): 'charge' | 'discharge' | undefined;
511
538
  /**
512
539
  * Sum battery charge/discharge power from Model 160 MPPT strings.
513
540
  *
514
- * - `StCha 3` → charging power (added, positive)
515
- * - `StDisCha 4` → discharging power (subtracted)
541
+ * - `StCha n` → charging power (added, positive)
542
+ * - `StDisCha n+1` → discharging power (subtracted)
516
543
  *
517
544
  * The result follows the battery-power sign convention used across this file:
518
545
  * positive = charging, negative = discharging. Returns `undefined` when neither
@@ -677,8 +704,8 @@ export declare class SunspecBattery extends BaseSunspecDevice {
677
704
  readData(clockId: string, resolution: EnyoDataBusMessageResolution): Promise<EnyoDataBusMessage[]>;
678
705
  /**
679
706
  * Extract battery power from MPPT strings with specific IDs
680
- * StCha 3: Battery charging power (positive)
681
- * StDisCha 4: Battery discharging power (negative)
707
+ * StCha n: Battery charging power (positive)
708
+ * StDisCha n+1: Battery discharging power (negative)
682
709
  */
683
710
  private extractBatteryPowerFromMPPT;
684
711
  /**
@@ -332,7 +332,7 @@ var SunspecPvPowerSource;
332
332
  * consumer can see which telemetry produced the number.
333
333
  *
334
334
  * - `MpptStrings`: summed per-string DC power from Model 160 (battery strings
335
- * `StCha 3` / `StDisCha 4` excluded). Already pure PV — never battery-adjusted.
335
+ * `StCha n` / `StDisCha n+1` excluded). Already pure PV — never battery-adjusted.
336
336
  * - `InverterDc`: the inverter's total DC power (Model 101 `DCW`). Pure PV — never
337
337
  * battery-adjusted.
338
338
  * - `InverterAc`: the inverter's total AC power (Model 101 `W`). On a hybrid this
@@ -892,7 +892,7 @@ export declare enum SunspecPvPowerSource {
892
892
  * consumer can see which telemetry produced the number.
893
893
  *
894
894
  * - `MpptStrings`: summed per-string DC power from Model 160 (battery strings
895
- * `StCha 3` / `StDisCha 4` excluded). Already pure PV — never battery-adjusted.
895
+ * `StCha n` / `StDisCha n+1` excluded). Already pure PV — never battery-adjusted.
896
896
  * - `InverterDc`: the inverter's total DC power (Model 101 `DCW`). Pure PV — never
897
897
  * battery-adjusted.
898
898
  * - `InverterAc`: the inverter's total AC power (Model 101 `W`). On a hybrid this
@@ -932,7 +932,7 @@ export interface SunspecInverterReading {
932
932
  inverterPowerWRaw: number;
933
933
  /**
934
934
  * Summed per-string MPPT DC power (W) from Model 160 (battery strings
935
- * `StCha 3` / `StDisCha 4` excluded), clamped to ≥ 0. Always computed and
935
+ * `StCha n` / `StDisCha n+1` excluded), clamped to ≥ 0. Always computed and
936
936
  * reported independently of `powerOrigin` — `0` when no PV strings are readable.
937
937
  */
938
938
  inverterPowerWDcStrings: number;
@@ -2494,7 +2494,7 @@ class SunspecModbusClient {
2494
2494
  // a live measurement — and produces e.g. 5000 W of "charging"
2495
2495
  // for an idle battery with inWRte = 100 % and a 5 kW nameplate.
2496
2496
  // Live battery power must come from a real source: Model 160
2497
- // StCha 3 / StDisCha 4 (see SunspecBattery.extractBatteryPower
2497
+ // StCha n / StDisCha n+1 (see SunspecBattery.extractBatteryPower
2498
2498
  // FromMPPT) or Model 802 `w` at offset 47 (the Model 802 branch
2499
2499
  // of this method, just below). Model-124-only devices should
2500
2500
  // publish "no signal" rather than the commanded cap.
@@ -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 = '1.12.0';
12
+ exports.SDK_VERSION = '1.13.0';
13
13
  /**
14
14
  * Gets the current SDK version.
15
15
  * @returns The semantic version string of the SDK
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Current version of the enyo Energy App SDK.
7
7
  */
8
- export declare const SDK_VERSION = "1.12.0";
8
+ export declare const SDK_VERSION = "1.13.0";
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
@@ -223,10 +223,11 @@ export declare class SunspecInverter extends BaseSunspecDevice {
223
223
  * reporting Faulted. Debounces transient single-poll FAULT reads (e.g. a
224
224
  * DC-coupled battery disturbing a string) that would otherwise oscillate
225
225
  * the appliance status. Recovery is immediate (counter resets on the first
226
- * non-fault read).
226
+ * non-fault read). Used when getOperatingFaultGraceMs() returns undefined.
227
227
  */
228
228
  private static readonly OPERATING_FAULT_THRESHOLD;
229
229
  private consecutiveOperatingFaults;
230
+ private operatingFaultSinceMs?;
230
231
  private errorState;
231
232
  private snapshotService?;
232
233
  private statusReassertedThisSession;
@@ -299,7 +300,18 @@ export declare class SunspecInverter extends BaseSunspecDevice {
299
300
  protected mapVendorEventBit(_registerIndex: 1 | 2 | 3 | 4, _bit: number): EnyoApplianceErrorCode | undefined;
300
301
  private hasErrorSetChanged;
301
302
  private buildStatusMessage;
302
- private detectAndEmitStatusTransition;
303
+ /**
304
+ * How long operatingState=7 (FAULT) must be reported without interruption
305
+ * before the inverter is reported Faulted, in ms. undefined (the default)
306
+ * keeps the poll-count debounce of OPERATING_FAULT_THRESHOLD consecutive
307
+ * FAULT reads. Override for vendors that report short FAULT phases without
308
+ * an error code while operating normally. Recovery stays immediate, and
309
+ * decoded event-register error bits are not affected.
310
+ */
311
+ protected getOperatingFaultGraceMs(): number | undefined;
312
+ private interruptOperatingFaultRun;
313
+ private isOperatingFaultSustained;
314
+ protected detectAndEmitStatusTransition(data: SunspecInverterData, timestamp: Date): Promise<void>;
303
315
  /**
304
316
  * A reconnect has only recovered the inverter if discovery finds one of its
305
317
  * data models. An SE gateway can accept the new socket and answer a partial
@@ -308,6 +320,7 @@ export declare class SunspecInverter extends BaseSunspecDevice {
308
320
  * no 101/103/111/112/113 model and report 0 W. Require an actual inverter model.
309
321
  */
310
322
  protected getRequiredModelIds(): readonly number[];
323
+ protected markOffline(): Promise<void>;
311
324
  protected onConnectionFailure(consecutiveFailures: number): Promise<void>;
312
325
  protected onConnectionRestored(): Promise<void>;
313
326
  /**
@@ -422,7 +435,8 @@ export declare class SunspecInverter extends BaseSunspecDevice {
422
435
  private sumDcStringsW;
423
436
  /**
424
437
  * Map MPPT data to DC string structure for data bus
425
- * Filters out battery-related strings (StCha 3, StDisCha 4)
438
+ * Filters out battery-related strings (StCha n, StDisCha n+1; see
439
+ * {@link mpptStorageStringKind})
426
440
  */
427
441
  protected mapMPPTToStrings(mpptDataList: SunspecMPPTData[]): EnyoDataBusInverterValuesV1String[];
428
442
  private mapMPPTOperatingState;
@@ -494,7 +508,7 @@ export declare function ratedDischargePowerW(batteryData: SunspecBatteryData | n
494
508
  /**
495
509
  * Pick the live battery power, in preference order:
496
510
  *
497
- * 1. Model 160 (MPPT) `StCha 3` / `StDisCha 4` — direct DC-link reading,
511
+ * 1. Model 160 (MPPT) `StCha n` / `StDisCha n+1` — direct DC-link reading,
498
512
  * passed in as the already-summed `mpptBatteryPowerW`.
499
513
  * 2. Model 802 `w` (offset 47) — surfaced as `chargePower` / `dischargePower`
500
514
  * by the Model 802 path of `SunspecModbusClient.readBatteryData`.
@@ -508,11 +522,24 @@ export declare function ratedDischargePowerW(batteryData: SunspecBatteryData | n
508
522
  * Exported as a free function so the preference logic can be unit-tested
509
523
  * without the full `SunspecBattery` scaffold.
510
524
  */
525
+ /**
526
+ * Classify a Model 160 module by its `IDStr` as a DC-coupled battery string.
527
+ *
528
+ * Fronius hybrids list the battery as two extra Model 160 modules after the PV
529
+ * MPPTs: `StCha <n>` (charge power) and `StDisCha <n+1>` (discharge power). The
530
+ * number is the module position, so it depends on how many PV trackers the
531
+ * device has: a GEN24 Plus (2 MPPTs) reports `StCha 3` / `StDisCha 4`, a
532
+ * Verto (3 MPPTs) `StCha 4` / `StDisCha 5`. Match the prefix, never the full
533
+ * label, or a battery module is counted as a PV string.
534
+ *
535
+ * Returns `undefined` for a PV string.
536
+ */
537
+ export declare function mpptStorageStringKind(stringId: string | undefined): 'charge' | 'discharge' | undefined;
511
538
  /**
512
539
  * Sum battery charge/discharge power from Model 160 MPPT strings.
513
540
  *
514
- * - `StCha 3` → charging power (added, positive)
515
- * - `StDisCha 4` → discharging power (subtracted)
541
+ * - `StCha n` → charging power (added, positive)
542
+ * - `StDisCha n+1` → discharging power (subtracted)
516
543
  *
517
544
  * The result follows the battery-power sign convention used across this file:
518
545
  * positive = charging, negative = discharging. Returns `undefined` when neither
@@ -677,8 +704,8 @@ export declare class SunspecBattery extends BaseSunspecDevice {
677
704
  readData(clockId: string, resolution: EnyoDataBusMessageResolution): Promise<EnyoDataBusMessage[]>;
678
705
  /**
679
706
  * Extract battery power from MPPT strings with specific IDs
680
- * StCha 3: Battery charging power (positive)
681
- * StDisCha 4: Battery discharging power (negative)
707
+ * StCha n: Battery charging power (positive)
708
+ * StDisCha n+1: Battery discharging power (negative)
682
709
  */
683
710
  private extractBatteryPowerFromMPPT;
684
711
  /**
@@ -515,10 +515,15 @@ export class SunspecInverter extends BaseSunspecDevice {
515
515
  * reporting Faulted. Debounces transient single-poll FAULT reads (e.g. a
516
516
  * DC-coupled battery disturbing a string) that would otherwise oscillate
517
517
  * the appliance status. Recovery is immediate (counter resets on the first
518
- * non-fault read).
518
+ * non-fault read). Used when getOperatingFaultGraceMs() returns undefined.
519
519
  */
520
520
  static OPERATING_FAULT_THRESHOLD = 3;
521
521
  consecutiveOperatingFaults = 0;
522
+ // Poll timestamp (ms) of the first read of the current uninterrupted
523
+ // operatingState=FAULT run; undefined while not in FAULT. Cleared on any
524
+ // gap in observation (failed read, offline, reconnect) so unobserved time
525
+ // never counts towards getOperatingFaultGraceMs().
526
+ operatingFaultSinceMs;
522
527
  // In-memory only — never persisted. See SunspecInverterErrorState.
523
528
  errorState = { activeCodes: [], lastStatus: 'healthy' };
524
529
  snapshotService;
@@ -713,6 +718,9 @@ export class SunspecInverter extends BaseSunspecDevice {
713
718
  messages.push(inverterMessage);
714
719
  await this.detectAndEmitStatusTransition(inverterData, timestamp);
715
720
  }
721
+ else {
722
+ this.interruptOperatingFaultRun();
723
+ }
716
724
  this.consecutiveReconnectFailures = 0;
717
725
  if (this.applianceId) {
718
726
  const appliance = await this.applianceManager.findApplianceById(this.applianceId);
@@ -866,6 +874,34 @@ export class SunspecInverter extends BaseSunspecDevice {
866
874
  }
867
875
  };
868
876
  }
877
+ /**
878
+ * How long operatingState=7 (FAULT) must be reported without interruption
879
+ * before the inverter is reported Faulted, in ms. undefined (the default)
880
+ * keeps the poll-count debounce of OPERATING_FAULT_THRESHOLD consecutive
881
+ * FAULT reads. Override for vendors that report short FAULT phases without
882
+ * an error code while operating normally. Recovery stays immediate, and
883
+ * decoded event-register error bits are not affected.
884
+ */
885
+ getOperatingFaultGraceMs() {
886
+ return undefined;
887
+ }
888
+ interruptOperatingFaultRun() {
889
+ this.operatingFaultSinceMs = undefined;
890
+ }
891
+ isOperatingFaultSustained(operatingFaultRaw, timestamp) {
892
+ if (!operatingFaultRaw) {
893
+ this.consecutiveOperatingFaults = 0;
894
+ this.operatingFaultSinceMs = undefined;
895
+ return false;
896
+ }
897
+ this.consecutiveOperatingFaults++;
898
+ this.operatingFaultSinceMs ??= timestamp.getTime();
899
+ const graceMs = this.getOperatingFaultGraceMs();
900
+ if (graceMs === undefined) {
901
+ return this.consecutiveOperatingFaults >= SunspecInverter.OPERATING_FAULT_THRESHOLD;
902
+ }
903
+ return timestamp.getTime() - this.operatingFaultSinceMs >= graceMs;
904
+ }
869
905
  async detectAndEmitStatusTransition(data, timestamp) {
870
906
  if (!this.applianceId || !this.dataBus)
871
907
  return;
@@ -877,13 +913,13 @@ export class SunspecInverter extends BaseSunspecDevice {
877
913
  // no error bits) reports Healthy even if it was previously faulted.
878
914
  //
879
915
  // A single FAULT read is debounced: we only treat it as a fault after
880
- // OPERATING_FAULT_THRESHOLD consecutive FAULT polls, so a transient
881
- // wobble (e.g. a faulted DC-coupled battery on a string) does not
882
- // oscillate the status. Recovery is immediate — the counter resets on
883
- // the first non-fault read. Event-register error bits stay immediate.
916
+ // OPERATING_FAULT_THRESHOLD consecutive FAULT polls (or, if the subclass
917
+ // sets getOperatingFaultGraceMs(), after FAULT has persisted that long),
918
+ // so a transient wobble (e.g. a faulted DC-coupled battery on a string)
919
+ // does not oscillate the status. Recovery is immediate — the debounce
920
+ // resets on the first non-fault read. Event-register error bits stay immediate.
884
921
  const operatingFaultRaw = data.operatingState === SunspecInverterOperatingState.FAULT;
885
- this.consecutiveOperatingFaults = operatingFaultRaw ? this.consecutiveOperatingFaults + 1 : 0;
886
- const operatingFault = this.consecutiveOperatingFaults >= SunspecInverter.OPERATING_FAULT_THRESHOLD;
922
+ const operatingFault = this.isOperatingFaultSustained(operatingFaultRaw, timestamp);
887
923
  const newStatus = (codeIds.length > 0 || operatingFault)
888
924
  ? EnyoApplianceStatusEnum.Faulted
889
925
  : EnyoApplianceStatusEnum.Healthy;
@@ -923,7 +959,12 @@ export class SunspecInverter extends BaseSunspecDevice {
923
959
  getRequiredModelIds() {
924
960
  return SunspecInverter.INVERTER_MODEL_IDS;
925
961
  }
962
+ async markOffline() {
963
+ this.interruptOperatingFaultRun();
964
+ await super.markOffline();
965
+ }
926
966
  async onConnectionFailure(consecutiveFailures) {
967
+ this.interruptOperatingFaultRun();
927
968
  if (!this.applianceId || !this.dataBus)
928
969
  return;
929
970
  if (consecutiveFailures < SunspecInverter.CONNECTION_FAULT_THRESHOLD)
@@ -946,6 +987,7 @@ export class SunspecInverter extends BaseSunspecDevice {
946
987
  };
947
988
  }
948
989
  async onConnectionRestored() {
990
+ this.interruptOperatingFaultRun();
949
991
  if (!this.applianceId || !this.dataBus)
950
992
  return;
951
993
  if (this.errorState.lastStatus !== 'connection_lost')
@@ -1193,13 +1235,14 @@ export class SunspecInverter extends BaseSunspecDevice {
1193
1235
  }
1194
1236
  /**
1195
1237
  * Map MPPT data to DC string structure for data bus
1196
- * Filters out battery-related strings (StCha 3, StDisCha 4)
1238
+ * Filters out battery-related strings (StCha n, StDisCha n+1; see
1239
+ * {@link mpptStorageStringKind})
1197
1240
  */
1198
1241
  mapMPPTToStrings(mpptDataList) {
1199
1242
  const result = [];
1200
1243
  mpptDataList.forEach((mppt, index) => {
1201
1244
  // Skip battery-related strings - they will be handled separately
1202
- if (mppt.stringId === 'StCha 3' || mppt.stringId === 'StDisCha 4') {
1245
+ if (mpptStorageStringKind(mppt.stringId) !== undefined) {
1203
1246
  return;
1204
1247
  }
1205
1248
  // Only include strings with valid data
@@ -1417,7 +1460,7 @@ export function ratedDischargePowerW(batteryData) {
1417
1460
  /**
1418
1461
  * Pick the live battery power, in preference order:
1419
1462
  *
1420
- * 1. Model 160 (MPPT) `StCha 3` / `StDisCha 4` — direct DC-link reading,
1463
+ * 1. Model 160 (MPPT) `StCha n` / `StDisCha n+1` — direct DC-link reading,
1421
1464
  * passed in as the already-summed `mpptBatteryPowerW`.
1422
1465
  * 2. Model 802 `w` (offset 47) — surfaced as `chargePower` / `dischargePower`
1423
1466
  * by the Model 802 path of `SunspecModbusClient.readBatteryData`.
@@ -1431,11 +1474,33 @@ export function ratedDischargePowerW(batteryData) {
1431
1474
  * Exported as a free function so the preference logic can be unit-tested
1432
1475
  * without the full `SunspecBattery` scaffold.
1433
1476
  */
1477
+ /**
1478
+ * Classify a Model 160 module by its `IDStr` as a DC-coupled battery string.
1479
+ *
1480
+ * Fronius hybrids list the battery as two extra Model 160 modules after the PV
1481
+ * MPPTs: `StCha <n>` (charge power) and `StDisCha <n+1>` (discharge power). The
1482
+ * number is the module position, so it depends on how many PV trackers the
1483
+ * device has: a GEN24 Plus (2 MPPTs) reports `StCha 3` / `StDisCha 4`, a
1484
+ * Verto (3 MPPTs) `StCha 4` / `StDisCha 5`. Match the prefix, never the full
1485
+ * label, or a battery module is counted as a PV string.
1486
+ *
1487
+ * Returns `undefined` for a PV string.
1488
+ */
1489
+ export function mpptStorageStringKind(stringId) {
1490
+ const id = stringId?.trim() ?? '';
1491
+ if (/^StCha\b/i.test(id)) {
1492
+ return 'charge';
1493
+ }
1494
+ if (/^StDisCha\b/i.test(id)) {
1495
+ return 'discharge';
1496
+ }
1497
+ return undefined;
1498
+ }
1434
1499
  /**
1435
1500
  * Sum battery charge/discharge power from Model 160 MPPT strings.
1436
1501
  *
1437
- * - `StCha 3` → charging power (added, positive)
1438
- * - `StDisCha 4` → discharging power (subtracted)
1502
+ * - `StCha n` → charging power (added, positive)
1503
+ * - `StDisCha n+1` → discharging power (subtracted)
1439
1504
  *
1440
1505
  * The result follows the battery-power sign convention used across this file:
1441
1506
  * positive = charging, negative = discharging. Returns `undefined` when neither
@@ -1447,10 +1512,11 @@ export function ratedDischargePowerW(batteryData) {
1447
1512
  export function sumMpptBatteryPowerW(mpptDataList) {
1448
1513
  let batteryPowerW;
1449
1514
  for (const mppt of mpptDataList) {
1450
- if (mppt.stringId === 'StCha 3' && mppt.dcPower !== undefined) {
1515
+ const kind = mpptStorageStringKind(mppt.stringId);
1516
+ if (kind === 'charge' && mppt.dcPower !== undefined) {
1451
1517
  batteryPowerW = (batteryPowerW ?? 0) + mppt.dcPower;
1452
1518
  }
1453
- else if (mppt.stringId === 'StDisCha 4' && mppt.dcPower !== undefined) {
1519
+ else if (kind === 'discharge' && mppt.dcPower !== undefined) {
1454
1520
  batteryPowerW = (batteryPowerW ?? 0) - mppt.dcPower;
1455
1521
  }
1456
1522
  }
@@ -1961,8 +2027,8 @@ export class SunspecBattery extends BaseSunspecDevice {
1961
2027
  }
1962
2028
  /**
1963
2029
  * Extract battery power from MPPT strings with specific IDs
1964
- * StCha 3: Battery charging power (positive)
1965
- * StDisCha 4: Battery discharging power (negative)
2030
+ * StCha n: Battery charging power (positive)
2031
+ * StDisCha n+1: Battery discharging power (negative)
1966
2032
  */
1967
2033
  extractBatteryPowerFromMPPT(mpptDataList) {
1968
2034
  return sumMpptBatteryPowerW(mpptDataList);
@@ -1974,10 +2040,11 @@ export class SunspecBattery extends BaseSunspecDevice {
1974
2040
  let hasCharge = false;
1975
2041
  let hasDischarge = false;
1976
2042
  mpptDataList.forEach((mppt) => {
1977
- if (mppt.stringId === 'StCha 3' && mppt.dcPower !== undefined && mppt.dcPower > 0) {
2043
+ const kind = mpptStorageStringKind(mppt.stringId);
2044
+ if (kind === 'charge' && mppt.dcPower !== undefined && mppt.dcPower > 0) {
1978
2045
  hasCharge = true;
1979
2046
  }
1980
- else if (mppt.stringId === 'StDisCha 4' && mppt.dcPower !== undefined && mppt.dcPower > 0) {
2047
+ else if (kind === 'discharge' && mppt.dcPower !== undefined && mppt.dcPower > 0) {
1981
2048
  hasDischarge = true;
1982
2049
  }
1983
2050
  });
@@ -892,7 +892,7 @@ export declare enum SunspecPvPowerSource {
892
892
  * consumer can see which telemetry produced the number.
893
893
  *
894
894
  * - `MpptStrings`: summed per-string DC power from Model 160 (battery strings
895
- * `StCha 3` / `StDisCha 4` excluded). Already pure PV — never battery-adjusted.
895
+ * `StCha n` / `StDisCha n+1` excluded). Already pure PV — never battery-adjusted.
896
896
  * - `InverterDc`: the inverter's total DC power (Model 101 `DCW`). Pure PV — never
897
897
  * battery-adjusted.
898
898
  * - `InverterAc`: the inverter's total AC power (Model 101 `W`). On a hybrid this
@@ -932,7 +932,7 @@ export interface SunspecInverterReading {
932
932
  inverterPowerWRaw: number;
933
933
  /**
934
934
  * Summed per-string MPPT DC power (W) from Model 160 (battery strings
935
- * `StCha 3` / `StDisCha 4` excluded), clamped to ≥ 0. Always computed and
935
+ * `StCha n` / `StDisCha n+1` excluded), clamped to ≥ 0. Always computed and
936
936
  * reported independently of `powerOrigin` — `0` when no PV strings are readable.
937
937
  */
938
938
  inverterPowerWDcStrings: number;
@@ -329,7 +329,7 @@ export var SunspecPvPowerSource;
329
329
  * consumer can see which telemetry produced the number.
330
330
  *
331
331
  * - `MpptStrings`: summed per-string DC power from Model 160 (battery strings
332
- * `StCha 3` / `StDisCha 4` excluded). Already pure PV — never battery-adjusted.
332
+ * `StCha n` / `StDisCha n+1` excluded). Already pure PV — never battery-adjusted.
333
333
  * - `InverterDc`: the inverter's total DC power (Model 101 `DCW`). Pure PV — never
334
334
  * battery-adjusted.
335
335
  * - `InverterAc`: the inverter's total AC power (Model 101 `W`). On a hybrid this
@@ -2485,7 +2485,7 @@ export class SunspecModbusClient {
2485
2485
  // a live measurement — and produces e.g. 5000 W of "charging"
2486
2486
  // for an idle battery with inWRte = 100 % and a 5 kW nameplate.
2487
2487
  // Live battery power must come from a real source: Model 160
2488
- // StCha 3 / StDisCha 4 (see SunspecBattery.extractBatteryPower
2488
+ // StCha n / StDisCha n+1 (see SunspecBattery.extractBatteryPower
2489
2489
  // FromMPPT) or Model 802 `w` at offset 47 (the Model 802 branch
2490
2490
  // of this method, just below). Model-124-only devices should
2491
2491
  // publish "no signal" rather than the commanded cap.
package/dist/version.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Current version of the enyo Energy App SDK.
7
7
  */
8
- export declare const SDK_VERSION = "1.12.0";
8
+ export declare const SDK_VERSION = "1.13.0";
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
package/dist/version.js CHANGED
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Current version of the enyo Energy App SDK.
7
7
  */
8
- export const SDK_VERSION = '1.12.0';
8
+ export const SDK_VERSION = '1.13.0';
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enyo-energy/sunspec-sdk",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "enyo Energy Sunspec SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@enyo-energy/appliance-calibration": "0.0.3",
45
- "@enyo-energy/energy-app-sdk": "1.64.0"
45
+ "@enyo-energy/energy-app-sdk": "1.70.0"
46
46
  },
47
47
  "volta": {
48
48
  "node": "22.17.0"