@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
@@ -13,6 +13,7 @@ import { EnergyAppAuthentication } from "./packages/energy-app-authentication.cj
13
13
  import { EnergyAppSettings } from "./packages/energy-app-settings.cjs";
14
14
  import { EnergyAppElectricityPrices } from "./packages/energy-app-electricity-prices.cjs";
15
15
  import { EnergyAppNotification } from "./packages/energy-app-notification.cjs";
16
+ import { EnergyAppSecretManager } from "./packages/energy-app-secret-manager.cjs";
16
17
  export * from './energy-app-package-definition.cjs';
17
18
  export * from './version.cjs';
18
19
  export * from './implementations/ocpp/ocpp16.cjs';
@@ -23,6 +24,7 @@ export * from './types/enyo-settings.cjs';
23
24
  export * from './types/enyo-energy-tariff.cjs';
24
25
  export * from './types/enyo-electricity-prices.cjs';
25
26
  export * from './types/enyo-notification.cjs';
27
+ export * from './types/enyo-secret-manager.cjs';
26
28
  export * from './implementations/appliances/appliance-manager.cjs';
27
29
  export * from './implementations/appliances/identifier-strategies.cjs';
28
30
  export declare class EnergyApp implements EnyoEnergyAppSdk {
@@ -47,6 +49,12 @@ export declare class EnergyApp implements EnyoEnergyAppSdk {
47
49
  useSettings(): EnergyAppSettings;
48
50
  useElectricityPrices(): EnergyAppElectricityPrices;
49
51
  useNotification(): EnergyAppNotification;
52
+ /**
53
+ * Gets the Secret Manager API for retrieving secrets from the developer organization.
54
+ * Provides methods to fetch secrets that have been configured in the developer org's secret store.
55
+ * @returns The Secret Manager API instance
56
+ */
57
+ useSecretManager(): EnergyAppSecretManager;
50
58
  /**
51
59
  * Gets the current SDK version.
52
60
  * @returns The semantic version string of the SDK
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,61 @@
1
+ import { SecretValue } from "../types/enyo-secret-manager.cjs";
2
+ export interface EnergyAppSecretManager {
3
+ /**
4
+ * Retrieves and decrypts a single secret from the developer organization's secret store.
5
+ * The secret must have been previously configured in the developer org using the enyo CLI.
6
+ *
7
+ * @param secretName - The name of the secret to retrieve (e.g., "ostrom_oauth")
8
+ * @param encryptionKey - The encryption key used to decrypt the secret
9
+ * @returns Promise that resolves to an object containing the decrypted secret's key-value pairs
10
+ * @throws {SecretNotFoundError} If the secret does not exist
11
+ * @throws {SecretRetrievalError} If there's an error retrieving or decrypting the secret
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const secretManager = energyApp.useSecretManager();
16
+ * const oauthSecret = await secretManager.getSecret("oauth", encryptionKey);
17
+ * // Returns: { client_id: "...", client_secret: "..." }
18
+ * ```
19
+ */
20
+ getSecret(secretName: string, encryptionKey: string): Promise<SecretValue>;
21
+ /**
22
+ * Retrieves and decrypts multiple secrets from the developer organization's secret store in a single request.
23
+ * This is more efficient than making multiple individual requests.
24
+ * All secrets must have been previously configured using the enyo CLI.
25
+ *
26
+ * @param secretNames - Array of secret names to retrieve
27
+ * @param encryptionKey - The encryption key used to decrypt the secrets
28
+ * @returns Promise that resolves to a record mapping secret names to their decrypted values
29
+ * @throws {SecretNotFoundError} If any of the secrets do not exist
30
+ * @throws {SecretRetrievalError} If there's an error retrieving or decrypting the secrets
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const secretManager = energyApp.useSecretManager();
35
+ * const encryptionKey = process.env.SECRET_ENCRYPTION_KEY;
36
+ * const secrets = await secretManager.getSecrets(["api_keys", "oauth_config"], encryptionKey);
37
+ * // Returns: {
38
+ * // "api_keys": { api_key: "...", api_secret: "..." },
39
+ * // "oauth_config": { client_id: "...", client_secret: "..." }
40
+ * // }
41
+ * ```
42
+ */
43
+ getSecrets(secretNames: string[], encryptionKey: string): Promise<Record<string, SecretValue>>;
44
+ /**
45
+ * Lists all available secret names that can be retrieved from the developer organization.
46
+ * This can be useful for discovering what secrets have been configured.
47
+ * Note: This returns only the names of secrets, not their values.
48
+ *
49
+ * @returns Promise that resolves to an array of available secret names
50
+ * @throws {SecretRetrievalError} If there's an error listing the secrets
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const secretManager = energyApp.useSecretManager();
55
+ * const encryptionKey = process.env.SECRET_ENCRYPTION_KEY;
56
+ * const availableSecrets = await secretManager.listAvailableSecrets(encryptionKey);
57
+ * // Returns: ["oauth", "api_keys", "database_config"]
58
+ * ```
59
+ */
60
+ listAvailableSecrets(): Promise<string[]>;
61
+ }
@@ -207,16 +207,27 @@ export interface EnyoDataBusInverterValuesV1 extends EnyoDataBusMessage {
207
207
  /** ID of the appliance that delivered these values */
208
208
  applianceId: string;
209
209
  data: {
210
+ /** Operation State of the inverter */
210
211
  state?: EnyoInverterStateEnum;
211
212
  /** Current PV Production (in Watt) */
212
213
  pvPowerW: number;
213
- /** voltage of Phase L1 to N*/
214
+ /** voltage of Phase L1 to N in V */
214
215
  voltageL1: number;
215
- /** voltage of Phase L2 to N*/
216
+ /** voltage of Phase L2 to N in V */
216
217
  voltageL2?: number;
217
- /** voltage of Phase L3 to N*/
218
+ /** voltage of Phase L3 to N in V */
218
219
  voltageL3?: number;
220
+ /** Current of Phase L1 to N in A */
221
+ currentL1?: number;
222
+ /** Current of Phase L2 to N in A */
223
+ currentL2?: number;
224
+ /** Current of Phase L3 to N in A */
225
+ currentL3?: number;
226
+ /** DC Power in W */
227
+ dcPowerW?: number;
228
+ /** Active power Limitation of the Inverter */
219
229
  activePowerLimitationW?: number;
230
+ /** DC String values. Please only provide active strings */
220
231
  strings?: EnyoDataBusInverterValuesV1String[];
221
232
  };
222
233
  }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecretRetrievalError = exports.SecretNotFoundError = void 0;
4
+ /**
5
+ * Error that occurs when a secret cannot be found.
6
+ */
7
+ class SecretNotFoundError extends Error {
8
+ }
9
+ exports.SecretNotFoundError = SecretNotFoundError;
10
+ /**
11
+ * Error that occurs when secret retrieval fails.
12
+ */
13
+ class SecretRetrievalError extends Error {
14
+ }
15
+ exports.SecretRetrievalError = SecretRetrievalError;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Represents a secret value object containing key-value pairs.
3
+ * The secret is retrieved from the developer organization's secret store.
4
+ */
5
+ export interface SecretValue {
6
+ [key: string]: string;
7
+ }
8
+ /**
9
+ * Request structure for fetching a single secret.
10
+ */
11
+ export interface SecretRequest {
12
+ /** The name of the secret to retrieve */
13
+ secretName: string;
14
+ }
15
+ /**
16
+ * Response structure for secret retrieval operations.
17
+ */
18
+ export interface SecretResponse {
19
+ /** The name of the secret */
20
+ secretName: string;
21
+ /** The secret values as key-value pairs */
22
+ values: SecretValue;
23
+ }
24
+ /**
25
+ * Error that occurs when a secret cannot be found.
26
+ */
27
+ export declare class SecretNotFoundError extends Error {
28
+ }
29
+ /**
30
+ * Error that occurs when secret retrieval fails.
31
+ */
32
+ export declare class SecretRetrievalError extends Error {
33
+ }
@@ -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.39';
12
+ exports.SDK_VERSION = '0.0.41';
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.39";
8
+ export declare const SDK_VERSION = "0.0.41";
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
@@ -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
  }
