v2c-any 0.4.1 → 0.4.2
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/dist/adapter/adapter-factory.js +1 -0
- package/dist/application-context.js +2 -2
- package/dist/device/shelly-pro-em/energy-information-em1-notify-status-adapter.js +13 -3
- package/dist/device/shelly-pro-em/energy-information-em1-status-adapter.js +6 -1
- package/dist/device/shelly-pro-em/index.js +6 -6
- package/dist/factory/mqtt-pull-executable-service-factory.js +5 -2
- package/dist/factory/mqtt-push-executable-service-factory.js +1 -1
- package/dist/index.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,12 +7,12 @@ import { logger } from './utils/logger.js';
|
|
|
7
7
|
* Registry of device provider factories keyed by device identifier.
|
|
8
8
|
* Each factory produces an `EM1Status` provider for a specific device.
|
|
9
9
|
*/
|
|
10
|
-
export const
|
|
10
|
+
export const devicesProviderFactoryRegistry = new Registry();
|
|
11
11
|
/**
|
|
12
12
|
* Registry of device adapters keyed by device identifier.
|
|
13
13
|
* Each adapter transforms raw device messages into `EnergyInformation`.
|
|
14
14
|
*/
|
|
15
|
-
export const
|
|
15
|
+
export const devicesAdapterFactoryRegistry = new Registry();
|
|
16
16
|
/**
|
|
17
17
|
* Dynamically loads all device modules discovered under devices.
|
|
18
18
|
* Imports each module to allow self-registration into application registries.
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { energyTypeToId } from '../../utils/mappers.js';
|
|
2
|
+
class EnergyInformationEM1NotifyStatusAdapter {
|
|
3
|
+
constructor(energyType) {
|
|
4
|
+
this.id = energyTypeToId(energyType);
|
|
5
|
+
}
|
|
2
6
|
adapt(input) {
|
|
3
|
-
const
|
|
7
|
+
const key = `em1:${this.id}`;
|
|
8
|
+
const em1Status = input.params[key];
|
|
4
9
|
if (em1Status !== undefined) {
|
|
5
10
|
return Promise.resolve({ power: em1Status.act_power });
|
|
6
11
|
}
|
|
7
12
|
return Promise.resolve(undefined);
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
|
-
|
|
15
|
+
class EnergyInformationEM1NotifyStatusAdapterFactory {
|
|
16
|
+
create(options) {
|
|
17
|
+
return new EnergyInformationEM1NotifyStatusAdapter(options.energyType);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export const energyInformationEM1NotifyStatusAdapterFactory = new EnergyInformationEM1NotifyStatusAdapterFactory();
|
|
@@ -21,4 +21,9 @@ class EnergyInformationEM1StatusAdapter {
|
|
|
21
21
|
* Singleton adapter instance for converting `EM1Status` to `EnergyInformation`.
|
|
22
22
|
* Use this ready-to-use instance where an adapter object is required.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
const energyInformationEM1StatusAdapter = new EnergyInformationEM1StatusAdapter();
|
|
25
|
+
export const energyInformationEM1StatusAdapterFactory = {
|
|
26
|
+
create() {
|
|
27
|
+
return energyInformationEM1StatusAdapter;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { devicesAdapterFactoryRegistry, devicesProviderFactoryRegistry, } from '../../application-context.js';
|
|
2
2
|
import { logger } from '../../utils/logger.js';
|
|
3
|
-
import {
|
|
3
|
+
import { energyInformationEM1StatusAdapterFactory } from './energy-information-em1-status-adapter.js';
|
|
4
4
|
import { em1StatusProviderFactory } from './em1-status-provider.js';
|
|
5
|
-
import {
|
|
5
|
+
import { energyInformationEM1NotifyStatusAdapterFactory } from './energy-information-em1-notify-status-adapter.js';
|
|
6
6
|
const DEVICE_NAME = 'shelly-pro-em';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
devicesProviderFactoryRegistry.register(DEVICE_NAME, em1StatusProviderFactory);
|
|
8
|
+
devicesAdapterFactoryRegistry.register(DEVICE_NAME, energyInformationEM1StatusAdapterFactory);
|
|
9
|
+
devicesAdapterFactoryRegistry.register(`${DEVICE_NAME}-notification`, energyInformationEM1NotifyStatusAdapterFactory);
|
|
10
10
|
logger.info('Shelly Pro EM registered');
|
|
@@ -33,10 +33,13 @@ export class MqttPullExecutableServiceFactory {
|
|
|
33
33
|
if (!providerFactory) {
|
|
34
34
|
throw new Error(`No provider registered for device: ${device}`);
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
if (!
|
|
36
|
+
const adapterFactory = this.adapterRegistry.get(device);
|
|
37
|
+
if (!adapterFactory) {
|
|
38
38
|
throw new Error(`No adapter registered for device: ${device}`);
|
|
39
39
|
}
|
|
40
|
+
const adapter = adapterFactory.create({
|
|
41
|
+
energyType: options.energyType,
|
|
42
|
+
});
|
|
40
43
|
return {
|
|
41
44
|
providerFactory: new AdapterProviderFactory(providerFactory, adapter),
|
|
42
45
|
interval: options.configuration.properties.interval,
|
|
@@ -28,7 +28,7 @@ export class MqttPushExecutableServiceFactory {
|
|
|
28
28
|
if (!adapter) {
|
|
29
29
|
throw new Error(`No adapter registered for device: ${device}`);
|
|
30
30
|
}
|
|
31
|
-
return new MqttBridgeService(options.configuration.properties, options.callbackProperties, adapter);
|
|
31
|
+
return new MqttBridgeService(options.configuration.properties, options.callbackProperties, adapter.create({ energyType: options.energyType }));
|
|
32
32
|
}
|
|
33
33
|
case 'off':
|
|
34
34
|
return noOpExecutableService;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { devicesAdapterFactoryRegistry as devicesAdapterFactoryRegistry, devicesProviderFactoryRegistry as devicesProviderFactoryRegistry, loadDeviceModules, } from './application-context.js';
|
|
3
3
|
import { ConfigurationLoader } from './configuration/configuration-loader.js';
|
|
4
4
|
import { ConfigurationValidator } from './configuration/configuration-validator.js';
|
|
5
5
|
import { logger } from './utils/logger.js';
|
|
@@ -17,11 +17,11 @@ async function main() {
|
|
|
17
17
|
let executableServiceFactory;
|
|
18
18
|
switch (configuration.provider) {
|
|
19
19
|
case 'rest': {
|
|
20
|
-
executableServiceFactory = new RestServiceFactory(new EM1StatusProviderFactory(
|
|
20
|
+
executableServiceFactory = new RestServiceFactory(new EM1StatusProviderFactory(devicesProviderFactoryRegistry));
|
|
21
21
|
break;
|
|
22
22
|
}
|
|
23
23
|
case 'mqtt': {
|
|
24
|
-
const mqttFeedExecutableServiceFactory = new MqttFeedExecutableServiceFactory(new MqttPullExecutableServiceFactory(
|
|
24
|
+
const mqttFeedExecutableServiceFactory = new MqttFeedExecutableServiceFactory(new MqttPullExecutableServiceFactory(devicesProviderFactoryRegistry, devicesAdapterFactoryRegistry), new MqttPushExecutableServiceFactory(devicesAdapterFactoryRegistry));
|
|
25
25
|
executableServiceFactory = new MqttServiceFactory(mqttFeedExecutableServiceFactory);
|
|
26
26
|
break;
|
|
27
27
|
}
|