@enyo-energy/sunspec-sdk 1.6.0 → 1.8.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.
@@ -4,6 +4,7 @@ exports.SunspecBatteryFeatureCalibrator = void 0;
4
4
  exports.decodeFeatureResults = decodeFeatureResults;
5
5
  const appliance_calibration_1 = require("@enyo-energy/appliance-calibration");
6
6
  const enyo_battery_appliance_js_1 = require("@enyo-energy/energy-app-sdk/dist/types/enyo-battery-appliance.js");
7
+ const sunspec_battery_grid_charge_js_1 = require("./sunspec-battery-grid-charge.cjs");
7
8
  const sunspec_interfaces_js_1 = require("./sunspec-interfaces.cjs");
8
9
  /**
9
10
  * SoC band each probe needs to operate in. Outside the band the probe returns
@@ -57,6 +58,7 @@ class SunspecBatteryFeatureCalibrator extends appliance_calibration_1.BatteryCal
57
58
  sunspecClient;
58
59
  unitId;
59
60
  readBatteryData;
61
+ gridChargeMethod;
60
62
  probeConfig;
61
63
  probeClock;
62
64
  // Local refs to the same instances the parent stores privately. We keep
@@ -71,6 +73,7 @@ class SunspecBatteryFeatureCalibrator extends appliance_calibration_1.BatteryCal
71
73
  this.sunspecClient = options.sunspecClient;
72
74
  this.unitId = options.unitId;
73
75
  this.readBatteryData = options.readBatteryData;
76
+ this.gridChargeMethod = options.gridChargeMethod ?? sunspec_interfaces_js_1.SunspecGridChargeMethod.ChargeRateLimit;
74
77
  this.probeConfig = { ...appliance_calibration_1.DEFAULT_BATTERY_CALIBRATOR_CONFIG, ...options.config };
75
78
  this.probeSnapshotService = options.snapshotService;
76
79
  this.probeResultStore = options.resultStore;
@@ -161,11 +164,10 @@ class SunspecBatteryFeatureCalibrator extends appliance_calibration_1.BatteryCal
161
164
  }
162
165
  const baselineBatW = this.sunspecDriver.readBatteryPowerW() ?? 0;
163
166
  const baselineGridW = this.sunspecDriver.readGridPowerW() ?? 0;
167
+ // wChaMax is lowered to the test power, so a 100 % rate charges at exactly testPowerW.
164
168
  const wrote = await this.sunspecClient.writeBatteryControls(this.unitId, {
165
- chaGriSet: sunspec_interfaces_js_1.SunspecChargeSource.GRID,
166
169
  wChaMax: this.probeConfig.testPowerW,
167
- inWRte: 100,
168
- storCtlMod: sunspec_interfaces_js_1.SunspecStorageControlMode.CHARGE,
170
+ ...(0, sunspec_battery_grid_charge_js_1.gridChargeControls)(this.gridChargeMethod, 100),
169
171
  });
170
172
  if (!wrote) {
171
173
  return { verdict: 'failed', note: 'writeBatteryControls returned false for grid charge' };
@@ -1,12 +1,14 @@
1
1
  import { BatteryCalibrator, type BatteryCalibratorOptions, type CalibrationResult } from "@enyo-energy/appliance-calibration";
2
2
  import { EnyoBatteryFeature } from "@enyo-energy/energy-app-sdk/dist/types/enyo-battery-appliance.js";
3
3
  import { BatteryControlsClient } from "./sunspec-battery-schedule-handler.cjs";
4
- import { type SunspecBatteryControls, type SunspecBatteryData } from "./sunspec-interfaces.cjs";
4
+ import { type SunspecBatteryControls, type SunspecBatteryData, SunspecGridChargeMethod } from "./sunspec-interfaces.cjs";
5
5
  export interface SunspecBatteryFeatureCalibratorOptions extends BatteryCalibratorOptions<SunspecBatteryControls> {
6
6
  sunspecClient: BatteryControlsClient;
7
7
  unitId: number;
8
8
  /** Pulls the latest battery data so the orchestrator can pre-check SoC. */
