@enyo-energy/energy-app-sdk 0.0.39 → 0.0.41

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 (41) hide show
  1. package/dist/cjs/energy-app-permission.type.cjs +1 -0
  2. package/dist/cjs/energy-app-permission.type.d.cts +3 -2
  3. package/dist/cjs/enyo-energy-app-sdk.d.cts +3 -0
  4. package/dist/cjs/implementations/appliances/appliance-manager.cjs +52 -24
  5. package/dist/cjs/implementations/appliances/appliance-manager.d.cts +19 -14
  6. package/dist/cjs/implementations/appliances/identifier-strategies.cjs +5 -39
  7. package/dist/cjs/implementations/appliances/identifier-strategies.d.cts +6 -31
  8. package/dist/cjs/implementations/appliances/in-memory-appliance-manager.cjs +36 -25
  9. package/dist/cjs/implementations/appliances/in-memory-appliance-manager.d.cts +2 -3
  10. package/dist/cjs/implementations/modbus/EnergyAppModbusDataTypeConverter.cjs +8 -0
  11. package/dist/cjs/implementations/modbus/interfaces.d.cts +5 -1
  12. package/dist/cjs/index.cjs +9 -0
  13. package/dist/cjs/index.d.cts +8 -0
  14. package/dist/cjs/packages/energy-app-secret-manager.cjs +2 -0
  15. package/dist/cjs/packages/energy-app-secret-manager.d.cts +61 -0
  16. package/dist/cjs/types/enyo-data-bus-value.d.cts +14 -3
  17. package/dist/cjs/types/enyo-secret-manager.cjs +15 -0
  18. package/dist/cjs/types/enyo-secret-manager.d.cts +33 -0
  19. package/dist/cjs/version.cjs +1 -1
  20. package/dist/cjs/version.d.cts +1 -1
  21. package/dist/energy-app-permission.type.d.ts +3 -2
  22. package/dist/energy-app-permission.type.js +1 -0
  23. package/dist/enyo-energy-app-sdk.d.ts +3 -0
  24. package/dist/implementations/appliances/appliance-manager.d.ts +19 -14
  25. package/dist/implementations/appliances/appliance-manager.js +52 -24
  26. package/dist/implementations/appliances/identifier-strategies.d.ts +6 -31
  27. package/dist/implementations/appliances/identifier-strategies.js +4 -37
  28. package/dist/implementations/appliances/in-memory-appliance-manager.d.ts +2 -3
  29. package/dist/implementations/appliances/in-memory-appliance-manager.js +36 -25
  30. package/dist/implementations/modbus/EnergyAppModbusDataTypeConverter.js +8 -0
  31. package/dist/implementations/modbus/interfaces.d.ts +5 -1
  32. package/dist/index.d.ts +8 -0
  33. package/dist/index.js +9 -0
  34. package/dist/packages/energy-app-secret-manager.d.ts +61 -0
  35. package/dist/packages/energy-app-secret-manager.js +1 -0
  36. package/dist/types/enyo-data-bus-value.d.ts +14 -3
  37. package/dist/types/enyo-secret-manager.d.ts +33 -0
  38. package/dist/types/enyo-secret-manager.js +10 -0
  39. package/dist/version.d.ts +1 -1
  40. package/dist/version.js +1 -1
  41. package/package.json +1 -1
@@ -18,4 +18,5 @@ var EnergyAppPermissionTypeEnum;
18
18
  EnergyAppPermissionTypeEnum["ChargingCard"] = "ChargingCard";
19
19
  EnergyAppPermissionTypeEnum["Vehicle"] = "Vehicle";
20
20
  EnergyAppPermissionTypeEnum["Charge"] = "Charge";
21
+ EnergyAppPermissionTypeEnum["SecretManager"] = "SecretManager";
21
22
  })(EnergyAppPermissionTypeEnum || (exports.EnergyAppPermissionTypeEnum = EnergyAppPermissionTypeEnum = {}));