@@ -15,4 +15,5 @@ export var EnergyAppPermissionTypeEnum;
15
15
  EnergyAppPermissionTypeEnum["ChargingCard"] = "ChargingCard";
16
16
  EnergyAppPermissionTypeEnum["Vehicle"] = "Vehicle";
17
17
  EnergyAppPermissionTypeEnum["Charge"] = "Charge";
18
+ EnergyAppPermissionTypeEnum["SecretManager"] = "SecretManager";
18
19
  })(EnergyAppPermissionTypeEnum || (EnergyAppPermissionTypeEnum = {}));
@@ -12,6 +12,7 @@ import { EnergyAppAuthentication } from "./packages/energy-app-authentication.js
12
12
  import { EnergyAppSettings } from "./packages/energy-app-settings.js";
13
13
  import { EnergyAppElectricityPrices } from "./packages/energy-app-electricity-prices.js";
14
14
  import { EnergyAppNotification } from "./packages/energy-app-notification.js";
15
+ import { EnergyAppSecretManager } from "./packages/energy-app-secret-manager.js";
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,4 +1,4 @@
1
- import type { EnergyApp } from "../../index.js";
1
+ import { EnergyApp } from "../../index.js";
2
2
  import type { EnyoNetworkDevice } from "../../types/enyo-network-device.js";