9
9
  readBatteryData: () => Promise<SunspecBatteryData | null>;
10
+ /** Register form the grid-charge probe tests; must match the schedule handler's. Defaults to ChargeRateLimit. */
11
+ gridChargeMethod?: SunspecGridChargeMethod;
10
12
  }
11
13
  /**
12
14
  * SunSpec-specific calibrator that exercises each of the four controllable
@@ -48,6 +50,7 @@ export declare class SunspecBatteryFeatureCalibrator extends BatteryCalibrator<S
48
50
  private readonly sunspecClient;
49
51
  private readonly unitId;
50
52
  private readonly readBatteryData;
53
+ private readonly gridChargeMethod;
51
54
  private readonly probeConfig;
52
55
  private readonly probeClock;
53
56
  private readonly probeSnapshotService;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gridChargeControls = gridChargeControls;
4
+ exports.gridChargeFields = gridChargeFields;
5
+ const sunspec_interfaces_js_1 = require("./sunspec-interfaces.cjs");
6
+ /**
7
+ * The Model 124 register set that charges the battery from the grid at `ratePct` of `WChaMax`,
8
+ * in the form the device acts on — see {@link SunspecGridChargeMethod}. Shared by the schedule
9
+ * handler and the calibrator's grid-charge probe, so the probe tests the write production uses.
10
+ */
11
+ function gridChargeControls(method, ratePct) {
12
+ switch (method) {
13
+ case sunspec_interfaces_js_1.SunspecGridChargeMethod.ChargeRateLimit:
14
+ return {
15
+ chaGriSet: sunspec_interfaces_js_1.SunspecChargeSource.GRID,
16
+ inWRte: ratePct,
17
+ storCtlMod: sunspec_interfaces_js_1.SunspecStorageControlMode.CHARGE,
18
+ };
19
+ case sunspec_interfaces_js_1.SunspecGridChargeMethod.NegativeDischargeRate:
20
+ return {
21
+ chaGriSet: sunspec_interfaces_js_1.SunspecChargeSource.GRID,
22
+ inWRte: 100,
23
+ outWRte: -ratePct,
24
+ storCtlMod: sunspec_interfaces_js_1.SunspecStorageControlMode.DISCHARGE,
25
+ };
26
+ }
27
+ }
28
+ /** The fields {@link gridChargeControls} writes, for the snapshot service's modification record. */
29
+ function gridChargeFields(controls) {
30
+ const fields = ['chaGriSet', 'inWRte', 'outWRte', 'storCtlMod'];
31
+ return fields.filter(field => controls[field] !== undefined);
32
+ }
@@ -0,0 +1,9 @@
1
+ import { type SunspecBatteryControls, SunspecGridChargeMethod } from "./sunspec-interfaces.cjs";
2
+ /**
3
+ * The Model 124 register set that charges the battery from the grid at `ratePct` of `WChaMax`,
4
+ * in the form the device acts on — see {@link SunspecGridChargeMethod}. Shared by the schedule
5
+ * handler and the calibrator's grid-charge probe, so the probe tests the write production uses.
6
+ */
7
+ export declare function gridChargeControls(method: SunspecGridChargeMethod, ratePct: number): Partial<SunspecBatteryControls>;
8
+ /** The fields {@link gridChargeControls} writes, for the snapshot service's modification record. */
9
+ export declare function gridChargeFields(controls: Partial<SunspecBatteryControls>): (keyof SunspecBatteryControls)[];
@@ -4,6 +4,7 @@ exports.SunspecBatteryScheduleHandler = void 0;
4
4
  const storage_schedule_handler_js_1 = require("@enyo-energy/energy-app-sdk/dist/implementations/storage/storage-schedule-handler.js");
5
5
  const enyo_data_bus_value_js_1 = require("@enyo-energy/energy-app-sdk/dist/types/enyo-data-bus-value.js");
6
6
  const sunspec_interfaces_js_1 = require("./sunspec-interfaces.cjs");
