@enyo-energy/sunspec-sdk 0.0.89 → 0.0.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/sunspec-devices.cjs +5 -53
- package/dist/cjs/sunspec-devices.d.cts +0 -5
- package/dist/cjs/sunspec-interfaces.d.cts +8 -5
- package/dist/cjs/version.cjs +1 -1
- package/dist/cjs/version.d.cts +1 -1
- package/dist/sunspec-devices.d.ts +0 -5
- package/dist/sunspec-devices.js +5 -53
- package/dist/sunspec-interfaces.d.ts +8 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -351,15 +351,15 @@ class SunspecInverter extends BaseSunspecDevice {
|
|
|
351
351
|
* non-fault read).
|
|
352
352
|
*/
|
|
353
353
|
static OPERATING_FAULT_THRESHOLD = 3;
|
|
354
|
-
storage;
|
|
355
354
|
consecutiveOperatingFaults = 0;
|
|
355
|
+
// In-memory only — never persisted. See SunspecInverterErrorState.
|
|
356
356
|
errorState = { activeCodes: [], lastStatus: 'healthy' };
|
|
357
357
|
snapshotService;
|
|
358
358
|
// Whether we've emitted a status update at least once since (re)connecting.
|
|
359
|
-
//
|
|
360
|
-
// (e.g. a faulted
|
|
361
|
-
// healthy), so we force one re-assert of the current status on
|
|
362
|
-
// successful read of each session to converge the core.
|
|
359
|
+
// Our fresh in-memory errorState can diverge from what the core still shows
|
|
360
|
+
// across an SDK restart (e.g. a faulted the core persisted while our local
|
|
361
|
+
// state reads healthy), so we force one re-assert of the current status on
|
|
362
|
+
// the first successful read of each session to converge the core.
|
|
363
363
|
statusReassertedThisSession = false;
|
|
364
364
|
constructor(energyApp, name, networkDevice, sunspecClient, applianceManager, unitId = 1, port = 502, baseAddress = 40000, capabilities = [], retryConfig, appliance, useTls) {
|
|
365
365
|
super(energyApp, name, networkDevice, sunspecClient, applianceManager, unitId, port, baseAddress, retryConfig, appliance, useTls);
|
|
@@ -438,23 +438,13 @@ class SunspecInverter extends BaseSunspecDevice {
|
|
|
438
438
|
if (mpptModel) {
|
|
439
439
|
console.log(`MPPT model found for inverter ${this.networkDevice.hostname}`);
|
|
440
440
|
}
|
|
441
|
-
await this.loadErrorState();
|
|
442
441
|
// Fresh session: force the next successful read to re-assert the true
|
|
443
442
|
// status so a stale faulted in the core is cleared on (re)start.
|
|
444
443
|
this.statusReassertedThisSession = false;
|
|
445
444
|
this.startDataBusListening();
|
|
446
|
-
// Cold-start recovery: if the persisted state says we were stuck in
|
|
447
|
-
// connection_lost but connect() just succeeded (we read commonBlock,
|
|
448
|
-
// settings, controls and MPPT above), the Modbus path is provably
|
|
449
|
-
// healthy. Clear the stale fault and emit Healthy via the same hook
|
|
450
|
-
// the in-process reconnect path uses.
|
|
451
|
-
if (this.errorState.lastStatus === 'connection_lost') {
|
|
452
|
-
await this.onConnectionRestored();
|
|
453
|
-
}
|
|
454
445
|
}
|
|
455
446
|
async disconnect() {
|
|
456
447
|
this.stopDataBusListening();
|
|
457
|
-
await this.removePersistedErrorState();
|
|
458
448
|
if (this.applianceId) {
|
|
459
449
|
try {
|
|
460
450
|
await this.applianceManager.updateApplianceState(this.applianceId, enyo_appliance_js_1.EnyoApplianceConnectionType.Connector, enyo_appliance_js_1.EnyoApplianceStateEnum.Offline);
|
|
@@ -621,41 +611,6 @@ class SunspecInverter extends BaseSunspecDevice {
|
|
|
621
611
|
}
|
|
622
612
|
};
|
|
623
613
|
}
|
|
624
|
-
storageKey() {
|
|
625
|
-
return `sunspec-inverter-error-state-${this.applianceId}`;
|
|
626
|
-
}
|
|
627
|
-
async loadErrorState() {
|
|
628
|
-
try {
|
|
629
|
-
this.storage = this.energyApp.useStorage();
|
|
630
|
-
const loaded = await this.storage.load(this.storageKey());
|
|
631
|
-
if (loaded) {
|
|
632
|
-
this.errorState = loaded;
|
|
633
|
-
console.log(`Inverter ${this.applianceId}: loaded persisted error state (lastStatus=${loaded.lastStatus}, codes=[${loaded.activeCodes.join(', ')}])`);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
catch (error) {
|
|
637
|
-
console.error(`Inverter ${this.applianceId}: failed to load persisted error state: ${error}`);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
async persistErrorState() {
|
|
641
|
-
if (!this.storage)
|
|
642
|
-
return;
|
|
643
|
-
try {
|
|
644
|
-
await this.storage.save(this.storageKey(), this.errorState);
|
|
645
|
-
}
|
|
646
|
-
catch (error) {
|
|
647
|
-
console.error(`Inverter ${this.applianceId}: failed to persist error state: ${error}`);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
async removePersistedErrorState() {
|
|
651
|
-
const storage = this.storage ?? this.energyApp.useStorage();
|
|
652
|
-
try {
|
|
653
|
-
await storage.remove(this.storageKey());
|
|
654
|
-
}
|
|
655
|
-
catch (error) {
|
|
656
|
-
console.error(`Inverter ${this.applianceId}: failed to remove persisted error state: ${error}`);
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
614
|
async detectAndEmitStatusTransition(data, timestamp) {
|
|
660
615
|
if (!this.applianceId || !this.dataBus)
|
|
661
616
|
return;
|
|
@@ -702,7 +657,6 @@ class SunspecInverter extends BaseSunspecDevice {
|
|
|
702
657
|
activeCodes: codeIds,
|
|
703
658
|
lastStatus: newLastStatus,
|
|
704
659
|
};
|
|
705
|
-
await this.persistErrorState();
|
|
706
660
|
}
|
|
707
661
|
async onConnectionFailure(consecutiveFailures) {
|
|
708
662
|
if (!this.applianceId || !this.dataBus)
|
|
@@ -725,7 +679,6 @@ class SunspecInverter extends BaseSunspecDevice {
|
|
|
725
679
|
activeCodes: [sunspec_interfaces_js_1.SUNSPEC_CONNECTION_LOST_CODE],
|
|
726
680
|
lastStatus: 'connection_lost',
|
|
727
681
|
};
|
|
728
|
-
await this.persistErrorState();
|
|
729
682
|
}
|
|
730
683
|
async onConnectionRestored() {
|
|
731
684
|
if (!this.applianceId || !this.dataBus)
|
|
@@ -739,7 +692,6 @@ class SunspecInverter extends BaseSunspecDevice {
|
|
|
739
692
|
activeCodes: [],
|
|
740
693
|
lastStatus: 'healthy',
|
|
741
694
|
};
|
|
742
|
-
await this.persistErrorState();
|
|
743
695
|
}
|
|
744
696
|
/**
|
|
745
697
|
* Compute the currently active feed-in / production limit in Watts from the
|
|
@@ -137,7 +137,6 @@ export declare class SunspecInverter extends BaseSunspecDevice {
|
|
|
137
137
|
* non-fault read).
|
|
138
138
|
*/
|
|
139
139
|
private static readonly OPERATING_FAULT_THRESHOLD;
|
|
140
|
-
private storage?;
|
|
141
140
|
private consecutiveOperatingFaults;
|
|
142
141
|
private errorState;
|
|
143
142
|
private snapshotService?;
|
|
@@ -179,10 +178,6 @@ export declare class SunspecInverter extends BaseSunspecDevice {
|
|
|
179
178
|
protected mapVendorEventBit(_registerIndex: 1 | 2 | 3 | 4, _bit: number): EnyoApplianceErrorCode | undefined;
|
|
180
179
|
private hasErrorSetChanged;
|
|
181
180
|
private buildStatusMessage;
|
|
182
|
-
private storageKey;
|
|
183
|
-
private loadErrorState;
|
|
184
|
-
private persistErrorState;
|
|
185
|
-
private removePersistedErrorState;
|
|
186
181
|
private detectAndEmitStatusTransition;
|
|
187
182
|
protected onConnectionFailure(consecutiveFailures: number): Promise<void>;
|
|
188
183
|
protected onConnectionRestored(): Promise<void>;
|
|
@@ -148,11 +148,14 @@ export declare enum SunspecInverterEvent1 {
|
|
|
148
148
|
*/
|
|
149
149
|
export declare const SUNSPEC_CONNECTION_LOST_CODE = "modbus_connection_lost";
|
|
150
150
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* re-emitting `faulted` for the same
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
* In-memory error/status-tracking state for a SunSpec inverter. Held only for
|
|
152
|
+
* the lifetime of the process (never written to storage) so the status reporter
|
|
153
|
+
* can detect transitions and avoid re-emitting `faulted` for the same
|
|
154
|
+
* already-known errors on every poll. Because it is not persisted, a transient
|
|
155
|
+
* error clears the moment the next read no longer sees it, and a restart never
|
|
156
|
+
* resurrects a stale fault.
|
|
157
|
+
*/
|
|
158
|
+
export interface SunspecInverterErrorState {
|
|
156
159
|
evt1?: number;
|
|
157
160
|
evt2?: number;
|
|
158
161
|
evtVnd1?: number;
|
package/dist/cjs/version.cjs
CHANGED
|
@@ -9,7 +9,7 @@ exports.getSdkVersion = getSdkVersion;
|
|
|
9
9
|
/**
|
|
10
10
|
* Current version of the enyo Energy App SDK.
|
|
11
11
|
*/
|
|
12
|
-
exports.SDK_VERSION = '0.0.
|
|
12
|
+
exports.SDK_VERSION = '0.0.90';
|
|
13
13
|
/**
|
|
14
14
|
* Gets the current SDK version.
|
|
15
15
|
* @returns The semantic version string of the SDK
|
package/dist/cjs/version.d.cts
CHANGED
|
@@ -137,7 +137,6 @@ export declare class SunspecInverter extends BaseSunspecDevice {
|
|
|
137
137
|
* non-fault read).
|
|
138
138
|
*/
|
|
139
139
|
private static readonly OPERATING_FAULT_THRESHOLD;
|
|
140
|
-
private storage?;
|
|
141
140
|
private consecutiveOperatingFaults;
|
|
142
141
|
private errorState;
|
|
143
142
|
private snapshotService?;
|
|
@@ -179,10 +178,6 @@ export declare class SunspecInverter extends BaseSunspecDevice {
|
|
|
179
178
|
protected mapVendorEventBit(_registerIndex: 1 | 2 | 3 | 4, _bit: number): EnyoApplianceErrorCode | undefined;
|
|
180
179
|
private hasErrorSetChanged;
|
|
181
180
|
private buildStatusMessage;
|
|
182
|
-
private storageKey;
|
|
183
|
-
private loadErrorState;
|
|
184
|
-
private persistErrorState;
|
|
185
|
-
private removePersistedErrorState;
|
|
186
181
|
private detectAndEmitStatusTransition;
|
|
187
182
|
protected onConnectionFailure(consecutiveFailures: number): Promise<void>;
|
|
188
183
|
protected onConnectionRestored(): Promise<void>;
|
package/dist/sunspec-devices.js
CHANGED
|
@@ -344,15 +344,15 @@ export class SunspecInverter extends BaseSunspecDevice {
|
|
|
344
344
|
* non-fault read).
|
|
345
345
|
*/
|
|
346
346
|
static OPERATING_FAULT_THRESHOLD = 3;
|
|
347
|
-
storage;
|
|
348
347
|
consecutiveOperatingFaults = 0;
|
|
348
|
+
// In-memory only — never persisted. See SunspecInverterErrorState.
|
|
349
349
|
errorState = { activeCodes: [], lastStatus: 'healthy' };
|
|
350
350
|
snapshotService;
|
|
351
351
|
// Whether we've emitted a status update at least once since (re)connecting.
|
|
352
|
-
//
|
|
353
|
-
// (e.g. a faulted
|
|
354
|
-
// healthy), so we force one re-assert of the current status on
|
|
355
|
-
// successful read of each session to converge the core.
|
|
352
|
+
// Our fresh in-memory errorState can diverge from what the core still shows
|
|
353
|
+
// across an SDK restart (e.g. a faulted the core persisted while our local
|
|
354
|
+
// state reads healthy), so we force one re-assert of the current status on
|
|
355
|
+
// the first successful read of each session to converge the core.
|
|
356
356
|
statusReassertedThisSession = false;
|
|
357
357
|
constructor(energyApp, name, networkDevice, sunspecClient, applianceManager, unitId = 1, port = 502, baseAddress = 40000, capabilities = [], retryConfig, appliance, useTls) {
|
|
358
358
|
super(energyApp, name, networkDevice, sunspecClient, applianceManager, unitId, port, baseAddress, retryConfig, appliance, useTls);
|
|
@@ -431,23 +431,13 @@ export class SunspecInverter extends BaseSunspecDevice {
|
|
|
431
431
|
if (mpptModel) {
|
|
432
432
|
console.log(`MPPT model found for inverter ${this.networkDevice.hostname}`);
|
|
433
433
|
}
|
|
434
|
-
await this.loadErrorState();
|
|
435
434
|
// Fresh session: force the next successful read to re-assert the true
|
|
436
435
|
// status so a stale faulted in the core is cleared on (re)start.
|
|
437
436
|
this.statusReassertedThisSession = false;
|
|
438
437
|
this.startDataBusListening();
|
|
439
|
-
// Cold-start recovery: if the persisted state says we were stuck in
|
|
440
|
-
// connection_lost but connect() just succeeded (we read commonBlock,
|
|
441
|
-
// settings, controls and MPPT above), the Modbus path is provably
|
|
442
|
-
// healthy. Clear the stale fault and emit Healthy via the same hook
|
|
443
|
-
// the in-process reconnect path uses.
|
|
444
|
-
if (this.errorState.lastStatus === 'connection_lost') {
|
|
445
|
-
await this.onConnectionRestored();
|
|
446
|
-
}
|
|
447
438
|
}
|
|
448
439
|
async disconnect() {
|
|
449
440
|
this.stopDataBusListening();
|
|
450
|
-
await this.removePersistedErrorState();
|
|
451
441
|
if (this.applianceId) {
|
|
452
442
|
try {
|
|
453
443
|
await this.applianceManager.updateApplianceState(this.applianceId, EnyoApplianceConnectionType.Connector, EnyoApplianceStateEnum.Offline);
|
|
@@ -614,41 +604,6 @@ export class SunspecInverter extends BaseSunspecDevice {
|
|
|
614
604
|
}
|
|
615
605
|
};
|
|
616
606
|
}
|
|
617
|
-
storageKey() {
|
|
618
|
-
return `sunspec-inverter-error-state-${this.applianceId}`;
|
|
619
|
-
}
|
|
620
|
-
async loadErrorState() {
|
|
621
|
-
try {
|
|
622
|
-
this.storage = this.energyApp.useStorage();
|
|
623
|
-
const loaded = await this.storage.load(this.storageKey());
|
|
624
|
-
if (loaded) {
|
|
625
|
-
this.errorState = loaded;
|
|
626
|
-
console.log(`Inverter ${this.applianceId}: loaded persisted error state (lastStatus=${loaded.lastStatus}, codes=[${loaded.activeCodes.join(', ')}])`);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
catch (error) {
|
|
630
|
-
console.error(`Inverter ${this.applianceId}: failed to load persisted error state: ${error}`);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
async persistErrorState() {
|
|
634
|
-
if (!this.storage)
|
|
635
|
-
return;
|
|
636
|
-
try {
|
|
637
|
-
await this.storage.save(this.storageKey(), this.errorState);
|
|
638
|
-
}
|
|
639
|
-
catch (error) {
|
|
640
|
-
console.error(`Inverter ${this.applianceId}: failed to persist error state: ${error}`);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
async removePersistedErrorState() {
|
|
644
|
-
const storage = this.storage ?? this.energyApp.useStorage();
|
|
645
|
-
try {
|
|
646
|
-
await storage.remove(this.storageKey());
|
|
647
|
-
}
|
|
648
|
-
catch (error) {
|
|
649
|
-
console.error(`Inverter ${this.applianceId}: failed to remove persisted error state: ${error}`);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
607
|
async detectAndEmitStatusTransition(data, timestamp) {
|
|
653
608
|
if (!this.applianceId || !this.dataBus)
|
|
654
609
|
return;
|
|
@@ -695,7 +650,6 @@ export class SunspecInverter extends BaseSunspecDevice {
|
|
|
695
650
|
activeCodes: codeIds,
|
|
696
651
|
lastStatus: newLastStatus,
|
|
697
652
|
};
|
|
698
|
-
await this.persistErrorState();
|
|
699
653
|
}
|
|
700
654
|
async onConnectionFailure(consecutiveFailures) {
|
|
701
655
|
if (!this.applianceId || !this.dataBus)
|
|
@@ -718,7 +672,6 @@ export class SunspecInverter extends BaseSunspecDevice {
|
|
|
718
672
|
activeCodes: [SUNSPEC_CONNECTION_LOST_CODE],
|
|
719
673
|
lastStatus: 'connection_lost',
|
|
720
674
|
};
|
|
721
|
-
await this.persistErrorState();
|
|
722
675
|
}
|
|
723
676
|
async onConnectionRestored() {
|
|
724
677
|
if (!this.applianceId || !this.dataBus)
|
|
@@ -732,7 +685,6 @@ export class SunspecInverter extends BaseSunspecDevice {
|
|
|
732
685
|
activeCodes: [],
|
|
733
686
|
lastStatus: 'healthy',
|
|
734
687
|
};
|
|
735
|
-
await this.persistErrorState();
|
|
736
688
|
}
|
|
737
689
|
/**
|
|
738
690
|
* Compute the currently active feed-in / production limit in Watts from the
|
|
@@ -148,11 +148,14 @@ export declare enum SunspecInverterEvent1 {
|
|
|
148
148
|
*/
|
|
149
149
|
export declare const SUNSPEC_CONNECTION_LOST_CODE = "modbus_connection_lost";
|
|
150
150
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* re-emitting `faulted` for the same
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
* In-memory error/status-tracking state for a SunSpec inverter. Held only for
|
|
152
|
+
* the lifetime of the process (never written to storage) so the status reporter
|
|
153
|
+
* can detect transitions and avoid re-emitting `faulted` for the same
|
|
154
|
+
* already-known errors on every poll. Because it is not persisted, a transient
|
|
155
|
+
* error clears the moment the next read no longer sees it, and a restart never
|
|
156
|
+
* resurrects a stale fault.
|
|
157
|
+
*/
|
|
158
|
+
export interface SunspecInverterErrorState {
|
|
156
159
|
evt1?: number;
|
|
157
160
|
evt2?: number;
|
|
158
161
|
evtVnd1?: number;
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED