@enyo-energy/sunspec-sdk 0.0.104 → 1.0.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.
@@ -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, type SunspecCustomDeviceConfig } from "./sunspec-interfaces.cjs";
1
+ import { type IRetryConfig, type SunspecBatteryBaseData, SunspecBatteryCapability, type SunspecBatteryControls, type SunspecBatteryData, type SunspecBatteryFeatureMode, type SunspecInverterData, SunspecInverterCapability, SunspecPvPowerSource, type SunspecInverterMetadataConfig, type SunspecBatteryMetadataConfig, SunspecPvPowerOrigin, type SunspecInverterReading, type SunspecBatteryReading, SunspecMeterCapability, type SunspecMPPTData, SunspecStorageMode, type SunspecCustomDeviceConfig } from "./sunspec-interfaces.cjs";
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";
@@ -208,6 +208,7 @@ type SunspecPvPower = {
208
208
  export declare class SunspecInverter extends BaseSunspecDevice {
209
209
  private readonly capabilities;
210
210
  private readonly pvPowerSource;
211
+ private readonly metadataConfig;
211
212
  /** Emit a connection-lost faulted status after this many consecutive failed reconnect attempts. */
212
213
  private static readonly CONNECTION_FAULT_THRESHOLD;
213
214
  /**
@@ -233,7 +234,13 @@ export declare class SunspecInverter extends BaseSunspecDevice {
233
234
  private acEnergyDropStreak;
234
235
  /** Consecutive corrupt reads that confirm a genuine reset/resync (vs a transient glitch). */
235
236
  private static readonly AC_ENERGY_RESET_CONFIRM;
236
- constructor(energyApp: EnergyApp, name: EnyoApplianceName[], networkDevice: EnyoNetworkDevice, sunspecClient: SunspecModbusClient, applianceManager: ApplianceManager, unitId?: number, port?: number, baseAddress?: number, capabilities?: SunspecInverterCapability[], retryConfig?: IRetryConfig, appliance?: EnyoAppliance, useTls?: boolean, pvPowerSource?: SunspecPvPowerSource);
237
+ constructor(energyApp: EnergyApp, name: EnyoApplianceName[], networkDevice: EnyoNetworkDevice, sunspecClient: SunspecModbusClient, applianceManager: ApplianceManager, unitId?: number, port?: number, baseAddress?: number, capabilities?: SunspecInverterCapability[], retryConfig?: IRetryConfig, appliance?: EnyoAppliance, useTls?: boolean, pvPowerSource?: SunspecPvPowerSource, metadataConfig?: SunspecInverterMetadataConfig);
238
+ /**
239
+ * The consumer-supplied inverter facts, as a spreadable object that only contains the keys that
240
+ * were actually configured. Spreading `{ controlAllowed: undefined }` over an existing appliance
241
+ * would erase a value the host set elsewhere; omitting the key leaves it alone.
242
+ */
243
+ private configuredInverterMetadata;
237
244
  connect(): Promise<void>;
238
245
  disconnect(): Promise<void>;
239
246
  readData(clockId: string, resolution: EnyoDataBusMessageResolution): Promise<EnyoDataBusMessage[]>;
@@ -510,6 +517,21 @@ export declare function filterFeaturesByCalibrationResult(detected: EnyoBatteryF
510
517
  /**
511
518
  * Sunspec Battery implementation
512
519
  */
520
+ /**
521
+ * Derive the storage mode from Model 124's StorCtl_Mod bitfield.
522
+ *
523
+ * The bits mark *which rate setpoint the device is enforcing* — bit 0 for
524
+ * InWRte, bit 1 for OutWRte — not which direction is permitted. So no bit set
525
+ * is the autonomous mode, and both bits set is the most externally controlled
526
+ * state there is, which is the opposite of what the naming suggests. Reading
527
+ * them the other way round meant a battery running its own logic reported
528
+ * `holding`, a fully clamped one reported `auto`, and no appliance could ever
529
+ * report that it had been handed back to itself.
530
+ *
531
+ * @param controls - Model 124 control registers, or null when unreadable.
532
+ * @returns The mode, or null when StorCtl_Mod could not be read.
533
+ */
534
+ export declare function deriveStorageMode(controls: SunspecBatteryControls | null): SunspecStorageMode | null;
513
535
  export declare class SunspecBattery extends BaseSunspecDevice {
514
536
  private readonly featureMode;
515
537
  private readonly capabilities;
@@ -532,7 +554,29 @@ export declare class SunspecBattery extends BaseSunspecDevice {
532
554
  * {@link computeAdvertisedFeatures}.
533
555
  */
534
556
  private static readonly CONTROLLABLE_FEATURES;
535
- constructor(energyApp: EnergyApp, name: EnyoApplianceName[], networkDevice: EnyoNetworkDevice, sunspecClient: SunspecModbusClient, applianceManager: ApplianceManager, featureMode: SunspecBatteryFeatureMode, unitId?: number, port?: number, baseAddress?: number, capabilities?: SunspecBatteryCapability[], retryConfig?: IRetryConfig, appliance?: EnyoAppliance, useTls?: boolean);
557
+ constructor(energyApp: EnergyApp, name: EnyoApplianceName[], networkDevice: EnyoNetworkDevice, sunspecClient: SunspecModbusClient, applianceManager: ApplianceManager, featureMode: SunspecBatteryFeatureMode, unitId?: number, port?: number, baseAddress?: number, capabilities?: SunspecBatteryCapability[], retryConfig?: IRetryConfig, appliance?: EnyoAppliance, useTls?: boolean, metadataConfig?: SunspecBatteryMetadataConfig);
558
+ /**
559
+ * Last known round-trip efficiency, seeded from the constructor config and replaceable at
560
+ * runtime via {@link setRoundTripEfficiencyPercent}. Undefined = not yet known; the SDK then
561
+ * writes nothing, leaving whatever the appliance store already holds.
562
+ */
563
+ private roundTripEfficiencyPercent?;
564
+ /**
565
+ * Update the battery's measured round-trip efficiency (percent, 0-100) and push it to the
566
+ * appliance immediately. Meant to be called whenever the host recomputes the figure from
567
+ * completed cycles - it drifts with cell age and temperature, so a value fixed at construction
568
+ * goes stale. Pass `undefined` to stop asserting a value (the last published one stays in the
569
+ * appliance store; the SDK does not erase it).
570
+ *
571
+ * Safe to call before {@link connect}: the value is remembered and published with the rest of
572
+ * the metadata once the appliance exists.
573
+ */
574
+ setRoundTripEfficiencyPercent(percent: number | undefined): Promise<void>;
575
+ /**
576
+ * The configured battery facts as a spreadable object holding only the keys actually known.
577
+ * Spreading an explicit `undefined` would erase a value the host set elsewhere.
578
+ */
579
+ private configuredBatteryMetadata;
536
580
  /**
537
581
  * Wire the battery into `@enyo-energy/appliance-calibration`'s
538
582
  * `BatteryCalibrator` test-charge flow. Call once after {@link connect}.
@@ -216,8 +216,15 @@ var SunspecBatteryEvent1;
216
216
  */
217
217
  var SunspecStorageControlMode;
218
218
  (function (SunspecStorageControlMode) {
219
+ /**
220
+ * No bit set — no external setpoint is active and the battery runs its own
221
+ * autonomous logic. This, not `CHARGE | DISCHARGE`, is what "auto" means on
222
+ * Model 124: the bits say *which rate setpoint is being enforced*, so
223
+ * clearing them is what hands control back to the device.
224
+ */
225
+ SunspecStorageControlMode[SunspecStorageControlMode["NONE"] = 0] = "NONE";
219
226
  SunspecStorageControlMode[SunspecStorageControlMode["CHARGE"] = 1] = "CHARGE";
220
- SunspecStorageControlMode[SunspecStorageControlMode["DISCHARGE"] = 2] = "DISCHARGE"; // Bit 1 - Enable discharge mode (allow external discharge control)
227
+ SunspecStorageControlMode[SunspecStorageControlMode["DISCHARGE"] = 2] = "DISCHARGE"; // Bit 1 - the OutWRte discharge-rate setpoint is active
221
228
  // Note: Higher bits may control other modes like autonomous/self-consumption
222
229
  // but these are device-specific and not standardized in SunSpec
223
230
  })(SunspecStorageControlMode || (exports.SunspecStorageControlMode = SunspecStorageControlMode = {}));
@@ -262,7 +269,7 @@ var SunspecStorageMode;
262
269
  SunspecStorageMode["CHARGE"] = "charge";
263
270
  SunspecStorageMode["DISCHARGE"] = "discharge";
264
271
  SunspecStorageMode["HOLDING"] = "holding";
265
- SunspecStorageMode["AUTO"] = "auto"; // Both charge and discharge allowed
272
+ SunspecStorageMode["AUTO"] = "auto"; // No external setpoint active (StorCtl_Mod = 0)
266
273
  })(SunspecStorageMode || (exports.SunspecStorageMode = SunspecStorageMode = {}));
267
274
  /**
268
275
  * Battery control structure for writing to Model 124
@@ -46,6 +46,26 @@ export interface IModbusPacingConfig {
46
46
  */
47
47
  waitBetweenMessagesMs?: number;
48
48
  }
49
+ /**
50
+ * Everything the client forwards verbatim to `useModbus().connect()`: the pacing options above plus
51
+ * the transport options added in energy-app-sdk 1.6.0. Kept as a superset of
52
+ * {@link IModbusPacingConfig} so callers that already pass a pacing object keep working unchanged.
53
+ */
54
+ export interface IModbusTransportConfig extends IModbusPacingConfig {
55
+ /**
56
+ * Take the connection from the host's shared pool of sockets — keyed by host, port, unit ID and
57
+ * transport settings — instead of opening one that belongs exclusively to this client (SDK
58
+ * `ModbusOptions.pooledConnection`, available from energy-app-sdk 1.6.0). Pooling lets several
59
+ * consumers of the same physical device share one TCP connection, which matters for devices that
60
+ * accept only a handful of simultaneous Modbus clients. A pooled `disconnect()` releases the
61
+ * connection back to the pool rather than necessarily closing the socket.
62
+ *
63
+ * Note that this SDK already refcounts one client per `host:port`
64
+ * ({@link getOrCreateSunspecClient}), so pooling only adds anything when something *outside* this
65
+ * client also talks to the same device. Leave it unset to keep the SDK's own default.
66
+ */
67
+ pooledConnection?: boolean;
68
+ }
49
69
  /**
50
70
  * Resilience configuration for the Modbus client: per-operation timeouts and half-open socket
51
71
  * detection. All fields are optional and default to sensible values, so existing consumers are
@@ -503,7 +523,14 @@ export declare enum SunspecBatteryEvent1 {
503
523
  * - To ensure external control works properly, the appropriate bits must be set
504
524
  */
505
525
  export declare enum SunspecStorageControlMode {
506
- CHARGE = 1,// Bit 0 - Enable charge mode (allow external charge control)
526
+ /**
527
+ * No bit set — no external setpoint is active and the battery runs its own
528
+ * autonomous logic. This, not `CHARGE | DISCHARGE`, is what "auto" means on
529
+ * Model 124: the bits say *which rate setpoint is being enforced*, so
530
+ * clearing them is what hands control back to the device.
531
+ */
532
+ NONE = 0,
533
+ CHARGE = 1,// Bit 0 - the InWRte charge-rate setpoint is active
507
534
  DISCHARGE = 2
508
535
  }
509
536
  /**
@@ -778,9 +805,9 @@ export declare enum SunspecChargeSource {
778
805
  * Storage modes for simplified battery control
779
806
  */
780
807
  export declare enum SunspecStorageMode {
781
- CHARGE = "charge",// Allow charging only
782
- DISCHARGE = "discharge",// Allow discharging only
783
- HOLDING = "holding",// No charge or discharge (holding mode)
808
+ CHARGE = "charge",// Charging is externally rate-limited via InWRte
809
+ DISCHARGE = "discharge",// Discharging is externally rate-limited via OutWRte
810
+ HOLDING = "holding",// Both directions clamped to 0 % — battery is parked
784
811
  AUTO = "auto"
785
812
  }
786
813
  /**
@@ -795,6 +822,29 @@ export declare enum SunspecStorageMode {
795
822
  export declare enum SunspecInverterCapability {
796
823
  FeedInLimit = "feed-in-limit"
797
824
  }
825
+ /**
826
+ * Nameplate/policy facts about an inverter that live outside the SunSpec register map, published
827
+ * onto `appliance.inverter` when the device connects. Nothing here is readable from Modbus — the
828
+ * installation record (Anlagenpass) or the host's own configuration is the source of truth — so the
829
+ * SDK only forwards what the consumer supplies. Fields left `undefined` are not written, so an
830
+ * existing value in the appliance store survives a reconnect.
831
+ *
832
+ * Both fields were added to the appliance model in energy-app-sdk 1.6.0.
833
+ */
834
+ export interface SunspecInverterMetadataConfig {
835
+ /**
836
+ * Whether the energy manager may actively steer this inverter (e.g. curtail production). Omit
837
+ * to leave the decision to the consumer's configured default — `undefined` is "not configured",
838
+ * which is not the same as `false`.
839
+ */
840
+ controlAllowed?: boolean;
841
+ /**
842
+ * Peak power of the PV modules attached to this inverter, in Watt-peak. Distinct from
843
+ * `maxPvProductionW`, which the SDK reads from the inverter's own AC nameplate (Model 121
844
+ * `WMax`): the module side of the installation is not in any register.
845
+ */
846
+ installedPeakPowerWp?: number;
847
+ }
798
848
  /**
799
849
  * Where an inverter's reported PV production (pvPowerW) is sourced from.
800
850
  * - Auto: summed MPPT DC strings (Model 160) when present, else the inverter's
@@ -905,6 +955,25 @@ export declare enum SunspecBatteryCapability {
905
955
  DischargeLimit = "discharge-limit",
906
956
  ChargeLimit = "charge-limit"
907
957
  }
958
+ /**
959
+ * Battery facts that live outside the SunSpec register map, published onto `appliance.battery` when
960
+ * the device connects. Fields left `undefined` are not written, so an existing value in the
961
+ * appliance store survives a reconnect.
962
+ */
963
+ export interface SunspecBatteryMetadataConfig {
964
+ /**
965
+ * Observed AC-to-AC round-trip efficiency in percent (0–100): of the energy put into the
966
+ * battery, how much comes back out. Added to the appliance model in energy-app-sdk 1.6.0.
967
+ *
968
+ * A *measured* figure, not a datasheet one — it drifts with cell age, temperature and depth of
969
+ * discharge, and no SunSpec model reports it, so the SDK cannot derive it. Supply it from
970
+ * whatever the host computes over completed cycles, either here at construction or later via
971
+ * {@link SunspecBattery.setRoundTripEfficiencyPercent}. Leave it unset until enough cycles have
972
+ * been observed: a missing value means "not yet known", and is more useful to an optimizer than
973
+ * a nameplate number that overstates what the pack returns.
974
+ */
975
+ roundTripEfficiencyPercent?: number;
976
+ }
908
977
  /**
909
978
  * Selects how `SunspecBattery` populates `appliance.battery.features`.
910
979
  *