7
+ const sunspec_battery_grid_charge_js_1 = require("./sunspec-battery-grid-charge.cjs");
7
8
  /**
8
9
  * How often the keepalive checks whether the active limit is due a refresh.
9
10
  * The refresh itself happens every third of the revert timeout; this only
@@ -23,6 +24,7 @@ class SunspecBatteryScheduleHandler extends storage_schedule_handler_js_1.Storag
23
24
  applianceIdForLog;
24
25
  getSnapshotService;
25
26
  onErrorCallback;
27
+ gridChargeMethod;
26
28
  installedWChaMax;
27
29
  /**
28
30
  * Sticky pre-schedule snapshot, captured once on the first `onInit` and
@@ -73,6 +75,7 @@ class SunspecBatteryScheduleHandler extends storage_schedule_handler_js_1.Storag
73
75
  this.applianceIdForLog = opts.applianceId;
74
76
  this.getSnapshotService = opts.getSnapshotService;
75
77
  this.onErrorCallback = opts.onErrorCallback;
78
+ this.gridChargeMethod = opts.gridChargeMethod ?? sunspec_interfaces_js_1.SunspecGridChargeMethod.ChargeRateLimit;
76
79
  this.interval = opts.interval;
77
80
  this.clock = opts.now ?? (() => Date.now());
78
81
  }
@@ -295,12 +298,9 @@ class SunspecBatteryScheduleHandler extends storage_schedule_handler_js_1.Storag
295
298
  }
296
299
  const pct = Math.min(100, Math.max(0, (powerW / baseline) * 100));
297
300
  if (direction === enyo_data_bus_value_js_1.EnyoStorageScheduleDirectionEnum.Charge) {
298
- await this.sunspecClient.writeBatteryControls(this.unitId, {
299
- chaGriSet: sunspec_interfaces_js_1.SunspecChargeSource.GRID,
300
- inWRte: pct,
301
- storCtlMod: sunspec_interfaces_js_1.SunspecStorageControlMode.CHARGE,
302
- });
303
- await this.getSnapshotService()?.recordModification(['chaGriSet', 'inWRte', 'storCtlMod']);
301
+ const controls = (0, sunspec_battery_grid_charge_js_1.gridChargeControls)(this.gridChargeMethod, pct);
302
+ await this.sunspecClient.writeBatteryControls(this.unitId, controls);
303
+ await this.getSnapshotService()?.recordModification((0, sunspec_battery_grid_charge_js_1.gridChargeFields)(controls));
304
304
  }
305
305
  else {
306
306
  await this.sunspecClient.writeBatteryControls(this.unitId, {
@@ -1,7 +1,7 @@
1
1
  import { StorageScheduleHandler, type ActiveStorageScheduleEntry, type StorageScheduleHandlerOptions } from "@enyo-energy/energy-app-sdk/dist/implementations/storage/storage-schedule-handler.js";
2
2
  import { type EnyoDataBusSetStorageScheduleV1 } from "@enyo-energy/energy-app-sdk/dist/types/enyo-data-bus-value.js";
3
3
  import { type SnapshotService } from "@enyo-energy/appliance-calibration";
4
- import { type SunspecBatteryControls } from "./sunspec-interfaces.cjs";
4
+ import { type SunspecBatteryControls, SunspecGridChargeMethod } from "./sunspec-interfaces.cjs";
5
5
  /**
6
6
  * Narrow interface covering only the modbus reads/writes the schedule handler
7
7
  * needs. The full `SunspecModbusClient` structurally satisfies this; pinning
@@ -47,6 +47,8 @@ export interface SunspecBatteryScheduleHandlerOptions extends StorageScheduleHan
47
47
  /** Lazy so the snapshot service can be initialised after the handler. */
48
48
  getSnapshotService: () => BatteryModificationRecorder | undefined;
49
49
  onErrorCallback?: (err: Error) => void;
50
+ /** Register form of a Charge entry. Defaults to {@link SunspecGridChargeMethod.ChargeRateLimit}. */
51
+ gridChargeMethod?: SunspecGridChargeMethod;
50
52
  }