3
3
  import { EnyoAppliance, EnyoApplianceConnectionType, EnyoApplianceMetadata, EnyoApplianceName, EnyoApplianceStateEnum, EnyoApplianceTopology, EnyoApplianceTypeEnum } from "../../types/enyo-appliance.js";
4
4
  import type { EnyoChargerApplianceMetadata } from "../../types/enyo-charger-appliance.js";
@@ -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,5 +1,5 @@
1
+ import { SerialNumberStrategy } from "../../index.js";
1
2
  import { EnyoApplianceConnectionType, EnyoApplianceStateEnum } from "../../types/enyo-appliance.js";
2
- import { NetworkDeviceIdStrategy } from "./identifier-strategies.js";
3
3
  /**
4
4
  * Manages appliances in the energy system with configurable identification strategies.
5
5
  * Provides comprehensive CRUD operations and state management for energy appliances.
@@ -17,62 +17,90 @@ export class ApplianceManager {
17
17
  constructor(energyApp, config) {
18
18
  this.energyApp = energyApp;
19
19
  this.config = {
20
- identifierStrategy: config?.identifierStrategy ?? new NetworkDeviceIdStrategy(),
20
+ identifierStrategy: config?.identifierStrategy ?? new SerialNumberStrategy(),
21
21
  autoUpdateMetadata: config?.autoUpdateMetadata ?? true,
22
22
  enableLogging: config?.enableLogging ?? true,
23
23
  defaultConnectionType: config?.defaultConnectionType ?? EnyoApplianceConnectionType.Connector,
24
- defaultVendorName: config?.defaultVendorName ?? ''
24
+ defaultVendorName: config?.defaultVendorName ?? '',
25
25
  };
26
26
  }
27
+ /**
28
+ * initializes a new ApplianceManager instance with async initialization.
29
+ * This factory method handles cache initialization if configured.
30
+ * @param energyApp The EnergyApp instance to use for API calls
31
+ * @param config Configuration options for the manager
32
+ * @returns Promise that resolves to an initialized ApplianceManager instance
33
+ */
34
+ static async initialize(energyApp, config) {
35
+ const manager = new ApplianceManager(energyApp, config);
36
+ await manager.refreshCache();
37
+ return manager;
38
+ }
27
39
  /**
28
40
  * Creates or updates an appliance with the given configuration.
29
- * @param config The appliance configuration
30
- * @param existingApplianceId Optional ID of an existing appliance to update
41
+ * Automatically detects if an appliance already exists based on the identifier strategy.
42
+ * @param appliance The appliance configuration
31
43
  * @returns The ID of the created or updated appliance
32
44
  */
