@nexgen-os/easee 0.5.1 → 0.6.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.
package/README.md CHANGED
@@ -15,11 +15,12 @@ report to Easee's cloud.
15
15
  ## What it reads
16
16
 
17
17
  ```ts
18
- import { collectEasee, easee } from '@nexgen-os/easee';
18
+ import { easee, readEasee } from '@nexgen-os/easee';
19
19
 
20
20
  const cloud = easee({ username, password }); // the secret of the connectors row
21
21
  await cloud.chargers(); // the chargers the account reaches
22
- await collectEasee(db, cloud, { organisationId, deviceId, chargerId, from, to });
22
+ const reading = await readEasee(cloud, { chargerId, from, to });
23
+ await recordCharger(db, { organisationId, deviceId }, reading); // of the charging module
23
24
  ```
24
25
 
25
26
  | Call | Endpoint | Gives |
@@ -38,8 +39,11 @@ cloud dates in.
38
39
 
39
40
  ## Sessions
40
41
 
41
- `collectEasee(db, connector, request)` writes a window on a charger
42
- described in `charging.devices` (`charger_not_described` otherwise):
42
+ `readEasee(connector, { chargerId, from, to })` reads a window of a
43
+ charger as a `ChargerReading` of `@nexgen-os/connector`; this package
44
+ reaches neither the database nor the core. `recordCharger()` of the
45
+ `charging` module writes it on a charger described in `charging.devices`
46
+ (`charger_not_described` otherwise):
43
47
 
44
48
  - each session through `charging.record()`, once per session id: source
45
49
  `station` (the cloud is the station's central system), `source_ref` the
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type CollectedSeries, type Db, type SourceRow } from '@nexgen-os/core';
1
+ import { type ChargerReading, type CollectedSeries, type SourceRow } from '@nexgen-os/connector';
2
2
  /** The subset of `fetch` the connector uses, so a test or a proxy can stand in. */