51
53
  /**
52
54
  * Concrete `StorageScheduleHandler` for SunSpec Model 124 batteries. The base
@@ -61,6 +63,7 @@ export declare class SunspecBatteryScheduleHandler extends StorageScheduleHandle
61
63
  private readonly applianceIdForLog;
62
64
  private readonly getSnapshotService;
63
65
  private readonly onErrorCallback?;
66
+ private readonly gridChargeMethod;
64
67
  private installedWChaMax;
65
68
  /**
66
69
  * Sticky pre-schedule snapshot, captured once on the first `onInit` and
@@ -1518,6 +1518,14 @@ function deriveStorageMode(controls) {
1518
1518
  if (chargeLimited && dischargeLimited && controls.inWRte === 0 && controls.outWRte === 0) {
1519
1519
  return sunspec_interfaces_js_1.SunspecStorageMode.HOLDING;
1520
1520
  }
1521
+ // A limit below zero reverses its direction: a negative discharge rate is a forced charge
1522
+ // (SunspecGridChargeMethod.NegativeDischargeRate), a negative charge rate a forced discharge.
1523
+ if (dischargeLimited && controls.outWRte !== undefined && controls.outWRte < 0) {
1524
+ return sunspec_interfaces_js_1.SunspecStorageMode.CHARGE;
1525
+ }
1526
+ if (chargeLimited && controls.inWRte !== undefined && controls.inWRte < 0) {
1527
+ return sunspec_interfaces_js_1.SunspecStorageMode.DISCHARGE;
1528
+ }
1521
1529
  return dischargeLimited && !chargeLimited
1522
1530
  ? sunspec_interfaces_js_1.SunspecStorageMode.DISCHARGE
1523
1531
  : sunspec_interfaces_js_1.SunspecStorageMode.CHARGE;
@@ -1540,6 +1548,8 @@ class SunspecBattery extends BaseSunspecDevice {
1540
1548
  batteryCalibrator;
1541
1549
  calibrationResultStore;
1542
1550
  scheduleHandler;
1551
+ /** Register form of a grid charge, for both the schedule handler and the calibration probe. */
1552
+ gridChargeMethod;
1543
1553
  /**
1544
1554
  * Battery features that imply outbound control writes from the host action-taker.
1545
1555
  * These are stripped from `appliance.battery.features` until the calibration result
@@ -1553,13 +1563,14 @@ class SunspecBattery extends BaseSunspecDevice {
1553
1563
  enyo_battery_appliance_js_1.EnyoBatteryFeature.DischargeLimitation,
1554
1564
  ];
1555
1565
  constructor(energyApp, name, networkDevice, sunspecClient, applianceManager, featureMode, unitId = 1, port = 502, baseAddress = 40000, capabilities = [], retryConfig, appliance, useTls,
1556
- // Battery facts no register carries (currently the measured round-trip efficiency).
1557
- // Forwarded onto `appliance.battery` on connect; see SunspecBatteryMetadataConfig.
1558
- metadataConfig = {}) {
1566
+ // Battery facts no register carries (forwarded onto `appliance.battery` on connect;
1567
+ // see SunspecBatteryMetadataConfig) plus how the device is driven.
1568
+ config = {}) {
1559
1569
  super(energyApp, name, networkDevice, sunspecClient, applianceManager, unitId, port, baseAddress, retryConfig, appliance, useTls);
1560
1570
  this.featureMode = featureMode;
1561
1571
  this.capabilities = capabilities;
1562
- this.roundTripEfficiencyPercent = metadataConfig.roundTripEfficiencyPercent;
1572
+ this.roundTripEfficiencyPercent = config.roundTripEfficiencyPercent;
1573
+ this.gridChargeMethod = config.gridChargeMethod ?? sunspec_interfaces_js_1.SunspecGridChargeMethod.ChargeRateLimit;
1563
1574
  }
1564
1575
  /**
1565
1576
  * Last known round-trip efficiency, seeded from the constructor config and replaceable at
@@ -1606,6 +1617,19 @@ class SunspecBattery extends BaseSunspecDevice {
1606
1617
  ? {}
1607
1618
  : { roundTripEfficiencyPercent: this.roundTripEfficiencyPercent };
1608
1619
  }
1620
+ /**
1621
+ * Whether the host may charge this battery from the grid. Follows the advertised
1622
+ * `GridCharging` feature, NOT the live `chaGriSet` register: our own schedule handler
1623
+ * writes GRID on every Charge and PV on Discharge/Auto, so the register only says
1624
+ * whether we are grid-charging right now. Publishing it made the flag `false` whenever
1625
+ * the pack sat on Auto (all night), and enyo-control honours an explicit `false` by
1626
+ * planning no buys at all (ENY-1241). The value is always set, never omitted, because
1627
+ * `updateAppliance` merges `battery` and would otherwise keep a stale `false`.
1628
+ * The live register stays available through {@link isGridChargingEnabled}.
1629
+ */
1630
+ gridChargingEnabled(features) {
1631
+ return features.includes(enyo_battery_appliance_js_1.EnyoBatteryFeature.GridCharging);
1632
+ }
1609
1633
  /**
1610
1634
  * Wire the battery into `@enyo-energy/appliance-calibration`'s
1611
1635
  * `BatteryCalibrator` test-charge flow. Call once after {@link connect}.
@@ -1640,6 +1664,7 @@ class SunspecBattery extends BaseSunspecDevice {
1640
1664
  sunspecClient: this.sunspecClient,
1641
1665
  unitId: this.unitId,
1642
1666
  readBatteryData: () => this.sunspecClient.readBatteryData(this.unitId),
1667
+ gridChargeMethod: this.gridChargeMethod,
1643
1668
  snapshotService: this.snapshotService,
1644
1669
  resultStore: opts.resultStore,
1645
1670
  config: opts.config,
@@ -1701,8 +1726,8 @@ class SunspecBattery extends BaseSunspecDevice {
1701
1726
  throw new Error('No battery model found in device');
1702
1727
  }
1703
1728
  // Give every limit a revert timeout so a hub that goes offline cannot leave the
1704
- // battery blocked (devices ship with 0 = never revert). Written once here; the
1705
- // schedule handler refreshes active limits inside this window.
1729
+ // battery blocked (devices ship with 0 = never revert). Written here and re-asserted
1730
+ // by limit writes; the schedule handler refreshes active limits inside this window.
1706
1731
  await this.sunspecClient.writeBatteryRateRevertTimeout(this.unitId);
1707
1732
  // Get device info
1708
1733
  const commonData = await this.sunspecClient.readCommonBlock(this.unitId);
@@ -1734,7 +1759,7 @@ class SunspecBattery extends BaseSunspecDevice {
1734
1759
  activeChargeLimitW: activeChargeLimitW,
1735
1760
  activeDischargeLimitW: activeDischargeLimitW,
1736
1761
  features,
1737
- gridChargingEnabled: batteryData?.chaGriSet === 1,
1762
+ gridChargingEnabled: this.gridChargingEnabled(features),
1738
1763
  ...this.configuredBatteryMetadata()
1739
1764
  }
1740
1765
  });
@@ -1763,7 +1788,7 @@ class SunspecBattery extends BaseSunspecDevice {
1763
1788
  activeChargeLimitW: activeChargeLimitW,
1764
1789
  activeDischargeLimitW: activeDischargeLimitW,
1765
1790
  features,
1766
- gridChargingEnabled: batteryData?.chaGriSet === 1,
1791
+ gridChargingEnabled: this.gridChargingEnabled(features),
1767
1792
  ...this.configuredBatteryMetadata()
1768
1793
  }
1769
1794
  });
@@ -1932,7 +1957,7 @@ class SunspecBattery extends BaseSunspecDevice {
1932
1957
  activeChargeLimitW: this.computeActiveChargeLimitW(batteryData),
1933
1958
  activeDischargeLimitW: this.computeActiveDischargeLimitW(batteryData),
1934
1959
  features,
1935
- gridChargingEnabled: batteryData?.chaGriSet === 1,
1960
+ gridChargingEnabled: this.gridChargingEnabled(features),
1936
1961
  ...this.configuredBatteryMetadata()
1937
1962
  }
1938
1963
  });
@@ -2116,7 +2141,7 @@ class SunspecBattery extends BaseSunspecDevice {
2116
2141
  }
2117
2142
  if (batteryData.inWRte >= 100)
2118
2143
  return null;
2119
- return (batteryData.wChaMax * batteryData.inWRte) / 100;
2144
+ return (batteryData.wChaMax * Math.max(0, batteryData.inWRte)) / 100;
2120
2145
  }
2121
2146
  /**
2122
2147
  * Compute the currently active discharge limit in Watts from Model 124's
@@ -2129,7 +2154,8 @@ class SunspecBattery extends BaseSunspecDevice {
2129
2154
  }
2130
2155
  if (batteryData.outWRte >= 100)
2131
2156
  return null;
2132
- return (batteryData.wChaMax * batteryData.outWRte) / 100;
2157
+ // A negative rate is a forced charge, not a negative limit: nothing may be discharged.
2158
+ return (batteryData.wChaMax * Math.max(0, batteryData.outWRte)) / 100;
2133
2159
  }
2134
2160
  determineStorageMode(controls) {
2135
2161
  return deriveStorageMode(controls);
@@ -2171,6 +2197,7 @@ class SunspecBattery extends BaseSunspecDevice {
2171
2197
  sunspecClient: this.sunspecClient,
2172
2198
  unitId: this.unitId,
2173
2199
  getSnapshotService: () => this.snapshotService,
2200
+ gridChargeMethod: this.gridChargeMethod,
2174
2201
  onErrorCallback: (err) => console.warn(`Battery ${this.applianceId}: schedule handler rejected input: ${err.message}`),
2175
2202
  });
2176
2203
  console.log(`Battery ${this.applianceId}: started data bus listening (listener ${this.dataBusListenerId})`);
@@ -1,4 +1,4 @@
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";
1
+ import { type IRetryConfig, type SunspecBatteryBaseData, SunspecBatteryCapability, type SunspecBatteryControls, type SunspecBatteryData, type SunspecBatteryFeatureMode, type SunspecInverterData, SunspecInverterCapability, SunspecPvPowerSource, type SunspecInverterMetadataConfig, type SunspecBatteryConfig, 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";
@@ -557,6 +557,8 @@ export declare class SunspecBattery extends BaseSunspecDevice {
557
557
  private batteryCalibrator?;
558
558
  private calibrationResultStore?;
559
559
  private scheduleHandler;
560
+ /** Register form of a grid charge, for both the schedule handler and the calibration probe. */
561
+ private readonly gridChargeMethod;
560
562
  /**
561
563
  * Battery features that imply outbound control writes from the host action-taker.
562
564
  * These are stripped from `appliance.battery.features` until the calibration result
@@ -564,7 +566,7 @@ export declare class SunspecBattery extends BaseSunspecDevice {
564
566
  * {@link computeAdvertisedFeatures}.
565
567
  */