33
- async createOrUpdateAppliance(config, existingApplianceId) {
45
+ async createOrUpdateAppliance(appliance) {
46
+ // Refresh cache to ensure we have latest appliances
47
+ await this.refreshCache();
48
+ // Try to find existing appliance using identifier strategy
49
+ let existingApplianceId;
50
+ const identifier = this.config.identifierStrategy.extract(appliance);
51
+ if (identifier) {
52
+ const existing = await this.findByIdentifier(identifier);
53
+ if (existing.length > 0) {
54
+ existingApplianceId = existing[0].id;
55
+ if (this.config.enableLogging) {
56
+ console.log(`Found existing appliance with ID ${existingApplianceId} for identifier ${identifier}`);
57
+ }
58
+ }
59
+ }
34
60
  // Build network device IDs list
35
- const networkDeviceIds = config.networkDevices?.map(d => d.id) ?? [];
61
+ const networkDeviceIds = appliance.networkDevices?.map(d => d.id) ?? [];
36
62
  // Merge metadata with defaults
37
63
  const metadata = {
38
64
  connectionType: this.config.defaultConnectionType,
39
65
  state: EnyoApplianceStateEnum.Connected,
40
- ...config.metadata
66
+ ...appliance.metadata
41
67
  };
42
68
  if (this.config.defaultVendorName && !metadata.vendorName) {
43
69
  metadata.vendorName = this.config.defaultVendorName;
44
70
  }
45
71
  // Build appliance data
46
72
  const applianceData = {
47
- name: config.name,
48
- type: config.type,
73
+ name: appliance.name,
74
+ type: appliance.type,
49
75
  networkDeviceIds,
50
76
  metadata,
51
- ...(config.topology && { topology: config.topology })
77
+ ...(appliance.topology && { topology: appliance.topology }),
78
+ meter: appliance.meter,
79
+ heatpump: appliance.heatpump,
80
+ battery: appliance.battery,
81
+ charger: appliance.charger,
82
+ inverter: appliance.inverter,
52
83
  };
53
- // Add type-specific metadata
54
- if (config.typeMetadata) {
55
- Object.assign(applianceData, config.typeMetadata);
56
- }
57
84
  // Save appliance
58
85
  const applianceId = await this.energyApp.useAppliances().save(applianceData, existingApplianceId);
59
86
  // Update cache
60
87
  const savedAppliance = await this.energyApp.useAppliances().getById(applianceId);
61
88
  if (savedAppliance) {
62
- this.updateCache(savedAppliance, config.networkDevices?.[0]);
89
+ this.updateCache(savedAppliance);
90
+ }
91
+ if (this.config.enableLogging) {
92
+ console.log(`${existingApplianceId ? 'Updated' : 'Created'} appliance ${applianceId} of type ${appliance.type}`);
63
93
  }
64
- console.log(`${existingApplianceId ? 'Updated' : 'Created'} appliance ${applianceId} of type ${config.type}`);
65
94
  return applianceId;
66
95
  }
67
96
  /**
68
97
  * Updates the internal cache with an appliance.
69
98
  * @param appliance The appliance to cache
70
- * @param networkDevice Optional network device for identifier extraction
71
99
  */
72
- updateCache(appliance, networkDevice) {
100
+ updateCache(appliance) {
73
101
  this.applianceCache.set(appliance.id, appliance);
74
102
  // Extract identifier
75
- const identifier = this.config.identifierStrategy.extract(appliance, networkDevice);
103
+ const identifier = this.config.identifierStrategy.extract(appliance);
76
104
  if (identifier) {
77
105
  if (!this.identifierToApplianceId.has(identifier)) {
78
106
  this.identifierToApplianceId.set(identifier, new Set());
@@ -96,7 +124,7 @@ export class ApplianceManager {
96
124
  for (const appliance of appliances) {
97
125
  // Try to get network devices if available
98
126
  const networkDevices = await this.getNetworkDevicesForAppliance(appliance);
99
- this.updateCache(appliance, networkDevices[0]);
127
+ this.updateCache(appliance);
100
128
  }
101
129
  }
102
130
  /**
@@ -140,10 +168,10 @@ export class ApplianceManager {
140
168
  const matches = [];
141
169
  for (const appliance of allAppliances) {
142
170
  const networkDevices = await this.getNetworkDevicesForAppliance(appliance);
143
- const extractedId = this.config.identifierStrategy.extract(appliance, networkDevices[0]);
171
+ const extractedId = this.config.identifierStrategy.extract(appliance);
144
172
  if (extractedId === identifier) {
145
173
  matches.push(appliance);
146
- this.updateCache(appliance, networkDevices[0]);
174
+ this.updateCache(appliance);
147
175
  }
148
176
  }
149
177
  return matches;
@@ -159,7 +187,7 @@ export class ApplianceManager {
159
187
  for (const strategy of strategies) {
160
188
  for (const appliance of allAppliances) {
161
189
  const networkDevices = await this.getNetworkDevicesForAppliance(appliance);
162
- const identifier = strategy.extract(appliance, networkDevices[0]);
190
+ const identifier = strategy.extract(appliance);
163
191
  if (identifier === searchValue) {
164
192
  return {
165
193
  appliance,
@@ -1,5 +1,5 @@
1
1
  import type { EnyoAppliance } from "../../types/enyo-appliance.js";
2
- import type { EnyoNetworkDevice } from "../../types/enyo-network-device.js";
2
+ import { ApplianceConfig } from "./appliance-manager.js";
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
  }
@@ -1,19 +1,3 @@
1
- /**
2
- * Strategy that uses the network device ID as the identifier.
3
- * This is the default strategy for most appliances.
4
- */
5
- export class NetworkDeviceIdStrategy {
6
- name = 'networkDeviceId';
7
- /**
8
- * Extracts the network device ID.
9
- * @param appliance The appliance (not used in this strategy)
10
- * @param networkDevice The network device to get the ID from
11
- * @returns The network device ID or undefined
12
- */
13
- extract(appliance, networkDevice) {
14
- return networkDevice?.id;
15
- }
16
- }
17
1
  /**
18
2
  * Strategy that uses the appliance's serial number as the identifier.
19
3
  * Useful when appliances can move between network devices.
@@ -75,13 +59,12 @@ export class CompositeIdentifierStrategy {
75
59
  /**
76
60
  * Extracts and combines identifiers from multiple strategies.
77
61
  * @param appliance The appliance to extract identifiers from
78
- * @param networkDevice The network device if available
79
62
  * @returns The combined identifier or undefined if any part is missing
80
63
  */
81
- extract(appliance, networkDevice) {
64
+ extract(appliance) {
82
65
  const parts = [];
83
66
  for (const strategy of this.strategies) {
84
- const value = strategy.extract(appliance, networkDevice);
67
+ const value = strategy.extract(appliance);
85
68
  if (!value) {
86
69
  return undefined; // All parts must be present
87
70
  }
@@ -108,12 +91,11 @@ export class FallbackIdentifierStrategy {
108
91
  /**
109
92
  * Tries strategies in order and returns the first available identifier.
110
93
  * @param appliance The appliance to extract identifiers from
111
- * @param networkDevice The network device if available
112
94
  * @returns The first available identifier or undefined
113
95
  */
114
- extract(appliance, networkDevice) {
96
+ extract(appliance) {
115
97
  for (const strategy of this.strategies) {
116
- const value = strategy.extract(appliance, networkDevice);
98
+ const value = strategy.extract(appliance);
117
99
  if (value) {
118
100
  return value;
119
101
  }
@@ -125,12 +107,6 @@ export class FallbackIdentifierStrategy {
125
107
  * Factory class for creating common identifier strategies.
126
108
  */
127
109
  export class IdentifierStrategyFactory {
128
- /**
129
- * Creates the default network device ID strategy.
130
- */
131
- static networkDeviceId() {
132
- return new NetworkDeviceIdStrategy();
133
- }
134
110
  /**
135
111
  * Creates a serial number strategy.
136
112
  */
@@ -159,13 +135,4 @@ export class IdentifierStrategyFactory {
159
135
  static fallback(strategies) {
160
136
  return new FallbackIdentifierStrategy(strategies);
161
137
  }
162
- /**
163
- * Creates a strategy that prefers serial number but falls back to network device ID.
164
- */
165
- static serialNumberOrDeviceId() {
166
- return new FallbackIdentifierStrategy([
167
- new SerialNumberStrategy(),
168
- new NetworkDeviceIdStrategy()
169
- ]);
170
- }
171
138
  }
@@ -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