@enyo-energy/sunspec-sdk 0.0.71 → 0.0.73

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.
Files changed (34) hide show
  1. package/README.md +302 -0
  2. package/dist/cjs/index.cjs +30 -2
  3. package/dist/cjs/index.d.cts +6 -1
  4. package/dist/cjs/sunspec-battery-calibration-driver.cjs +158 -0
  5. package/dist/cjs/sunspec-battery-calibration-driver.d.cts +63 -0
  6. package/dist/cjs/sunspec-battery-feature-calibrator.cjs +350 -0
  7. package/dist/cjs/sunspec-battery-feature-calibrator.d.cts +89 -0
  8. package/dist/cjs/sunspec-battery-schedule-handler.cjs +92 -0
  9. package/dist/cjs/sunspec-battery-schedule-handler.d.cts +67 -0
  10. package/dist/cjs/sunspec-calibration-storage.cjs +47 -0
  11. package/dist/cjs/sunspec-calibration-storage.d.cts +24 -0
  12. package/dist/cjs/sunspec-devices.cjs +305 -215
  13. package/dist/cjs/sunspec-devices.d.cts +129 -19
  14. package/dist/cjs/sunspec-interfaces.cjs +42 -1
  15. package/dist/cjs/sunspec-interfaces.d.cts +66 -0
  16. package/dist/cjs/version.cjs +1 -1
  17. package/dist/cjs/version.d.cts +1 -1
  18. package/dist/index.d.ts +6 -1
  19. package/dist/index.js +12 -1
  20. package/dist/sunspec-battery-calibration-driver.d.ts +63 -0
  21. package/dist/sunspec-battery-calibration-driver.js +154 -0
  22. package/dist/sunspec-battery-feature-calibrator.d.ts +89 -0
  23. package/dist/sunspec-battery-feature-calibrator.js +345 -0
  24. package/dist/sunspec-battery-schedule-handler.d.ts +67 -0
  25. package/dist/sunspec-battery-schedule-handler.js +88 -0
  26. package/dist/sunspec-calibration-storage.d.ts +24 -0
  27. package/dist/sunspec-calibration-storage.js +42 -0
  28. package/dist/sunspec-devices.d.ts +129 -19
  29. package/dist/sunspec-devices.js +304 -216
  30. package/dist/sunspec-interfaces.d.ts +66 -0
  31. package/dist/sunspec-interfaces.js +41 -0
  32. package/dist/version.d.ts +1 -1
  33. package/dist/version.js +1 -1
  34. package/package.json +7 -3
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * SunSpec block interfaces with block numbers
3
3
  */
4
+ import { EnyoBatteryFeature } from "@enyo-energy/energy-app-sdk/dist/types/enyo-battery-appliance.js";
4
5
  /**
5
6
  * A single phase in the tiered retry schedule
6
7
  */
@@ -616,6 +617,39 @@ export declare enum SunspecBatteryCapability {
616
617
  DischargeLimit = "discharge-limit",
617
618
  ChargeLimit = "charge-limit"
618
619
  }
620
+ /**
621
+ * Selects how `SunspecBattery` populates `appliance.battery.features`.
622
+ *
623
+ * - `Disabled`: ignore the SunSpec registers and ignore calibration. The SDK
624
+ * publishes whatever the consumer puts in `allowedFeatures` (omit or pass
625
+ * `[]` to advertise nothing). Useful when the host already knows what the
626
+ * battery can do and doesn't want the SDK to make any inference.
627
+ * - `RegisterBased`: publish whatever the device's registers expose. If
628
+ * `allowedFeatures` is set, the published list is the intersection — the
629
+ * register-detected set filtered to the allow-list. Lets the consumer hide
630
+ * features that the hardware exposes but they don't want to use.
631
+ * - `CalibrationBased`: same as `RegisterBased`, but controllable features
632
+ * (grid charging, grid discharging, charge limitation, discharge
633
+ * limitation) stay hidden until `CalibrationResultStore.isCalibrated(...)`
634
+ * returns true for this appliance. Requires `configureCalibration(...)` to
635
+ * actually run a calibration; without it the controllable features remain
636
+ * hidden forever (safe-fallback behaviour).
637
+ */
638
+ export declare enum SunspecBatteryFeatureModeKind {
639
+ Disabled = "disabled",
640
+ RegisterBased = "register-based",
641
+ CalibrationBased = "calibration-based"
642
+ }
643
+ export type SunspecBatteryFeatureMode = {
644
+ kind: SunspecBatteryFeatureModeKind.Disabled;
645
+ allowedFeatures?: EnyoBatteryFeature[];
646
+ } | {
647
+ kind: SunspecBatteryFeatureModeKind.RegisterBased;
648
+ allowedFeatures?: EnyoBatteryFeature[];
649
+ } | {
650
+ kind: SunspecBatteryFeatureModeKind.CalibrationBased;
651
+ allowedFeatures?: EnyoBatteryFeature[];
652
+ };
619
653
  export declare enum SunspecMeterCapability {
620
654
  }