566
568
  private static readonly CONTROLLABLE_FEATURES;
567
- 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);
569
+ 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, config?: SunspecBatteryConfig);
568
570
  /**
569
571
  * Last known round-trip efficiency, seeded from the constructor config and replaceable at
570
572
  * runtime via {@link setRoundTripEfficiencyPercent}. Undefined = not yet known; the SDK then
@@ -587,6 +589,17 @@ export declare class SunspecBattery extends BaseSunspecDevice {
587
589
  * Spreading an explicit `undefined` would erase a value the host set elsewhere.
588
590
  */
589
591
  private configuredBatteryMetadata;
592
+ /**
593
+ * Whether the host may charge this battery from the grid. Follows the advertised
594
+ * `GridCharging` feature, NOT the live `chaGriSet` register: our own schedule handler
595
+ * writes GRID on every Charge and PV on Discharge/Auto, so the register only says
596
+ * whether we are grid-charging right now. Publishing it made the flag `false` whenever
597
+ * the pack sat on Auto (all night), and enyo-control honours an explicit `false` by
598
+ * planning no buys at all (ENY-1241). The value is always set, never omitted, because
599
+ * `updateAppliance` merges `battery` and would otherwise keep a stale `false`.
600
+ * The live register stays available through {@link isGridChargingEnabled}.
601
+ */
602
+ private gridChargingEnabled;
590
603
  /**
591
604
  * Wire the battery into `@enyo-energy/appliance-calibration`'s
592
605
  * `BatteryCalibrator` test-charge flow. Call once after {@link connect}.
@@ -3,7 +3,7 @@
3
3
  * SunSpec block interfaces with block numbers
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SUNSPEC_CONTROLLABLE_FEATURES = exports.SunspecMeterCapability = exports.SunspecBatteryFeatureModeKind = exports.SunspecBatteryCapability = exports.SunspecPvPowerOrigin = exports.SunspecPvPowerSource = exports.SunspecInverterCapability = exports.SunspecStorageMode = exports.SunspecChargeSource = exports.SunspecVArPctMode = exports.SunspecEnableControl = exports.SunspecConnectionControl = exports.MAX_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = exports.MIN_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = exports.DEFAULT_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = exports.SunspecStorageControlMode = exports.SunspecBatteryEvent1 = exports.SunspecBatteryBankState = exports.SunspecBatteryType = exports.SunspecBatteryControlMode = exports.SunspecBatteryChargeState = exports.SunspecInverterOperatingState = exports.SunspecMPPTOperatingState = exports.SUNSPEC_CONNECTION_LOST_CODE = exports.SunspecInverterEvent1 = exports.SunspecModelId = exports.DEFAULT_MODBUS_RESILIENCE_CONFIG = exports.DEFAULT_RETRY_CONFIG = void 0;
6
+ exports.SUNSPEC_CONTROLLABLE_FEATURES = exports.SunspecMeterCapability = exports.SunspecBatteryFeatureModeKind = exports.SunspecGridChargeMethod = exports.SunspecBatteryCapability = exports.SunspecPvPowerOrigin = exports.SunspecPvPowerSource = exports.SunspecInverterCapability = exports.SunspecStorageMode = exports.SunspecChargeSource = exports.SunspecVArPctMode = exports.SunspecEnableControl = exports.SunspecConnectionControl = exports.BATTERY_RATE_REVERT_REASSERT_MS = exports.MAX_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = exports.MIN_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = exports.DEFAULT_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = exports.SunspecStorageControlMode = exports.SunspecBatteryEvent1 = exports.SunspecBatteryBankState = exports.SunspecBatteryType = exports.SunspecBatteryControlMode = exports.SunspecBatteryChargeState = exports.SunspecInverterOperatingState = exports.SunspecMPPTOperatingState = exports.SUNSPEC_CONNECTION_LOST_CODE = exports.SunspecInverterEvent1 = exports.SunspecModelId = exports.DEFAULT_MODBUS_RESILIENCE_CONFIG = exports.DEFAULT_RETRY_CONFIG = void 0;
7
7
  const enyo_battery_appliance_js_1 = require("@enyo-energy/energy-app-sdk/dist/types/enyo-battery-appliance.js");
8
8
  exports.DEFAULT_RETRY_CONFIG = {
9
9
  phases: [
@@ -250,6 +250,11 @@ exports.MIN_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = 15;
250
250
  * "not implemented" marker.
251
251
  */