@@ -1,4 +1,4 @@
1
- export type EnergyAppPermissionType = 'RestrictedInternetAccess' | 'NetworkDeviceDiscovery' | 'NetworkDeviceSearch' | 'NetworkDeviceAccess' | 'Modbus' | 'Storage' | 'Appliance' | 'AllAppliances' | 'SendDataBusValues' | 'SubscribeDataBus' | 'SendDataBusCommands' | 'OcppServer';
1
+ export type EnergyAppPermissionType = 'RestrictedInternetAccess' | 'NetworkDeviceDiscovery' | 'NetworkDeviceSearch' | 'NetworkDeviceAccess' | 'Modbus' | 'Storage' | 'Appliance' | 'AllAppliances' | 'SendDataBusValues' | 'SubscribeDataBus' | 'SendDataBusCommands' | 'OcppServer' | 'ChargingCard' | 'Vehicle' | 'Charge' | 'SecretManager';
2
2
  export declare enum EnergyAppPermissionTypeEnum {
3
3
  RestrictedInternetAccess = "RestrictedInternetAccess",
4
4
  NetworkDeviceDiscovery = "NetworkDeviceDiscovery",
@@ -14,5 +14,6 @@ export declare enum EnergyAppPermissionTypeEnum {
14
14
  OcppServer = "OcppServer",
15
15
  ChargingCard = "ChargingCard",
16
16
  Vehicle = "Vehicle",
17
- Charge = "Charge"
17
+ Charge = "Charge",
18
+ SecretManager = "SecretManager"
18
19
  }
@@ -12,6 +12,7 @@ import { EnergyAppAuthentication } from "./packages/energy-app-authentication.cj
12
12
  import { EnergyAppSettings } from "./packages/energy-app-settings.cjs";
13
13
  import { EnergyAppElectricityPrices } from "./packages/energy-app-electricity-prices.cjs";
14
14
  import { EnergyAppNotification } from "./packages/energy-app-notification.cjs";
15
+ import { EnergyAppSecretManager } from "./packages/energy-app-secret-manager.cjs";
15
16
  export declare enum EnergyAppStateEnum {
16
17
  Launching = "launching",
17
18
  Running = "running",
@@ -64,4 +65,6 @@ export interface EnyoEnergyAppSdk {
64
65
  useElectricityPrices: () => EnergyAppElectricityPrices;
65
66
  /** Get the Notification API */
66
67
  useNotification: () => EnergyAppNotification;
68
+ /** Get the Secret Manager API */
69
+ useSecretManager: () => EnergyAppSecretManager;
67
70
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApplianceManager = void 0;
4
+ const index_js_1 = require("../../index.cjs");
4
5
  const enyo_appliance_js_1 = require("../../types/enyo-appliance.cjs");
5
- const identifier_strategies_js_1 = require("./identifier-strategies.cjs");
6
6
  /**
7
7
  * Manages appliances in the energy system with configurable identification strategies.
8
8
  * Provides comprehensive CRUD operations and state management for energy appliances.
@@ -20,62 +20,90 @@ class ApplianceManager {
20
20
  constructor(energyApp, config) {
21
21
  this.energyApp = energyApp;
22
22
  this.config = {
23
- identifierStrategy: config?.identifierStrategy ?? new identifier_strategies_js_1.NetworkDeviceIdStrategy(),
23
+ identifierStrategy: config?.identifierStrategy ?? new index_js_1.SerialNumberStrategy(),
24
24
  autoUpdateMetadata: config?.autoUpdateMetadata ?? true,
25
25
  enableLogging: config?.enableLogging ?? true,
26
26
  defaultConnectionType: config?.defaultConnectionType ?? enyo_appliance_js_1.EnyoApplianceConnectionType.Connector,
27
- defaultVendorName: config?.defaultVendorName ?? ''
27
+ defaultVendorName: config?.defaultVendorName ?? '',
28
28
  };
29
29
  }
30
+ /**
31
+ * initializes a new ApplianceManager instance with async initialization.
32
+ * This factory method handles cache initialization if configured.
33
+ * @param energyApp The EnergyApp instance to use for API calls
34
+ * @param config Configuration options for the manager
35
+ * @returns Promise that resolves to an initialized ApplianceManager instance
36
+ */
37
+ static async initialize(energyApp, config) {
38
+ const manager = new ApplianceManager(energyApp, config);
39
+ await manager.refreshCache();
40
+ return manager;
41
+ }
30
42
  /**
31
43
  * Creates or updates an appliance with the given configuration.
32
- * @param config The appliance configuration
33
- * @param existingApplianceId Optional ID of an existing appliance to update
44
+ * Automatically detects if an appliance already exists based on the identifier strategy.
45
+ * @param appliance The appliance configuration
34
46
  * @returns The ID of the created or updated appliance
35
47
  */
36
- async createOrUpdateAppliance(config, existingApplianceId) {
48
+ async createOrUpdateAppliance(appliance) {
49
+ // Refresh cache to ensure we have latest appliances
50
+ await this.refreshCache();
51
+ // Try to find existing appliance using identifier strategy
52
+ let existingApplianceId;
53
+ const identifier = this.config.identifierStrategy.extract(appliance);
54
+ if (identifier) {
55
+ const existing = await this.findByIdentifier(identifier);
56
+ if (existing.length > 0) {
57
+ existingApplianceId = existing[0].id;
58
+ if (this.config.enableLogging) {
59
+ console.log(`Found existing appliance with ID ${existingApplianceId} for identifier ${identifier}`);
60
+ }
61
+ }
62
+ }
37
63
  // Build network device IDs list
38
- const networkDeviceIds = config.networkDevices?.map(d => d.id) ?? [];
64
+ const networkDeviceIds = appliance.networkDevices?.map(d => d.id) ?? [];
39
65
  // Merge metadata with defaults
40
66
  const metadata = {
41
67
  connectionType: this.config.defaultConnectionType,
42
68
  state: enyo_appliance_js_1.EnyoApplianceStateEnum.Connected,
43
- ...config.metadata
69
+ ...appliance.metadata
44
70
  };
45
71
  if (this.config.defaultVendorName && !metadata.vendorName) {
46
72
  metadata.vendorName = this.config.defaultVendorName;
47
73
  }
48
74
  // Build appliance data
49
75
  const applianceData = {
50
- name: config.name,
51
- type: config.type,
76
+ name: appliance.name,
77
+ type: appliance.type,
52
78
  networkDeviceIds,
53
79
  metadata,
54
- ...(config.topology && { topology: config.topology })
80
+ ...(appliance.topology && { topology: appliance.topology }),
81
+ meter: appliance.meter,
82
+ heatpump: appliance.heatpump,
83
+ battery: appliance.battery,
84
+ charger: appliance.charger,
85
+ inverter: appliance.inverter,
55
86
  };
56
- // Add type-specific metadata
57
- if (config.typeMetadata) {
58
- Object.assign(applianceData, config.typeMetadata);
59
- }
60
87
  // Save appliance
61
88
  const applianceId = await this.energyApp.useAppliances().save(applianceData, existingApplianceId);
62
89
  // Update cache
63
90
  const savedAppliance = await this.energyApp.useAppliances().getById(applianceId);
64
91
  if (savedAppliance) {
65
- this.updateCache(savedAppliance, config.networkDevices?.[0]);
92
+ this.updateCache(savedAppliance);
93
+ }
94
+ if (this.config.enableLogging) {
95
+ console.log(`${existingApplianceId ? 'Updated' : 'Created'} appliance ${applianceId} of type ${appliance.type}`);
66
96
  }
67
- console.log(`${existingApplianceId ? 'Updated' : 'Created'} appliance ${applianceId} of type ${config.type}`);
68
97
  return applianceId;
69
98
  }
70
99
  /**
71
100
  * Updates the internal cache with an appliance.
72
101
  * @param appliance The appliance to cache
73
- * @param networkDevice Optional network device for identifier extraction
74
102
  */
75
- updateCache(appliance, networkDevice) {
103
+ updateCache(appliance) {
76
104
  this.applianceCache.set(appliance.id, appliance);
77
105
  // Extract identifier
78
- const identifier = this.config.identifierStrategy.extract(appliance, networkDevice);
106
+ const identifier = this.config.identifierStrategy.extract(appliance);
79
107
  if (identifier) {
80
108
  if (!this.identifierToApplianceId.has(identifier)) {
81
109
  this.identifierToApplianceId.set(identifier, new Set());
@@ -99,7 +127,7 @@ class ApplianceManager {
99
127
  for (const appliance of appliances) {
100
128
  // Try to get network devices if available
101
129
  const networkDevices = await this.getNetworkDevicesForAppliance(appliance);
102
- this.updateCache(appliance, networkDevices[0]);
130
+ this.updateCache(appliance);
103
131
  }
104
132
  }
105
133
  /**
@@ -143,10 +171,10 @@ class ApplianceManager {
143
171
  const matches = [];
144
172
  for (const appliance of allAppliances) {
145
173
  const networkDevices = await this.getNetworkDevicesForAppliance(appliance);
146
- const extractedId = this.config.identifierStrategy.extract(appliance, networkDevices[0]);
174
+ const extractedId = this.config.identifierStrategy.extract(appliance);
147
175
  if (extractedId === identifier) {
148
176
  matches.push(appliance);
149
- this.updateCache(appliance, networkDevices[0]);
177
+ this.updateCache(appliance);
150
178
  }
151
179
  }
152
180
  return matches;
@@ -162,7 +190,7 @@ class ApplianceManager {
162
190
  for (const strategy of strategies) {
163
191
  for (const appliance of allAppliances) {
164
192
  const networkDevices = await this.getNetworkDevicesForAppliance(appliance);
165
- const identifier = strategy.extract(appliance, networkDevices[0]);
193
+ const identifier = strategy.extract(appliance);
166
194
  if (identifier === searchValue) {
167
195
  return {
168
196
  appliance,
@@ -1,4 +1,4 @@
1
- import type { EnergyApp } from "../../index.cjs";
1
+ import { EnergyApp } from "../../index.cjs";
2
2
  import type { EnyoNetworkDevice } from "../../types/enyo-network-device.cjs";
3
3
  import { EnyoAppliance, EnyoApplianceConnectionType, EnyoApplianceMetadata, EnyoApplianceName, EnyoApplianceStateEnum, EnyoApplianceTopology, EnyoApplianceTypeEnum } from "../../types/enyo-appliance.cjs";
4
4
  import type { EnyoChargerApplianceMetadata } from "../../types/enyo-charger-appliance.cjs";
@@ -22,13 +22,11 @@ export interface ApplianceConfig {
22
22
  /** Topology information */
23
23
  topology?: EnyoApplianceTopology;
24
24
  /** Type-specific metadata based on appliance type */
25
- typeMetadata?: {
26
- meter?: EnyoMeterAppliance;
27
- inverter?: EnyoInverterApplianceMetadata;
28
- charger?: EnyoChargerApplianceMetadata;
29
- heatpump?: EnyoHeatpumpApplianceMetadata;
30
- battery?: EnyoBatteryApplianceMetadata;
31
- };
25
+ meter?: EnyoMeterAppliance;
26
+ inverter?: EnyoInverterApplianceMetadata;
27
+ charger?: EnyoChargerApplianceMetadata;
28
+ heatpump?: EnyoHeatpumpApplianceMetadata;
29
+ battery?: EnyoBatteryApplianceMetadata;
32
30
  }
33
31
  /**
34
32
  * Configuration options for the ApplianceManager.
@@ -64,26 +62,33 @@ export declare class ApplianceManager {
64
62
  private energyApp;
65
63
  private applianceCache;
66
64
  private identifierToApplianceId;
67
- private config;
65
+ protected config: Required<ApplianceManagerConfig>;
68
66
  /**
69
67
  * Creates a new ApplianceManager instance.
70
68
  * @param energyApp The EnergyApp instance to use for API calls
71
69
  * @param config Configuration options for the manager
72
70
  */
73
71
  constructor(energyApp: EnergyApp, config?: ApplianceManagerConfig);
72
+ /**
73
+ * initializes a new ApplianceManager instance with async initialization.
74
+ * This factory method handles cache initialization if configured.
75
+ * @param energyApp The EnergyApp instance to use for API calls
76
+ * @param config Configuration options for the manager
77
+ * @returns Promise that resolves to an initialized ApplianceManager instance
78
+ */
79
+ static initialize(energyApp: EnergyApp, config?: ApplianceManagerConfig): Promise<ApplianceManager>;
74
80
  /**
75
81
  * Creates or updates an appliance with the given configuration.
76
- * @param config The appliance configuration
77
- * @param existingApplianceId Optional ID of an existing appliance to update
82
+ * Automatically detects if an appliance already exists based on the identifier strategy.
83
+ * @param appliance The appliance configuration
78
84
  * @returns The ID of the created or updated appliance
79
85
  */
80
- createOrUpdateAppliance(config: ApplianceConfig, existingApplianceId?: string): Promise<string>;
86
+ createOrUpdateAppliance(appliance: ApplianceConfig): Promise<string>;
81
87
  /**
82
88
  * Updates the internal cache with an appliance.
83
89
  * @param appliance The appliance to cache
84
- * @param networkDevice Optional network device for identifier extraction
85
90
  */
86
- protected updateCache(appliance: EnyoAppliance, networkDevice?: EnyoNetworkDevice): void;
91
+ protected updateCache(appliance: EnyoAppliance): void;
87
92
  /**
88
93
  * Clears the internal cache.
89
94
  */
@@ -1,23 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IdentifierStrategyFactory = exports.FallbackIdentifierStrategy = exports.CompositeIdentifierStrategy = exports.CustomMetadataStrategy = exports.SerialNumberStrategy = exports.NetworkDeviceIdStrategy = void 0;
4
- /**
5
- * Strategy that uses the network device ID as the identifier.
6
- * This is the default strategy for most appliances.
7
- */
8
- class NetworkDeviceIdStrategy {
9
- name = 'networkDeviceId';
10
- /**
11
- * Extracts the network device ID.
12
- * @param appliance The appliance (not used in this strategy)
13
- * @param networkDevice The network device to get the ID from
14
- * @returns The network device ID or undefined
15
- */
16
- extract(appliance, networkDevice) {
17
- return networkDevice?.id;
18
- }
19
- }
20
- exports.NetworkDeviceIdStrategy = NetworkDeviceIdStrategy;
3
+ exports.IdentifierStrategyFactory = exports.FallbackIdentifierStrategy = exports.CompositeIdentifierStrategy = exports.CustomMetadataStrategy = exports.SerialNumberStrategy = void 0;
21
4
  /**
22
5
  * Strategy that uses the appliance's serial number as the identifier.
23
6
  * Useful when appliances can move between network devices.
@@ -81,13 +64,12 @@ class CompositeIdentifierStrategy {
81
64
  /**
82
65
  * Extracts and combines identifiers from multiple strategies.
83
66
  * @param appliance The appliance to extract identifiers from
84
- * @param networkDevice The network device if available
85
67
  * @returns The combined identifier or undefined if any part is missing
86
68
  */
87
- extract(appliance, networkDevice) {
69
+ extract(appliance) {
88
70
  const parts = [];
89
71
  for (const strategy of this.strategies) {
90
- const value = strategy.extract(appliance, networkDevice);
72
+ const value = strategy.extract(appliance);
91
73
  if (!value) {
92
74
  return undefined; // All parts must be present
93
75
  }
@@ -115,12 +97,11 @@ class FallbackIdentifierStrategy {
115
97
  /**
116
98
  * Tries strategies in order and returns the first available identifier.
117
99
  * @param appliance The appliance to extract identifiers from
118
- * @param networkDevice The network device if available
119
100
  * @returns The first available identifier or undefined
120
101
  */
121
- extract(appliance, networkDevice) {
102
+ extract(appliance) {
122
103
  for (const strategy of this.strategies) {
123
- const value = strategy.extract(appliance, networkDevice);
104
+ const value = strategy.extract(appliance);
124
105
  if (value) {
125
106
  return value;
126
107
  }
@@ -133,12 +114,6 @@ exports.FallbackIdentifierStrategy = FallbackIdentifierStrategy;
133
114
  * Factory class for creating common identifier strategies.
134
115
  */
135
116
  class IdentifierStrategyFactory {
136
- /**
137
- * Creates the default network device ID strategy.
138
- */
139
- static networkDeviceId() {
140
- return new NetworkDeviceIdStrategy();
141
- }
142
117
  /**
143
118
  * Creates a serial number strategy.
144
119
  */
@@ -167,14 +142,5 @@ class IdentifierStrategyFactory {
167
142
  static fallback(strategies) {
168
143
  return new FallbackIdentifierStrategy(strategies);
169
144
  }
170
- /**
171
- * Creates a strategy that prefers serial number but falls back to network device ID.
172
- */
173
- static serialNumberOrDeviceId() {
174
- return new FallbackIdentifierStrategy([
175
- new SerialNumberStrategy(),
176
- new NetworkDeviceIdStrategy()
177
- ]);
178
- }
179
145
  }
180
146
  exports.IdentifierStrategyFactory = IdentifierStrategyFactory;
@@ -1,5 +1,5 @@
1
1
  import type { EnyoAppliance } from "../../types/enyo-appliance.cjs";
2
- import type { EnyoNetworkDevice } from "../../types/enyo-network-device.cjs";
2
+ import { ApplianceConfig } from "./appliance-manager.cjs";
3
3
  /**
4
4
  * Strategy interface for extracting unique identifiers from appliances.
5
5
  * Allows flexible identification of appliances based on different criteria.
@@ -8,29 +8,14 @@ export interface IdentifierStrategy {
8
8
  /**
9
9
  * Extract the unique identifier from an appliance or its associated data.
10
10
  * @param appliance The appliance to extract the identifier from
11
- * @param networkDevice Optional network device associated with the appliance
12
11
  * @returns The extracted identifier string, or undefined if not available
13
12
  */
14
- extract(appliance: Partial<EnyoAppliance>, networkDevice?: EnyoNetworkDevice): string | undefined;
13
+ extract(appliance: EnyoAppliance | ApplianceConfig): string | undefined;
15
14
  /**
16
15
  * Name of the strategy for logging and debugging purposes.
17
16
  */
18
17
  name: string;
19
18
  }
20
- /**
21
- * Strategy that uses the network device ID as the identifier.
22
- * This is the default strategy for most appliances.
23
- */
24
- export declare class NetworkDeviceIdStrategy implements IdentifierStrategy {
25
- name: string;
26
- /**
27
- * Extracts the network device ID.
28
- * @param appliance The appliance (not used in this strategy)
29
- * @param networkDevice The network device to get the ID from
30
- * @returns The network device ID or undefined
31
- */
32
- extract(appliance: Partial<EnyoAppliance>, networkDevice?: EnyoNetworkDevice): string | undefined;
33
- }
34
19
  /**
35
20
  * Strategy that uses the appliance's serial number as the identifier.
36
21
  * Useful when appliances can move between network devices.
@@ -42,7 +27,7 @@ export declare class SerialNumberStrategy implements IdentifierStrategy {
42
27
  * @param appliance The appliance to extract the serial number from
43
28
  * @returns The serial number or undefined
44
29
  */
45
- extract(appliance: Partial<EnyoAppliance>): string | undefined;
30
+ extract(appliance: EnyoAppliance | ApplianceConfig): string | undefined;
46
31
  }
47
32
  /**
48
33
  * Strategy that uses a custom metadata field as the identifier.
@@ -61,7 +46,7 @@ export declare class CustomMetadataStrategy implements IdentifierStrategy {
61
46
  * @param appliance The appliance to extract the field from
62
47
  * @returns The field value or undefined
63
48
  */
64
- extract(appliance: Partial<EnyoAppliance>): string | undefined;
49
+ extract(appliance: EnyoAppliance | ApplianceConfig): string | undefined;
65
50
  }
66
51
  /**
67
52
  * Strategy that combines multiple identifiers to create a composite key.
@@ -80,10 +65,9 @@ export declare class CompositeIdentifierStrategy implements IdentifierStrategy {
80
65
  /**
81
66
  * Extracts and combines identifiers from multiple strategies.
82
67
  * @param appliance The appliance to extract identifiers from
83
- * @param networkDevice The network device if available
84
68
  * @returns The combined identifier or undefined if any part is missing
85
69
  */
86
- extract(appliance: Partial<EnyoAppliance>, networkDevice?: EnyoNetworkDevice): string | undefined;
70
+ extract(appliance: EnyoAppliance | ApplianceConfig): string | undefined;
87
71
  }
88
72
  /**
89
73
  * Strategy that tries multiple strategies in order and uses the first available identifier.
@@ -100,19 +84,14 @@ export declare class FallbackIdentifierStrategy implements IdentifierStrategy {
100
84
  /**
101
85
  * Tries strategies in order and returns the first available identifier.
102
86
  * @param appliance The appliance to extract identifiers from
103
- * @param networkDevice The network device if available
104
87
  * @returns The first available identifier or undefined
105
88
  */
106
- extract(appliance: Partial<EnyoAppliance>, networkDevice?: EnyoNetworkDevice): string | undefined;
89
+ extract(appliance: EnyoAppliance | ApplianceConfig): string | undefined;
107
90
  }
108
91
  /**
109
92
  * Factory class for creating common identifier strategies.
110
93
  */
111
94
  export declare class IdentifierStrategyFactory {
112
- /**
113
- * Creates the default network device ID strategy.
114
- */
115
- static networkDeviceId(): NetworkDeviceIdStrategy;
116
95
  /**
117
96
  * Creates a serial number strategy.
118
97
  */
@@ -133,8 +112,4 @@ export declare class IdentifierStrategyFactory {
133
112
  * @param strategies The strategies to try
134
113
  */
135
114
  static fallback(strategies: IdentifierStrategy[]): FallbackIdentifierStrategy;
136
- /**
137
- * Creates a strategy that prefers serial number but falls back to network device ID.
138
- */
139
- static serialNumberOrDeviceId(): FallbackIdentifierStrategy;
140
115
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InMemoryApplianceManager = void 0;
4
4
  const enyo_appliance_js_1 = require("../../types/enyo-appliance.cjs");
5
5
  const appliance_manager_js_1 = require("./appliance-manager.cjs");
6
+ const node_crypto_1 = require("node:crypto");
6
7
  /**
7
8
  * Demo implementation of ApplianceManager that stores all data in memory.
8
9
  * This class provides the same interface as ApplianceManager but doesn't
@@ -22,48 +23,58 @@ class InMemoryApplianceManager extends appliance_manager_js_1.ApplianceManager {
22
23
  }
23
24
  /**
24
25
  * Creates or updates an appliance in memory.
25
- * @param config The appliance configuration
26
- * @param existingApplianceId Optional ID of an existing appliance to update
26
+ * @param appliance The appliance configuration
27
27
  * @returns The ID of the created or updated appliance
28
28
  */
29
- async createOrUpdateAppliance(config, existingApplianceId) {
30
- const applianceId = existingApplianceId || `appliance_${this.nextId++}`;
29
+ async createOrUpdateAppliance(appliance) {
31
30
  // Build network device IDs list
32
- const networkDeviceIds = config.networkDevices?.map(d => d.id) ?? [];
33
- // Get existing metadata if updating
34
- const existingAppliance = existingApplianceId ? this.memoryStore.get(existingApplianceId) : null;
31
+ const networkDeviceIds = appliance.networkDevices?.map(d => d.id) ?? [];
32
+ // Try to find existing appliance using identifier strategy
33
+ let existingAppliance;
34
+ const identifier = this.config.identifierStrategy.extract(appliance);
35
+ if (identifier) {
36
+ const existing = await this.findByIdentifier(identifier);
37
+ if (existing.length > 0) {
38
+ existingAppliance = existing[0];
39
+ if (this.config.enableLogging) {
40
+ console.log(`Found existing appliance with ID ${existingAppliance.id} for identifier ${identifier}`);
41
+ }
42
+ }
43
+ }
35
44
  // Merge metadata with defaults and existing values
36
45
  const metadata = {
37
- connectionType: config.metadata?.connectionType ||
46
+ connectionType: appliance.metadata?.connectionType ||
38
47
  existingAppliance?.metadata?.connectionType ||
39
48
  enyo_appliance_js_1.EnyoApplianceConnectionType.Connector,
40
- state: config.metadata?.state ||
49
+ state: appliance.metadata?.state ||
41
50
  existingAppliance?.metadata?.state ||
42
51
  enyo_appliance_js_1.EnyoApplianceStateEnum.Connected,
43
- ...config.metadata
52
+ ...appliance.metadata
44
53
  };
45
54
  // Build appliance data
55
+ const applianceId = existingAppliance?.id || (0, node_crypto_1.randomUUID)();
46
56
  const applianceData = {
47
57
  id: applianceId,
48
- name: config.name,
49
- type: config.type,
58
+ name: appliance.name,
59
+ type: appliance.type,
50
60
  networkDeviceIds,
51
61
  metadata,
52
- ...(config.topology && { topology: config.topology })
62
+ ...(appliance.topology && { topology: appliance.topology }),
63
+ meter: appliance.meter,
64
+ heatpump: appliance.heatpump,
65
+ battery: appliance.battery,
66
+ charger: appliance.charger,
67
+ inverter: appliance.inverter,
53
68
  };
54
- // Add type-specific metadata
55
- if (config.typeMetadata) {
56
- Object.assign(applianceData, config.typeMetadata);
57
- }
58
69
  // Save to memory store
59
70
  this.memoryStore.set(applianceId, applianceData);
60
71
  // Store network devices if provided
61
- if (config.networkDevices) {
62
- this.networkDevicesStore.set(applianceId, config.networkDevices);
72
+ if (appliance.networkDevices) {
73
+ this.networkDevicesStore.set(applianceId, appliance.networkDevices);
63
74
  }
64
75
  // Update cache
65
- this.updateCache(applianceData, config.networkDevices?.[0]);
66
- console.log(`[DEMO] ${existingApplianceId ? 'Updated' : 'Created'} appliance ${applianceId} of type ${config.type}`);
76
+ this.updateCache(applianceData);
77
+ console.log(`[DEMO] ${existingAppliance ? 'Updated' : 'Created'} appliance ${applianceId} of type ${appliance.type}`);
67
78
  return applianceId;
68
79
  }
69
80
  /**
@@ -99,10 +110,10 @@ class InMemoryApplianceManager extends appliance_manager_js_1.ApplianceManager {
99
110
  const strategy = this.getIdentifierStrategy();
100
111
  for (const appliance of this.memoryStore.values()) {
101
112
  const networkDevices = await this.getNetworkDevicesForApplianceDemo(appliance);
102
- const extractedId = strategy.extract(appliance, networkDevices[0]);
113
+ const extractedId = strategy.extract(appliance);
103
114
  if (extractedId === identifier) {
104
115
  matches.push(appliance);
105
- this.updateCache(appliance, networkDevices[0]);
116
+ this.updateCache(appliance);
106
117
  }
107
118
  }
108
119
  return matches;
@@ -117,7 +128,7 @@ class InMemoryApplianceManager extends appliance_manager_js_1.ApplianceManager {
117
128
  for (const strategy of strategies) {
118
129
  for (const appliance of this.memoryStore.values()) {
119
130
  const networkDevices = await this.getNetworkDevicesForApplianceDemo(appliance);
120
- const identifier = strategy.extract(appliance, networkDevices[0]);
131
+ const identifier = strategy.extract(appliance);
121
132
  if (identifier === searchValue) {
122
133
  return {
123
134
  appliance,
@@ -257,7 +268,7 @@ class InMemoryApplianceManager extends appliance_manager_js_1.ApplianceManager {
257
268
  this.clearCache();
258
269
  for (const appliance of this.memoryStore.values()) {
259
270
  const networkDevices = await this.getNetworkDevicesForApplianceDemo(appliance);
260
- this.updateCache(appliance, networkDevices[0]);
271
+ this.updateCache(appliance);
261
272
  }
262
273
  }
263
274
  /**
@@ -20,11 +20,10 @@ export declare class InMemoryApplianceManager extends ApplianceManager {
20
20
  constructor(energyApp: EnergyApp, config?: ApplianceManagerConfig);
21
21
  /**
22
22
  * Creates or updates an appliance in memory.
23
- * @param config The appliance configuration
24
- * @param existingApplianceId Optional ID of an existing appliance to update
23
+ * @param appliance The appliance configuration
25
24
  * @returns The ID of the created or updated appliance
26
25
  */
27
- createOrUpdateAppliance(config: ApplianceConfig, existingApplianceId?: string): Promise<string>;
26
+ createOrUpdateAppliance(appliance: ApplianceConfig): Promise<string>;
28
27
  /**
29
28
  * Gets an appliance by ID from memory.
30
29
  * @param applianceId The ID of the appliance
@@ -19,6 +19,10 @@ class EnergyAppModbusDataTypeConverter {
19
19
  convertFromBuffer(buffer, dataType, scale, quantity) {
20
20
  try {
21
21
  switch (dataType) {
22
+ case 'acc16': {
23
+ const value = buffer.readUInt16BE(0);
24
+ return this.applyScale(value, scale);
25
+ }
22
26
  case 'uint16': {
23
27
  const value = buffer.readUInt16BE(0);
24
28
  return this.applyScale(value, scale);
@@ -27,6 +31,10 @@ class EnergyAppModbusDataTypeConverter {
27
31
  const value = buffer.readInt16BE(0);
28
32
  return this.applyScale(value, scale);
29
33
  }
34
+ case 'acc32': {
35
+ const value = buffer.readUInt32BE(0);
36
+ return this.applyScale(value, scale);
37
+ }
30
38
  case 'uint32': {
31
39
  const value = buffer.readUInt32BE(0);
32
40
  return this.applyScale(value, scale);
@@ -6,7 +6,7 @@ import type { EnyoApplianceName, EnyoApplianceTopology } from "../../types/enyo-
6
6
  * - Numeric types: uint16, int16, uint32, int32, float32
7
7
  * - String type: string (requires length property in register config)
8
8
  */
9
- export type EnergyAppModbusDataType = 'uint16' | 'int16' | 'uint32' | 'int32' | 'float32' | 'string';
9
+ export type EnergyAppModbusDataType = 'uint16' | 'int16' | 'uint32' | 'int32' | 'float32' | 'string' | 'acc32' | 'acc16';
10
10
  export interface EnergyAppModbusStateValueMapping<T> {
11
11
  value: number;
12
12
  mappedState: T;
@@ -55,6 +55,10 @@ export interface RegisterReadResult<T = any> {
55
55
  export interface IRegisterReader {
56
56
  readHoldingRegisters(startAddress: number, quantity: number): Promise<RegisterReadResult<Buffer>>;
57
57
  readInputRegisters?(startAddress: number, quantity: number): Promise<RegisterReadResult<Buffer>>;
58
+ readHoldingRegisterWithType<T = any>(address: number, dataType: EnergyAppModbusDataType, options?: {
59
+ scale?: number;
60
+ quantity?: number;
61
+ }): Promise<RegisterReadResult<T>>;
58
62
  isHealthy(): boolean;
59
63
  }
60
64
  export interface IRegisterMapper {
@@ -26,6 +26,7 @@ __exportStar(require("./types/enyo-settings.cjs"), exports);
26
26
  __exportStar(require("./types/enyo-energy-tariff.cjs"), exports);
27
27
  __exportStar(require("./types/enyo-electricity-prices.cjs"), exports);
28
28
  __exportStar(require("./types/enyo-notification.cjs"), exports);
29
+ __exportStar(require("./types/enyo-secret-manager.cjs"), exports);
29
30
  __exportStar(require("./implementations/appliances/appliance-manager.cjs"), exports);
30
31
  __exportStar(require("./implementations/appliances/identifier-strategies.cjs"), exports);
31
32
  class EnergyApp {
@@ -105,6 +106,14 @@ class EnergyApp {
105
106
  useNotification() {
106
107
  return this.energyAppSdk.useNotification();
107
108
  }
109
+ /**
110
+ * Gets the Secret Manager API for retrieving secrets from the developer organization.
111
+ * Provides methods to fetch secrets that have been configured in the developer org's secret store.
112
+ * @returns The Secret Manager API instance
113
+ */
114
+ useSecretManager() {
115
+ return this.energyAppSdk.useSecretManager();
116
+ }
108
117
  /**
109
118
  * Gets the current SDK version.
110
119
  * @returns The semantic version string of the SDK