@enyo-energy/energy-app-sdk 0.0.92 → 0.0.93

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.
@@ -14,6 +14,42 @@ class ApplianceManager {
14
14
  listenerIds = [];
15
15
  disposed = false;
16
16
  config;
17
+ /**
18
+ * Merges partial appliance data with an existing appliance, performing a shallow merge
19
+ * on each metadata sub-object (metadata, inverter, charger, battery, heatpump, meter,
20
+ * temperatureSensor) so that only the provided keys are overwritten and existing keys
21
+ * are preserved.
22
+ * @param existing The existing appliance data
23
+ * @param update The partial update data to merge
24
+ * @returns The merged appliance data
25
+ */
26
+ mergeApplianceData(existing, update) {
27
+ return {
28
+ ...existing,
29
+ ...update,
30
+ metadata: update.metadata
31
+ ? { ...existing.metadata, ...update.metadata }
32
+ : existing.metadata,
33
+ inverter: update.inverter
34
+ ? { ...existing.inverter, ...update.inverter }
35
+ : existing.inverter,
36
+ charger: update.charger
37
+ ? { ...existing.charger, ...update.charger }
38
+ : existing.charger,
39
+ battery: update.battery
40
+ ? { ...existing.battery, ...update.battery }
41
+ : existing.battery,
42
+ heatpump: update.heatpump
43
+ ? { ...existing.heatpump, ...update.heatpump }
44
+ : existing.heatpump,
45
+ meter: update.meter
46
+ ? { ...existing.meter, ...update.meter }
47
+ : existing.meter,
48
+ temperatureSensor: update.temperatureSensor
49
+ ? { ...existing.temperatureSensor, ...update.temperatureSensor }
50
+ : existing.temperatureSensor,
51
+ };
52
+ }
17
53
  /**
18
54
  * Creates a new ApplianceManager instance.
19
55
  * @param energyApp The EnergyApp instance to use for API calls
@@ -74,8 +110,8 @@ class ApplianceManager {
74
110
  if (this.config.defaultVendorName && !metadata.vendorName) {
75
111
  metadata.vendorName = this.config.defaultVendorName;
76
112
  }
77
- // Build appliance data
78
- const applianceData = {
113
+ // Build new appliance data
114
+ const newApplianceData = {
79
115
  name: appliance.name,
80
116
  type: appliance.type,
81
117
  networkDeviceIds,
@@ -88,6 +124,14 @@ class ApplianceManager {
88
124
  inverter: appliance.inverter,
89
125
  temperatureSensor: appliance.temperatureSensor,
90
126
  };
127
+ // When updating an existing appliance, merge metadata to preserve existing keys
128
+ let applianceData = newApplianceData;
129
+ if (existingApplianceId) {
130
+ const existingAppliance = await this.energyApp.useAppliances().getById(existingApplianceId);
131
+ if (existingAppliance) {
132
+ applianceData = this.mergeApplianceData(existingAppliance, newApplianceData);
133
+ }
134
+ }
91
135
  // Save appliance
92
136
  const applianceId = await this.energyApp.useAppliances().save(applianceData, existingApplianceId);
93
137
  // Update cache
@@ -309,10 +353,7 @@ class ApplianceManager {
309
353
  try {
310
354
  const appliance = await this.energyApp.useAppliances().getById(applianceId);
311
355
  if (appliance) {
312
- const updatedAppliance = {
313
- ...appliance,
314
- ...attributes
315
- };
356
+ const updatedAppliance = this.mergeApplianceData(appliance, attributes);
316
357
  await this.energyApp.useAppliances().save(updatedAppliance, applianceId);
317
358
  // Update cache
318
359
  this.applianceCache.set(applianceId, { id: applianceId, ...updatedAppliance });
@@ -408,15 +449,11 @@ class ApplianceManager {
408
449
  try {
409
450
  const appliance = await this.energyApp.useAppliances().getById(update.applianceId);
410
451
  if (appliance) {
411
- const updatedAppliance = {
412
- ...appliance,
413
- ...update.data
414
- };
452
+ const updatedAppliance = this.mergeApplianceData(appliance, update.data);
415
453
  await this.energyApp.useAppliances().save(updatedAppliance, update.applianceId);
416
454
  succeeded.push(update.applianceId);
417
455
  // Update cache
418
- Object.assign(appliance, update.data);
419
- this.applianceCache.set(update.applianceId, appliance);
456
+ this.applianceCache.set(update.applianceId, { id: update.applianceId, ...updatedAppliance });
420
457
  }
421
458
  else {
422
459
  failed.push(update.applianceId);
@@ -67,6 +67,16 @@ export declare class ApplianceManager {
67
67
  private listenerIds;
68
68
  private disposed;
69
69
  protected config: Required<ApplianceManagerConfig>;
70
+ /**
71
+ * Merges partial appliance data with an existing appliance, performing a shallow merge
72
+ * on each metadata sub-object (metadata, inverter, charger, battery, heatpump, meter,
73
+ * temperatureSensor) so that only the provided keys are overwritten and existing keys
74
+ * are preserved.
75
+ * @param existing The existing appliance data
76
+ * @param update The partial update data to merge
77
+ * @returns The merged appliance data
78
+ */
79
+ private mergeApplianceData;
70
80
  /**
71
81
  * Creates a new ApplianceManager instance.
72
82
  * @param energyApp The EnergyApp instance to use for API calls
@@ -12,6 +12,8 @@ export declare enum EnyoBatteryFeature {
12
12
  }
13
13
  export interface EnyoBatteryApplianceMetadata {
14
14
  connectedToApplianceId?: string;
15
+ /** If the battery is connected in between dc strings, you can configure it here*/
16
+ connectedWithDcStrings?: number[];
15
17
  maxDischargePowerW?: number;
16
18
  maxChargingPowerW?: number;
17
19
  maxCapacityWh?: number;
@@ -255,7 +255,7 @@ export interface EnyoDataBusBatteryValuesUpdateV1 extends EnyoDataBusMessage {
255
255
  applianceId: string;
256
256
  data: {
257
257
  state?: EnyoBatteryStateEnum;
258
- /** Current Battery Power (in Watt). Positive = Consumption from the Battery, Negative = Feed in / charging of the battery. */
258
+ /** Current Battery Power (in Watt). Positive = charging of the battery, Negative = Consumption from the Battery. */
259
259
  batteryPowerW?: number;
260
260
  /** Battery State of Charge. Value between 0 and 100 */
261
261
  batterySoC: number;
@@ -975,9 +975,10 @@ export interface EnyoDataBusHeatpumpTemperaturesV1 extends EnyoDataBusMessage {
975
975
  }[];
976
976
  /** Buffer tank temperature */
977
977
  bufferTank?: {
978
+ index: number;
978
979
  /** Current buffer tank temperature in Celsius */
979
980
  temperatureC: number;
980
- };
981
+ }[];
981
982
  };
982
983
  }