252
252
  exports.MAX_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = 0xFFFE;
253
+ /**
254
+ * How often a battery limit write re-asserts InOutWRte_RvrtTms. Once per connect was not enough:
255
+ * a device can come up with, or be reset to, a value that drops every limit within a second.
256
+ */
257
+ exports.BATTERY_RATE_REVERT_REASSERT_MS = 60_000;
253
258
  /**
254
259
  * Enum values for connection control
255
260
  */
@@ -348,6 +353,25 @@ var SunspecBatteryCapability;
348
353
  SunspecBatteryCapability["DischargeLimit"] = "discharge-limit";
349
354
  SunspecBatteryCapability["ChargeLimit"] = "charge-limit";
350
355
  })(SunspecBatteryCapability || (exports.SunspecBatteryCapability = SunspecBatteryCapability = {}));
356
+ /**
357
+ * How a Model 124 battery is made to charge from the grid. Vendors read the rate setpoints
358
+ * differently, so the host picks the form its hardware actually acts on.
359
+ */
360
+ var SunspecGridChargeMethod;
361
+ (function (SunspecGridChargeMethod) {
362
+ /**
363
+ * StorCtl_Mod bit 0 + InWRte = the target rate. A charge-rate *cap* on devices that treat
364
+ * InWRte as a maximum: with no PV surplus, nothing is charged. The historical default.
365
+ */
366
+ SunspecGridChargeMethod["ChargeRateLimit"] = "charge-rate-limit";
367
+ /**
368
+ * StorCtl_Mod bit 1 + a negative OutWRte (-rate %), InWRte opened to 100 %. A discharge limit
369
+ * below zero is a minimum charge rate, which forces the charge whatever the PV does. Required
370
+ * by Fronius GEN24, where the bit-0 form only caps PV charging (same writes as evcc's and the
371
+ * Home Assistant fronius_modbus integration's "charge from grid").
372
+ */
373
+ SunspecGridChargeMethod["NegativeDischargeRate"] = "negative-discharge-rate";
374
+ })(SunspecGridChargeMethod || (exports.SunspecGridChargeMethod = SunspecGridChargeMethod = {}));
351
375
  /**
352
376
  * Selects how `SunspecBattery` populates `appliance.battery.features`.
353
377
  *
@@ -555,6 +555,11 @@ export declare const MIN_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = 15;
555
555
  * "not implemented" marker.
556
556
  */