621
655
  export interface SunspecBatteryControls {
@@ -626,3 +660,35 @@ export interface SunspecBatteryControls {
626
660
  outWRte?: number;
627
661
  minRsvPct?: number;
628
662
  }
663
+ /**
664
+ * The four `EnyoBatteryFeature` values that imply outbound control writes from
665
+ * the host action-taker. `SunspecBattery` calibration probes each one
666
+ * individually so `appliance.battery.features` reflects only what the device
667
+ * actually honours.
668
+ *
669
+ * Exposed as `as const` (not a plain `EnyoBatteryFeature[]`) so consumers can
670
+ * iterate the tuple with full type narrowing — see the `WRITABLE_BATTERY_FIELDS`
671
+ * pattern in `sunspec-battery-calibration-driver.ts`.
672
+ */
673
+ export declare const SUNSPEC_CONTROLLABLE_FEATURES: readonly [EnyoBatteryFeature.GridCharging, EnyoBatteryFeature.GridDischarging, EnyoBatteryFeature.ChargeLimitation, EnyoBatteryFeature.DischargeLimitation];
674
+ export type SunspecControllableFeature = typeof SUNSPEC_CONTROLLABLE_FEATURES[number];
675
+ /**
676
+ * Outcome of a single per-feature calibration probe.
677
+ *
678
+ * - `passed`: the SDK observed the expected register/meter response.
679
+ * - `failed`: the SDK wrote the registers but the response was absent or wrong.
680
+ * - `not-supported`: a precondition stopped the probe (battery SoC out of
681
+ * range, missing telemetry, register not exposed). Distinct from `failed`
682
+ * so the host can distinguish "device won't" from "we couldn't even try".
683
+ */
684
+ export type SunspecFeatureVerdict = 'passed' | 'failed' | 'not-supported';
685
+ /**
686
+ * Per-feature outcomes captured during one calibration session. Serialised
687
+ * into `CalibrationResult.notes` as JSON; decoded with runtime guards by
688
+ * `decodeFeatureResults` (no `as` casts at the use site).
689
+ */
690
+ export interface SunspecCalibrationFeatureResults {
691
+ featureResults: Partial<Record<SunspecControllableFeature, SunspecFeatureVerdict>>;
692
+ /** Free-form per-probe diagnostics (SoC at start, observed deltas, timeouts). */
693
+ diagnostics?: Partial<Record<SunspecControllableFeature, string>>;
694
+ }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * SunSpec block interfaces with block numbers
3
3
  */
4
+ import { EnyoBatteryFeature } from "@enyo-energy/energy-app-sdk/dist/types/enyo-battery-appliance.js";
4
5
  export const DEFAULT_RETRY_CONFIG = {
5
6
  phases: [
6
7
  { intervalMs: 10_000, durationMs: 60_000 }, // Phase 1: every 10s for 1 minute
@@ -254,6 +255,46 @@ export var SunspecBatteryCapability;
254
255
  SunspecBatteryCapability["DischargeLimit"] = "discharge-limit";
255
256
  SunspecBatteryCapability["ChargeLimit"] = "charge-limit";
256
257
  })(SunspecBatteryCapability || (SunspecBatteryCapability = {}));
258
+ /**
259
+ * Selects how `SunspecBattery` populates `appliance.battery.features`.
260
+ *
261
+ * - `Disabled`: ignore the SunSpec registers and ignore calibration. The SDK
262
+ * publishes whatever the consumer puts in `allowedFeatures` (omit or pass
263
+ * `[]` to advertise nothing). Useful when the host already knows what the
264
+ * battery can do and doesn't want the SDK to make any inference.
265
+ * - `RegisterBased`: publish whatever the device's registers expose. If
266
+ * `allowedFeatures` is set, the published list is the intersection — the
267
+ * register-detected set filtered to the allow-list. Lets the consumer hide
268
+ * features that the hardware exposes but they don't want to use.
269
+ * - `CalibrationBased`: same as `RegisterBased`, but controllable features
270
+ * (grid charging, grid discharging, charge limitation, discharge
271
+ * limitation) stay hidden until `CalibrationResultStore.isCalibrated(...)`
272
+ * returns true for this appliance. Requires `configureCalibration(...)` to
273
+ * actually run a calibration; without it the controllable features remain
274
+ * hidden forever (safe-fallback behaviour).
275
+ */
276
+ export var SunspecBatteryFeatureModeKind;
277
+ (function (SunspecBatteryFeatureModeKind) {
278
+ SunspecBatteryFeatureModeKind["Disabled"] = "disabled";
279
+ SunspecBatteryFeatureModeKind["RegisterBased"] = "register-based";
280
+ SunspecBatteryFeatureModeKind["CalibrationBased"] = "calibration-based";
281
+ })(SunspecBatteryFeatureModeKind || (SunspecBatteryFeatureModeKind = {}));
257
282
  export var SunspecMeterCapability;
258
283
  (function (SunspecMeterCapability) {
259
284
  })(SunspecMeterCapability || (SunspecMeterCapability = {}));
285
+ /**
286
+ * The four `EnyoBatteryFeature` values that imply outbound control writes from
287
+ * the host action-taker. `SunspecBattery` calibration probes each one
288
+ * individually so `appliance.battery.features` reflects only what the device
289
+ * actually honours.
290
+ *
291
+ * Exposed as `as const` (not a plain `EnyoBatteryFeature[]`) so consumers can
292
+ * iterate the tuple with full type narrowing — see the `WRITABLE_BATTERY_FIELDS`
293
+ * pattern in `sunspec-battery-calibration-driver.ts`.
294
+ */
295
+ export const SUNSPEC_CONTROLLABLE_FEATURES = [
296
+ EnyoBatteryFeature.GridCharging,
297
+ EnyoBatteryFeature.GridDischarging,
298
+ EnyoBatteryFeature.ChargeLimitation,
299
+ EnyoBatteryFeature.DischargeLimitation,
300
+ ];
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 = "0.0.71";
8
+ export declare const SDK_VERSION = "0.0.73";
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 = '0.0.71';
8
+ export const SDK_VERSION = '0.0.73';
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": "0.0.71",
3
+ "version": "0.0.73",
4
4
  "description": "enyo Energy Sunspec SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,6 +8,8 @@
8
8
  "scripts": {
9
9
  "extract-version": "node scripts/extract-version.js",
10
10
  "build": "npm run extract-version && duel",
11
+ "test": "vitest run",
12
+ "test:watch": "vitest",
11
13
  "prepublishOnly": "npm run extract-version && npm run build"
12
14
  },
13
15
  "files": [
@@ -34,10 +36,12 @@
34
36
  "@knighted/duel": "2.1.4",
35
37
  "@types/express": "^5.0.3",
36
38
  "@types/node": "^24.0.13",
37
- "typescript": "^5.8.3"
39
+ "typescript": "^5.8.3",
40
+ "vitest": "^2.1.9"
38
41
  },
39
42
  "dependencies": {
40
- "@enyo-energy/energy-app-sdk": "^0.0.137"
43
+ "@enyo-energy/appliance-calibration": "0.0.2",
44
+ "@enyo-energy/energy-app-sdk": "0.0.143"
41
45
  },
42
46
  "volta": {
43
47
  "node": "22.17.0"