983
984
  /**
@@ -24,6 +24,12 @@ export interface EnyoHeatpumpApplianceDomesticHotWater {
24
24
  targetTemperatureC: number;
25
25
  hysteresisK?: number;
26
26
  }
27
+ export interface EnyoHeatpumpApplianceBufferTank {
28
+ index: number;
29
+ tankSizeLiter?: number;
30
+ targetTemperatureC?: number;
31
+ hysteresisK?: number;
32
+ }
27
33
  export interface EnyoHeatpumpApplianceCompressor {
28
34
  index: number;
29
35
  }
@@ -35,6 +41,7 @@ export interface EnyoHeatpumpApplianceMetadata {
35
41
  availableFeatures: EnyoHeatpumpApplianceAvailableFeaturesEnum[];
36
42
  mode?: EnyoHeatpumpApplianceModeEnum;
37
43
  domesticHotWater?: EnyoHeatpumpApplianceDomesticHotWater[];
44
+ bufferTanks?: EnyoHeatpumpApplianceBufferTank[];
38
45
  compressors?: EnyoHeatpumpApplianceCompressor[];
39
46
  heatingCircuits?: EnyoHeatpumpApplianceHeatingCircuit[];
40
47
  }
@@ -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.92';
12
+ exports.SDK_VERSION = '0.0.93';
13
13
  /**
14
14
  * Gets the current SDK version.
15
15
  * @returns The semantic version string of the SDK
@@ -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.92";
8
+ export declare const SDK_VERSION = "0.0.93";
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
@@ -67,6 +67,16 @@ export declare class ApplianceManager {
67
67
  private listenerIds;
68
68
  private disposed;
69
69
  protected config: Required<ApplianceManagerConfig>;
70
+ /**
71
+ * Merges partial appliance data with an existing appliance, performing a shallow merge
72
+ * on each metadata sub-object (metadata, inverter, charger, battery, heatpump, meter,
73
+ * temperatureSensor) so that only the provided keys are overwritten and existing keys
74
+ * are preserved.
75
+ * @param existing The existing appliance data
76
+ * @param update The partial update data to merge
77
+ * @returns The merged appliance data
78
+ */
79
+ private mergeApplianceData;
70
80
  /**
71
81
  * Creates a new ApplianceManager instance.
72
82
  * @param energyApp The EnergyApp instance to use for API calls
@@ -11,6 +11,42 @@ export class ApplianceManager {
11
11
  listenerIds = [];
12
12
  disposed = false;
13
13
  config;
14
+ /**
15
+ * Merges partial appliance data with an existing appliance, performing a shallow merge
16
+ * on each metadata sub-object (metadata, inverter, charger, battery, heatpump, meter,
17
+ * temperatureSensor) so that only the provided keys are overwritten and existing keys
18
+ * are preserved.
19
+ * @param existing The existing appliance data
20
+ * @param update The partial update data to merge
21
+ * @returns The merged appliance data
22
+ */
23
+ mergeApplianceData(existing, update) {
24
+ return {
25
+ ...existing,
26
+ ...update,
27
+ metadata: update.metadata
28
+ ? { ...existing.metadata, ...update.metadata }
29
+ : existing.metadata,
30
+ inverter: update.inverter
31
+ ? { ...existing.inverter, ...update.inverter }
32
+ : existing.inverter,
33
+ charger: update.charger
34
+ ? { ...existing.charger, ...update.charger }
35
+ : existing.charger,
36
+ battery: update.battery
37
+ ? { ...existing.battery, ...update.battery }
38
+ : existing.battery,
39
+ heatpump: update.heatpump
40
+ ? { ...existing.heatpump, ...update.heatpump }
41
+ : existing.heatpump,
42
+ meter: update.meter
43
+ ? { ...existing.meter, ...update.meter }
44
+ : existing.meter,
45
+ temperatureSensor: update.temperatureSensor
46
+ ? { ...existing.temperatureSensor, ...update.temperatureSensor }
47
+ : existing.temperatureSensor,
48
+ };
49
+ }
14
50
  /**
15
51
  * Creates a new ApplianceManager instance.
16
52
  * @param energyApp The EnergyApp instance to use for API calls
@@ -71,8 +107,8 @@ export class ApplianceManager {
71
107
  if (this.config.defaultVendorName && !metadata.vendorName) {
72
108
  metadata.vendorName = this.config.defaultVendorName;
73
109
  }
74
- // Build appliance data
75
- const applianceData = {
110
+ // Build new appliance data
111
+ const newApplianceData = {
76
112
  name: appliance.name,
77
113
  type: appliance.type,
78
114
  networkDeviceIds,
@@ -85,6 +121,14 @@ export class ApplianceManager {
85
121
  inverter: appliance.inverter,
86
122
  temperatureSensor: appliance.temperatureSensor,
87
123
  };
124
+ // When updating an existing appliance, merge metadata to preserve existing keys
125
+ let applianceData = newApplianceData;
126
+ if (existingApplianceId) {
127
+ const existingAppliance = await this.energyApp.useAppliances().getById(existingApplianceId);
128
+ if (existingAppliance) {
129
+ applianceData = this.mergeApplianceData(existingAppliance, newApplianceData);
130
+ }
131
+ }
88
132
  // Save appliance
89
133
  const applianceId = await this.energyApp.useAppliances().save(applianceData, existingApplianceId);
90
134
  // Update cache
@@ -306,10 +350,7 @@ export class ApplianceManager {
306
350
  try {
307
351
  const appliance = await this.energyApp.useAppliances().getById(applianceId);
308
352
  if (appliance) {
309
- const updatedAppliance = {
310
- ...appliance,
311
- ...attributes
312
- };
353
+ const updatedAppliance = this.mergeApplianceData(appliance, attributes);
313
354
  await this.energyApp.useAppliances().save(updatedAppliance, applianceId);
314
355
  // Update cache
315
356
  this.applianceCache.set(applianceId, { id: applianceId, ...updatedAppliance });
@@ -405,15 +446,11 @@ export class ApplianceManager {
405
446
  try {
406
447
  const appliance = await this.energyApp.useAppliances().getById(update.applianceId);
407
448
  if (appliance) {
408
- const updatedAppliance = {
409
- ...appliance,
410
- ...update.data
411
- };
449
+ const updatedAppliance = this.mergeApplianceData(appliance, update.data);
412
450
  await this.energyApp.useAppliances().save(updatedAppliance, update.applianceId);
413
451
  succeeded.push(update.applianceId);
414
452
  // Update cache
415
- Object.assign(appliance, update.data);
416
- this.applianceCache.set(update.applianceId, appliance);
453
+ this.applianceCache.set(update.applianceId, { id: update.applianceId, ...updatedAppliance });
417
454
  }
418
455
  else {
419
456
  failed.push(update.applianceId);
@@ -12,6 +12,8 @@ export declare enum EnyoBatteryFeature {
12
12
  }
13
13
  export interface EnyoBatteryApplianceMetadata {
14
14
  connectedToApplianceId?: string;
15
+ /** If the battery is connected in between dc strings, you can configure it here*/
16
+ connectedWithDcStrings?: number[];
15
17
  maxDischargePowerW?: number;