557
557
  export declare const MAX_BATTERY_RATE_REVERT_TIMEOUT_SECONDS = 65534;
558
+ /**
559
+ * How often a battery limit write re-asserts InOutWRte_RvrtTms. Once per connect was not enough:
560
+ * a device can come up with, or be reset to, a value that drops every limit within a second.
561
+ */
562
+ export declare const BATTERY_RATE_REVERT_REASSERT_MS = 60000;
558
563
  /**
559
564
  * Battery data structure based on Model 124 (Basic Storage Controls)
560
565
  *
@@ -977,6 +982,24 @@ export declare enum SunspecBatteryCapability {
977
982
  DischargeLimit = "discharge-limit",
978
983
  ChargeLimit = "charge-limit"
979
984
  }
985
+ /**
986
+ * How a Model 124 battery is made to charge from the grid. Vendors read the rate setpoints
987
+ * differently, so the host picks the form its hardware actually acts on.
988
+ */
989
+ export declare enum SunspecGridChargeMethod {
990
+ /**
991
+ * StorCtl_Mod bit 0 + InWRte = the target rate. A charge-rate *cap* on devices that treat
992
+ * InWRte as a maximum: with no PV surplus, nothing is charged. The historical default.
993
+ */
994
+ ChargeRateLimit = "charge-rate-limit",
995
+ /**
996
+ * StorCtl_Mod bit 1 + a negative OutWRte (-rate %), InWRte opened to 100 %. A discharge limit
997
+ * below zero is a minimum charge rate, which forces the charge whatever the PV does. Required
998
+ * by Fronius GEN24, where the bit-0 form only caps PV charging (same writes as evcc's and the
999
+ * Home Assistant fronius_modbus integration's "charge from grid").
1000
+ */
1001
+ NegativeDischargeRate = "negative-discharge-rate"
1002
+ }
980
1003
  /**
981
1004
  * Battery facts that live outside the SunSpec register map, published onto `appliance.battery` when
982
1005
  * the device connects. Fields left `undefined` are not written, so an existing value in the
@@ -996,6 +1019,11 @@ export interface SunspecBatteryMetadataConfig {
996
1019
  */
997
1020
  roundTripEfficiencyPercent?: number;
998
1021
  }
1022
+ /** Per-battery configuration: the published metadata plus how the device is driven. */
1023
+ export interface SunspecBatteryConfig extends SunspecBatteryMetadataConfig {
1024
+ /** Register form for a grid charge. Defaults to {@link SunspecGridChargeMethod.ChargeRateLimit}. */
1025
+ gridChargeMethod?: SunspecGridChargeMethod;
1026
+ }
999
1027
  /**
1000
1028
  * Selects how `SunspecBattery` populates `appliance.battery.features`.
1001
1029
  *