3
3
  export type HttpFetch = (url: string, init?: {
4
4
  method?: string;
@@ -103,33 +103,23 @@ export declare function seriesOfEasee(observation: number, history: unknown): Ea
103
103
  * (`stamp_invalid`).
104
104
  */
105
105
  export declare function sessionsOfEasee(sessions: unknown[]): EaseeSessions;
106
- export interface CollectedEasee {
107
- /** The sessions recorded, by id in `charging.sessions`, in the order of the cloud. */
108
- sessions: string[];
109
- /** The series of the charger written, with the readings each received. */
110
- series: {
111
- quantity: string;
112
- seriesId: string;
113
- inserted: number;
114
- }[];
106
+ export interface ReadEasee extends ChargerReading {
107
+ source_code: 'easee';
115
108
  skipped: {
116
109
  observations: EaseeReadings['skipped'];
117
110
  sessions: EaseeSessions['skipped'];
118
111
  };
119
112
  }
120
113
  /**
121
- * A window of an Easee charger written on its device described in
122
- * `charging.devices`: each session once by `charging.record()` (source
123
- * `station`, `source_ref` the charger's serial), the lifetime energy
124
- * register and the power as `measured` series of the device, source `easee`.
125
- * Refuses as `charging.record()` does (`charger_not_described`).
114
+ * A window of an Easee charger, ready for `recordCharger()` of the `charging`
115
+ * module: each session with the charger's serial as its `source_ref`, the
116
+ * lifetime energy register and the power as series of the charger, and what
117
+ * was left out.
126
118
  */
127
- export declare function collectEasee(db: Db, connector: Pick<EaseeConnector, 'observations' | 'sessions'>, request: {
128
- organisationId: string;
129
- deviceId: string;
119
+ export declare function readEasee(connector: Pick<EaseeConnector, 'observations' | 'sessions'>, window: {
130
120
  chargerId: string;
131
121
  from: string;
132
122
  to: string;
133
- }): Promise<CollectedEasee>;
123
+ }): Promise<ReadEasee>;
134
124
  /** The `sources` row this package ships (`source.json`): write it with `registerSource()`. */
135
125
  export declare const easeeSource: SourceRow;
package/dist/index.js CHANGED
@@ -15,11 +15,11 @@
15
15
  // (`GET /api/sessions/charger/{id}/sessions/{from}/{to}`), each as the
16
16
  // record `charging.record()` takes.
17
17
  //
18
- // `collectEasee()` writes a window on a charger described in
19
- // `charging.devices`: the sessions through `charging.record()` (source
20
- // `station`, the charger's serial as `source_ref`), once per session id, and
21
- // the series through `storeSeries()`; a second collection of the same window
22
- // changes nothing.
18
+ // `readEasee()` reads a window of a charger as the `ChargerReading` of
19
+ // `@nexgen-os/connector`: its sessions, the charger's serial as their
20
+ // `source_ref`, and its series. The caller writes it (`recordCharger()` of
21
+ // the `charging` module): this package reaches neither the database nor the
22
+ // core (decision 0064).
23
23
  //
24
24
  // The cloud limits how often it is asked (two lists of chargers a minute, ten
25
25
  // lists of sessions an hour): a collection asks each endpoint once per
@@ -37,7 +37,7 @@
37
37
  // from the secret the organisation's `connectors` row names, resolved by the
38
38
  // installation's vault.
39
39
  import { readFileSync } from 'node:fs';
40
- import { GestureError, storeSeries } from '@nexgen-os/core';
40
+ import { GestureError } from '@nexgen-os/connector';
41
41
  /** The observations read into series: their id in the cloud, the quantity, its kind and the unit the cloud gives. */
42
42
  export const OBSERVATIONS = {
43
43
  124: { quantity: 'consumption_energy', value_kind: 'cumulative', unit: 'KiloW-HR' },
@@ -198,27 +198,20 @@ export function sessionsOfEasee(sessions) {
198
198
  return out;
199
199
  }
200
200
  /**
201
- * A window of an Easee charger written on its device described in
202
- * `charging.devices`: each session once by `charging.record()` (source
203
- * `station`, `source_ref` the charger's serial), the lifetime energy
204
- * register and the power as `measured` series of the device, source `easee`.
205
- * Refuses as `charging.record()` does (`charger_not_described`).
201
+ * A window of an Easee charger, ready for `recordCharger()` of the `charging`
202
+ * module: each session with the charger's serial as its `source_ref`, the
203
+ * lifetime energy register and the power as series of the charger, and what
204
+ * was left out.
206
205
  */
207
- export async function collectEasee(db, connector, request) {
208
- const window = { chargerId: request.chargerId, from: request.from, to: request.to };
206
+ export async function readEasee(connector, window) {
209
207
  const sessions = await connector.sessions(window);
210
- const recorded = [];
211
- for (const s of sessions.sessions) {
212
- const r = await db.query('select charging.record($1, $2::jsonb, $3, $4) id', [request.deviceId, JSON.stringify(s), 'station', request.chargerId]);
213
- recorded.push(r.rows[0].id);
214
- }
215
208
  const readings = await connector.observations(window);
216
- const series = [];
217
- for (const s of readings.series) {
218
- const stored = await storeSeries(db, { organisationId: request.organisationId, objectKind: 'device', objectId: request.deviceId, sourceCode: 'easee', kind: 'measured' }, s);
219
- series.push({ quantity: s.quantity_code, ...stored });
220
- }
221
- return { sessions: recorded, series, skipped: { observations: readings.skipped, sessions: sessions.skipped } };
209
+ return {
210
+ source_code: 'easee',
211
+ sessions: sessions.sessions.map((record) => ({ record, source_ref: window.chargerId })),
212
+ series: readings.series,
213
+ skipped: { observations: readings.skipped, sessions: sessions.skipped },
214
+ };
222
215
  }
223
216
  /** The `sources` row this package ships (`source.json`): write it with `registerSource()`. */
224
217
  export const easeeSource = JSON.parse(readFileSync(new URL('../source.json', import.meta.url), 'utf8'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexgen-os/easee",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Easee charging stations read from their cloud as a Nexgen OS connector: the chargers of an account, their lifetime energy register and power, and their sessions, as sessions and series of the charger.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,6 +33,6 @@
33
33
  "build": "tsc -p tsconfig.build.json"
34
34
  },
35
35
  "dependencies": {
36
- "@nexgen-os/core": "^0.5.0"
36
+ "@nexgen-os/connector": "^0.6.0"
37
37
  }
38
38
  }