16
18
  maxChargingPowerW?: number;
17
19
  maxCapacityWh?: number;
@@ -255,7 +255,7 @@ export interface EnyoDataBusBatteryValuesUpdateV1 extends EnyoDataBusMessage {
255
255
  applianceId: string;
256
256
  data: {
257
257
  state?: EnyoBatteryStateEnum;
258
- /** Current Battery Power (in Watt). Positive = Consumption from the Battery, Negative = Feed in / charging of the battery. */
258
+ /** Current Battery Power (in Watt). Positive = charging of the battery, Negative = Consumption from the Battery. */
259
259
  batteryPowerW?: number;
260
260
  /** Battery State of Charge. Value between 0 and 100 */
261
261
  batterySoC: number;
@@ -975,9 +975,10 @@ export interface EnyoDataBusHeatpumpTemperaturesV1 extends EnyoDataBusMessage {
975
975
  }[];
976
976
  /** Buffer tank temperature */
977
977
  bufferTank?: {
978
+ index: number;
978
979
  /** Current buffer tank temperature in Celsius */
979
980
  temperatureC: number;
980
- };
981
+ }[];
981
982
  };
982
983
  }
983
984
  /**
@@ -24,6 +24,12 @@ export interface EnyoHeatpumpApplianceDomesticHotWater {
24
24
  targetTemperatureC: number;
25
25
  hysteresisK?: number;
26
26
  }
27
+ export interface EnyoHeatpumpApplianceBufferTank {
28
+ index: number;
29
+ tankSizeLiter?: number;
30
+ targetTemperatureC?: number;
31
+ hysteresisK?: number;
32
+ }
27
33
  export interface EnyoHeatpumpApplianceCompressor {
28
34
  index: number;
29
35
  }
@@ -35,6 +41,7 @@ export interface EnyoHeatpumpApplianceMetadata {
35
41
  availableFeatures: EnyoHeatpumpApplianceAvailableFeaturesEnum[];
36
42
  mode?: EnyoHeatpumpApplianceModeEnum;
37
43
  domesticHotWater?: EnyoHeatpumpApplianceDomesticHotWater[];
44
+ bufferTanks?: EnyoHeatpumpApplianceBufferTank[];
38
45
  compressors?: EnyoHeatpumpApplianceCompressor[];
39
46
  heatingCircuits?: EnyoHeatpumpApplianceHeatingCircuit[];
40
47
  }
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.92";
8
+ export declare const SDK_VERSION = "0.0.93";
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.92';
8
+ export const SDK_VERSION = '0.0.93';
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/energy-app-sdk",
3
- "version": "0.0.92",
3
+ "version": "0.0.93",
4
4
  "description": "enyo Energy App SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",