@enyo-energy/energy-app-sdk 0.0.186 → 0.0.187
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/README.md
CHANGED
|
@@ -724,6 +724,37 @@ const sessions = await charging.getActiveSessions();
|
|
|
724
724
|
await charging.stopCharge(sessionId);
|
|
725
725
|
```
|
|
726
726
|
|
|
727
|
+
React to charging sessions as they happen:
|
|
728
|
+
|
|
729
|
+
```typescript
|
|
730
|
+
const charge = energyApp.useCharge();
|
|
731
|
+
|
|
732
|
+
const startedId = charge.listenForChargeStarted((session) => {
|
|
733
|
+
console.log(`charging started on ${session.applianceId}`);
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
const updatedId = charge.listenForChargeUpdated((session) => {
|
|
737
|
+
const latest = session.meterValues?.at(-1);
|
|
738
|
+
console.log(`now at ${latest?.valueWh} Wh`);
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
const stoppedId = charge.listenForChargeStopped((session) => {
|
|
742
|
+
if (session.status === EnyoChargeStatus.Completed) {
|
|
743
|
+
console.log(`delivered ${session.totalEnergyKwh} kWh`);
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
// later
|
|
748
|
+
charge.removeListener(startedId);
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
The three events are disjoint: `listenForChargeUpdated` fires only for changes to a
|
|
752
|
+
*running* session (meter values, charge mode, smart-charging schedule, additional
|
|
753
|
+
transaction IDs), never for the start or the end, so a handler never sees the same
|
|
754
|
+
event twice. Check `session.status` in the stopped listener — `Completed` and
|
|
755
|
+
`Failed` both end a charge. Meter updates can arrive every few seconds, so keep
|
|
756
|
+
the update callback cheap.
|
|
757
|
+
|
|
727
758
|
#### `useChargingCard(): EnergyAppChargingCard`
|
|
728
759
|
|
|
729
760
|
Handle charging authentication:
|
|
@@ -52,4 +52,84 @@ export interface EnergyAppCharge {
|
|
|
52
52
|
* @returns Promise resolving to the configured default charge mode
|
|
53
53
|
*/
|
|
54
54
|
getDefaultChargeMode: (applianceId: string) => Promise<EnyoDefaultChargeMode>;
|
|
55
|
+
/**
|
|
56
|
+
* Listen for charging sessions that have just started.
|
|
57
|
+
*
|
|
58
|
+
* Fires once per session, when the charge is first created and enters
|
|
59
|
+
* {@link EnyoChargeStatus.Charging} — not on subsequent meter updates (use
|
|
60
|
+
* {@link listenForChargeUpdated} for those). The delivered charge carries the
|
|
61
|
+
* data known at start: `applianceId`, `transactionId`, `startTime` and
|
|
62
|
+
* `meterStartValueWh`; the totals are only meaningful once the session ends.
|
|
63
|
+
*
|
|
64
|
+
* Listeners receive sessions of every appliance the package can see — filter
|
|
65
|
+
* on {@link EnyoCharge.applianceId} when only one charger is of interest.
|
|
66
|
+
*
|
|
67
|
+
* @param listener - Callback invoked with the started charging session
|
|
68
|
+
* @returns A unique listener ID that can be used to remove the listener
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const charge = energyApp.useCharge();
|
|
73
|
+
* const listenerId = charge.listenForChargeStarted(async (session) => {
|
|
74
|
+
* console.log(`charging started on ${session.applianceId}`);
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
listenForChargeStarted: (listener: (charge: EnyoCharge) => void | Promise<void>) => string;
|
|
79
|
+
/**
|
|
80
|
+
* Listen for charging sessions that have ended.
|
|
81
|
+
*
|
|
82
|
+
* Fires once per session, when it leaves {@link EnyoChargeStatus.Charging}
|
|
83
|
+
* for a terminal status. Check {@link EnyoCharge.status} to tell a session
|
|
84
|
+
* that {@link EnyoChargeStatus.Completed completed} from one that
|
|
85
|
+
* {@link EnyoChargeStatus.Failed failed} — both end a charge, and a listener
|
|
86
|
+
* that assumes success will mis-report faulted sessions.
|
|
87
|
+
*
|
|
88
|
+
* The delivered charge is the final record, including `endTime`,
|
|
89
|
+
* `meterEndValueWh` and `totalEnergyKwh`.
|
|
90
|
+
*
|
|
91
|
+
* @param listener - Callback invoked with the ended charging session
|
|
92
|
+
* @returns A unique listener ID that can be used to remove the listener
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* charge.listenForChargeStopped(async (session) => {
|
|
97
|
+
* if (session.status === EnyoChargeStatus.Completed) {
|
|
98
|
+
* console.log(`delivered ${session.totalEnergyKwh} kWh`);
|
|
99
|
+
* }
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
listenForChargeStopped: (listener: (charge: EnyoCharge) => void | Promise<void>) => string;
|
|
104
|
+
/**
|
|
105
|
+
* Listen for changes to a running charging session.
|
|
106
|
+
*
|
|
107
|
+
* Fires whenever an active charge is modified — new meter values, a changed
|
|
108
|
+
* {@link EnyoCharge.chargeMode}, an updated smart-charging
|
|
109
|
+
* {@link EnyoCharge.schedule}, or an additional transaction ID. It does NOT
|
|
110
|
+
* fire for the start and the end of a session; those have their own
|
|
111
|
+
* listeners, so a handler registered here never sees the same event twice.
|
|
112
|
+
*
|
|
113
|
+
* Meter updates can arrive at the charger's reporting interval (often every
|
|
114
|
+
* few seconds), so keep the callback cheap and do not persist on every call.
|
|
115
|
+
*
|
|
116
|
+
* @param listener - Callback invoked with the updated charging session
|
|
117
|
+
* @returns A unique listener ID that can be used to remove the listener
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* charge.listenForChargeUpdated(async (session) => {
|
|
122
|
+
* const latest = session.meterValues?.at(-1);
|
|
123
|
+
* console.log(`now at ${latest?.valueWh} Wh`);
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
listenForChargeUpdated: (listener: (charge: EnyoCharge) => void | Promise<void>) => string;
|
|
128
|
+
/**
|
|
129
|
+
* Removes a previously registered listener.
|
|
130
|
+
*
|
|
131
|
+
* @param listenerId - The ID returned by {@link listenForChargeStarted},
|
|
132
|
+
* {@link listenForChargeStopped} or {@link listenForChargeUpdated}
|
|
133
|
+
*/
|
|
134
|
+
removeListener: (listenerId: string) => void;
|
|
55
135
|
}
|
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.187';
|
|
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
|
@@ -52,4 +52,84 @@ export interface EnergyAppCharge {
|
|
|
52
52
|
* @returns Promise resolving to the configured default charge mode
|
|
53
53
|
*/
|
|
54
54
|
getDefaultChargeMode: (applianceId: string) => Promise<EnyoDefaultChargeMode>;
|
|
55
|
+
/**
|
|
56
|
+
* Listen for charging sessions that have just started.
|
|
57
|
+
*
|
|
58
|
+
* Fires once per session, when the charge is first created and enters
|
|
59
|
+
* {@link EnyoChargeStatus.Charging} — not on subsequent meter updates (use
|
|
60
|
+
* {@link listenForChargeUpdated} for those). The delivered charge carries the
|
|
61
|
+
* data known at start: `applianceId`, `transactionId`, `startTime` and
|
|
62
|
+
* `meterStartValueWh`; the totals are only meaningful once the session ends.
|
|
63
|
+
*
|
|
64
|
+
* Listeners receive sessions of every appliance the package can see — filter
|
|
65
|
+
* on {@link EnyoCharge.applianceId} when only one charger is of interest.
|
|
66
|
+
*
|
|
67
|
+
* @param listener - Callback invoked with the started charging session
|
|
68
|
+
* @returns A unique listener ID that can be used to remove the listener
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const charge = energyApp.useCharge();
|
|
73
|
+
* const listenerId = charge.listenForChargeStarted(async (session) => {
|
|
74
|
+
* console.log(`charging started on ${session.applianceId}`);
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
listenForChargeStarted: (listener: (charge: EnyoCharge) => void | Promise<void>) => string;
|
|
79
|
+
/**
|
|
80
|
+
* Listen for charging sessions that have ended.
|
|
81
|
+
*
|
|
82
|
+
* Fires once per session, when it leaves {@link EnyoChargeStatus.Charging}
|
|
83
|
+
* for a terminal status. Check {@link EnyoCharge.status} to tell a session
|
|
84
|
+
* that {@link EnyoChargeStatus.Completed completed} from one that
|
|
85
|
+
* {@link EnyoChargeStatus.Failed failed} — both end a charge, and a listener
|
|
86
|
+
* that assumes success will mis-report faulted sessions.
|
|
87
|
+
*
|
|
88
|
+
* The delivered charge is the final record, including `endTime`,
|
|
89
|
+
* `meterEndValueWh` and `totalEnergyKwh`.
|
|
90
|
+
*
|
|
91
|
+
* @param listener - Callback invoked with the ended charging session
|
|
92
|
+
* @returns A unique listener ID that can be used to remove the listener
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* charge.listenForChargeStopped(async (session) => {
|
|
97
|
+
* if (session.status === EnyoChargeStatus.Completed) {
|
|
98
|
+
* console.log(`delivered ${session.totalEnergyKwh} kWh`);
|
|
99
|
+
* }
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
listenForChargeStopped: (listener: (charge: EnyoCharge) => void | Promise<void>) => string;
|
|
104
|
+
/**
|
|
105
|
+
* Listen for changes to a running charging session.
|
|
106
|
+
*
|
|
107
|
+
* Fires whenever an active charge is modified — new meter values, a changed
|
|
108
|
+
* {@link EnyoCharge.chargeMode}, an updated smart-charging
|
|
109
|
+
* {@link EnyoCharge.schedule}, or an additional transaction ID. It does NOT
|
|
110
|
+
* fire for the start and the end of a session; those have their own
|
|
111
|
+
* listeners, so a handler registered here never sees the same event twice.
|
|
112
|
+
*
|
|
113
|
+
* Meter updates can arrive at the charger's reporting interval (often every
|
|
114
|
+
* few seconds), so keep the callback cheap and do not persist on every call.
|
|
115
|
+
*
|
|
116
|
+
* @param listener - Callback invoked with the updated charging session
|
|
117
|
+
* @returns A unique listener ID that can be used to remove the listener
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* charge.listenForChargeUpdated(async (session) => {
|
|
122
|
+
* const latest = session.meterValues?.at(-1);
|
|
123
|
+
* console.log(`now at ${latest?.valueWh} Wh`);
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
listenForChargeUpdated: (listener: (charge: EnyoCharge) => void | Promise<void>) => string;
|
|
128
|
+
/**
|
|
129
|
+
* Removes a previously registered listener.
|
|
130
|
+
*
|
|
131
|
+
* @param listenerId - The ID returned by {@link listenForChargeStarted},
|
|
132
|
+
* {@link listenForChargeStopped} or {@link listenForChargeUpdated}
|
|
133
|
+
*/
|
|
134
|
+
removeListener: (listenerId: string) => void;
|
|
55
135
|
}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED