@pietrolubini/homebridge-ecoflow 1.0.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.
Files changed (60) hide show
  1. package/.prettierrc.json +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +92 -0
  4. package/config.schema.json +49 -0
  5. package/dist/accessories/apis/ecoFlowHttpApi.d.ts +15 -0
  6. package/dist/accessories/apis/ecoFlowHttpApi.js +115 -0
  7. package/dist/accessories/apis/ecoFlowHttpApi.js.map +1 -0
  8. package/dist/accessories/apis/ecoFlowMqttApi.d.ts +23 -0
  9. package/dist/accessories/apis/ecoFlowMqttApi.js +86 -0
  10. package/dist/accessories/apis/ecoFlowMqttApi.js.map +1 -0
  11. package/dist/accessories/apis/interfaces/ecoFlowHttpContacts.d.ts +46 -0
  12. package/dist/accessories/apis/interfaces/ecoFlowHttpContacts.js +6 -0
  13. package/dist/accessories/apis/interfaces/ecoFlowHttpContacts.js.map +1 -0
  14. package/dist/accessories/apis/interfaces/ecoFlowMqttContacts.d.ts +68 -0
  15. package/dist/accessories/apis/interfaces/ecoFlowMqttContacts.js +9 -0
  16. package/dist/accessories/apis/interfaces/ecoFlowMqttContacts.js.map +1 -0
  17. package/dist/accessories/delta2maxAccessory.d.ts +27 -0
  18. package/dist/accessories/delta2maxAccessory.js +123 -0
  19. package/dist/accessories/delta2maxAccessory.js.map +1 -0
  20. package/dist/accessories/ecoFlowAccessory.d.ts +34 -0
  21. package/dist/accessories/ecoFlowAccessory.js +83 -0
  22. package/dist/accessories/ecoFlowAccessory.js.map +1 -0
  23. package/dist/accessories/services/accessoryInformationService.d.ts +6 -0
  24. package/dist/accessories/services/accessoryInformationService.js +24 -0
  25. package/dist/accessories/services/accessoryInformationService.js.map +1 -0
  26. package/dist/accessories/services/batteryService.d.ts +8 -0
  27. package/dist/accessories/services/batteryService.js +29 -0
  28. package/dist/accessories/services/batteryService.js.map +1 -0
  29. package/dist/accessories/services/outletAcService.d.ts +6 -0
  30. package/dist/accessories/services/outletAcService.js +15 -0
  31. package/dist/accessories/services/outletAcService.js.map +1 -0
  32. package/dist/accessories/services/outletCarService.d.ts +6 -0
  33. package/dist/accessories/services/outletCarService.js +10 -0
  34. package/dist/accessories/services/outletCarService.js.map +1 -0
  35. package/dist/accessories/services/outletServiceBase.d.ts +15 -0
  36. package/dist/accessories/services/outletServiceBase.js +44 -0
  37. package/dist/accessories/services/outletServiceBase.js.map +1 -0
  38. package/dist/accessories/services/outletUsbService.d.ts +6 -0
  39. package/dist/accessories/services/outletUsbService.js +10 -0
  40. package/dist/accessories/services/outletUsbService.js.map +1 -0
  41. package/dist/accessories/services/serviceBase.d.ts +11 -0
  42. package/dist/accessories/services/serviceBase.js +20 -0
  43. package/dist/accessories/services/serviceBase.js.map +1 -0
  44. package/dist/config.d.ts +13 -0
  45. package/dist/config.js +5 -0
  46. package/dist/config.js.map +1 -0
  47. package/dist/helpers/machineId.d.ts +2 -0
  48. package/dist/helpers/machineId.js +15 -0
  49. package/dist/helpers/machineId.js.map +1 -0
  50. package/dist/helpers/machineIdHelper.cjs +5 -0
  51. package/dist/index.d.ts +6 -0
  52. package/dist/index.js +9 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/platform.d.ts +26 -0
  55. package/dist/platform.js +96 -0
  56. package/dist/platform.js.map +1 -0
  57. package/dist/settings.d.ts +8 -0
  58. package/dist/settings.js +9 -0
  59. package/dist/settings.js.map +1 -0
  60. package/package.json +55 -0
@@ -0,0 +1,123 @@
1
+ import { EcoFlowAccessoryWithQuota } from './ecoFlowAccessory.js';
2
+ import { BatteryService } from './services/batteryService.js';
3
+ import { OutletUsbService } from './services/outletUsbService.js';
4
+ import { OutletCarService } from './services/outletCarService.js';
5
+ import { OutletAcService } from './services/outletAcService.js';
6
+ import { MqttMessageType, } from './apis/interfaces/ecoFlowMqttContacts.js';
7
+ export class Delta2MaxAccessory extends EcoFlowAccessoryWithQuota {
8
+ platform;
9
+ accessory;
10
+ config;
11
+ batteryService;
12
+ outletUsbService;
13
+ outletAcService;
14
+ outletCarService;
15
+ constructor(platform, accessory, config) {
16
+ super(platform, accessory, config);
17
+ this.platform = platform;
18
+ this.accessory = accessory;
19
+ this.config = config;
20
+ this.batteryService = new BatteryService(this);
21
+ this.outletUsbService = new OutletUsbService(this);
22
+ this.outletAcService = new OutletAcService(this);
23
+ this.outletCarService = new OutletCarService(this);
24
+ }
25
+ getServices() {
26
+ return [this.batteryService, this.outletUsbService, this.outletAcService, this.outletCarService];
27
+ }
28
+ updateInitialValues(initialData) {
29
+ this.updateBmsInitialValues(initialData);
30
+ this.updateInvInitialValues(initialData);
31
+ this.updatePdInitialValues(initialData);
32
+ }
33
+ subscribeOnParameterUpdates() {
34
+ return [
35
+ this.mqttApi.bmsParams$.subscribe(params => this.updateBmsValues(params)),
36
+ this.mqttApi.invParams$.subscribe(params => this.updateInvValues(params)),
37
+ this.mqttApi.pdParams$.subscribe(params => this.updatePdValues(params)),
38
+ ];
39
+ }
40
+ updateBmsInitialValues(initialData) {
41
+ const bmsMessage = {
42
+ typeCode: MqttMessageType.BMS,
43
+ params: {
44
+ f32ShowSoc: initialData['bms_bmsStatus.f32ShowSoc'],
45
+ },
46
+ };
47
+ this.mqttApi.processMqttMessage(bmsMessage);
48
+ }
49
+ updateInvInitialValues(initialData) {
50
+ const invMessage = {
51
+ typeCode: MqttMessageType.INV,
52
+ params: {
53
+ inputWatts: initialData['inv.inputWatts'],
54
+ outputWatts: initialData['inv.outputWatts'],
55
+ cfgAcEnabled: initialData['inv.cfgAcEnabled'],
56
+ },
57
+ };
58
+ this.mqttApi.processMqttMessage(invMessage);
59
+ }
60
+ updatePdInitialValues(initialData) {
61
+ const pdMessage = {
62
+ typeCode: MqttMessageType.PD,
63
+ params: {
64
+ carState: initialData['pd.carState'],
65
+ carWatts: initialData['pd.carWatts'],
66
+ dcOutState: initialData['pd.dcOutState'],
67
+ usb1Watts: initialData['pd.usb1Watts'],
68
+ usb2Watts: initialData['pd.usb2Watts'],
69
+ qcUsb1Watts: initialData['pd.qcUsb1Watts'],
70
+ qcUsb2Watts: initialData['pd.qcUsb2Watts'],
71
+ typec1Watts: initialData['pd.typec1Watts'],
72
+ typec2Watts: initialData['pd.typec2Watts'],
73
+ },
74
+ };
75
+ this.mqttApi.processMqttMessage(pdMessage);
76
+ }
77
+ updateBmsValues(params) {
78
+ if (params.f32ShowSoc !== undefined) {
79
+ this.batteryService.updateStatusLowBattery(params.f32ShowSoc);
80
+ this.batteryService.updateBatteryLevel(params.f32ShowSoc);
81
+ }
82
+ }
83
+ updateInvValues(params) {
84
+ if (params.inputWatts !== undefined) {
85
+ this.batteryService.updateChargingState(params.inputWatts);
86
+ }
87
+ if (params.cfgAcEnabled !== undefined) {
88
+ this.outletAcService.updateState(params.cfgAcEnabled);
89
+ }
90
+ if (params.outputWatts !== undefined) {
91
+ this.outletAcService.updateInUse(params.outputWatts > 0);
92
+ }
93
+ }
94
+ updatePdValues(params) {
95
+ if (params.carState !== undefined) {
96
+ this.outletCarService.updateState(params.carState);
97
+ }
98
+ if (params.carWatts !== undefined) {
99
+ this.outletCarService.updateInUse(params.carWatts > 0);
100
+ }
101
+ if (params.dcOutState !== undefined) {
102
+ this.outletUsbService.updateState(params.dcOutState);
103
+ }
104
+ if (params.usb1Watts !== undefined ||
105
+ params.usb2Watts !== undefined ||
106
+ params.qcUsb1Watts !== undefined ||
107
+ params.qcUsb2Watts !== undefined ||
108
+ params.typec1Watts !== undefined ||
109
+ params.typec2Watts !== undefined) {
110
+ const usbWatts = this.getUsbWatts(params.usb1Watts, params.usb2Watts, params.qcUsb1Watts, params.qcUsb2Watts, params.typec1Watts, params.typec2Watts);
111
+ this.outletUsbService.updateInUse(usbWatts > 0);
112
+ }
113
+ }
114
+ getUsbWatts(usb1Watts, usb2Watts, qcUsb1Watts, qcUsb2Watts, typec1Watts, typec2Watts) {
115
+ return ((usb1Watts ?? 0) +
116
+ (usb2Watts ?? 0) +
117
+ (qcUsb1Watts ?? 0) +
118
+ (qcUsb2Watts ?? 0) +
119
+ (typec1Watts ?? 0) +
120
+ (typec2Watts ?? 0));
121
+ }
122
+ }
123
+ //# sourceMappingURL=delta2maxAccessory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delta2maxAccessory.js","sourceRoot":"","sources":["../../src/accessories/delta2maxAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAIL,eAAe,GAEhB,MAAM,0CAA0C,CAAC;AAMlD,MAAM,OAAO,kBAAmB,SAAQ,yBAAqD;IAOzE;IACA;IACA;IARD,cAAc,CAAiB;IAC/B,gBAAgB,CAAmB;IACnC,eAAe,CAAkB;IACjC,gBAAgB,CAAmB;IAEpD,YACkB,QAAmC,EACnC,SAA4B,EAC5B,MAAoB;QAEpC,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAJnB,aAAQ,GAAR,QAAQ,CAA2B;QACnC,cAAS,GAAT,SAAS,CAAmB;QAC5B,WAAM,GAAN,MAAM,CAAc;QAGpC,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAEkB,WAAW;QAC5B,OAAO,CAAC,IAAI,CAAC,cAAc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B,EACpB,WAAoB;QAEpB,OAAO,CACL,CAAC,SAAS,IAAI,CAAC,CAAC;YAChB,CAAC,SAAS,IAAI,CAAC,CAAC;YAChB,CAAC,WAAW,IAAI,CAAC,CAAC;YAClB,CAAC,WAAW,IAAI,CAAC,CAAC;YAClB,CAAC,WAAW,IAAI,CAAC,CAAC;YAClB,CAAC,WAAW,IAAI,CAAC,CAAC,CACnB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,34 @@
1
+ import { Logging, PlatformAccessory } from 'homebridge';
2
+ import { EcoFlowHomebridgePlatform } from '../platform.js';
3
+ import { DeviceConfig } from '../config.js';
4
+ import { ServiceBase } from './services/serviceBase.js';
5
+ import { EcoFlowMqttApi } from './apis/ecoFlowMqttApi.js';
6
+ import { EcoFlowHttpApi } from './apis/ecoFlowHttpApi.js';
7
+ import { CmdResponseData } from './apis/interfaces/ecoFlowHttpContacts.js';
8
+ import { Subscription } from 'rxjs';
9
+ export declare abstract class EcoFlowAccessory {
10
+ readonly platform: EcoFlowHomebridgePlatform;
11
+ readonly accessory: PlatformAccessory;
12
+ readonly config: DeviceConfig;
13
+ readonly log: Logging;
14
+ readonly mqttApi: EcoFlowMqttApi;
15
+ protected readonly httpApi: EcoFlowHttpApi;
16
+ private services;
17
+ private reconnectMqttTimeoutId;
18
+ private isMqttConnected;
19
+ private subscriptions;
20
+ constructor(platform: EcoFlowHomebridgePlatform, accessory: PlatformAccessory, config: DeviceConfig);
21
+ initialize(): Promise<void>;
22
+ destroy(): void;
23
+ protected abstract getServices(): ServiceBase[];
24
+ protected abstract subscribeOnParameterUpdates(): Subscription[];
25
+ private initializeServices;
26
+ private cleanupServices;
27
+ private connectMqtt;
28
+ private initMqtt;
29
+ }
30
+ export declare abstract class EcoFlowAccessoryWithQuota<TGetQuotasCmdResponseData extends CmdResponseData> extends EcoFlowAccessory {
31
+ private initialData;
32
+ initialize(): Promise<void>;
33
+ protected abstract updateInitialValues(initialData: TGetQuotasCmdResponseData): void;
34
+ }
@@ -0,0 +1,83 @@
1
+ import { EcoFlowMqttApi } from './apis/ecoFlowMqttApi.js';
2
+ import { AccessoryInformationService } from './services/accessoryInformationService.js';
3
+ import { EcoFlowHttpApi } from './apis/ecoFlowHttpApi.js';
4
+ export class EcoFlowAccessory {
5
+ platform;
6
+ accessory;
7
+ config;
8
+ log;
9
+ mqttApi;
10
+ httpApi;
11
+ services = [];
12
+ reconnectMqttTimeoutId = null;
13
+ isMqttConnected = false;
14
+ subscriptions = [];
15
+ constructor(platform, accessory, config) {
16
+ this.platform = platform;
17
+ this.accessory = accessory;
18
+ this.config = config;
19
+ this.log = this.platform.log;
20
+ this.httpApi = new EcoFlowHttpApi(this.config, this.log);
21
+ this.mqttApi = new EcoFlowMqttApi(this.httpApi, this.log);
22
+ }
23
+ async initialize() {
24
+ this.services = this.getServices();
25
+ this.services.push(new AccessoryInformationService(this));
26
+ this.initializeServices();
27
+ this.subscriptions = this.subscribeOnParameterUpdates();
28
+ await this.connectMqtt();
29
+ }
30
+ destroy() {
31
+ if (this.reconnectMqttTimeoutId !== null) {
32
+ clearTimeout(this.reconnectMqttTimeoutId);
33
+ this.reconnectMqttTimeoutId = null;
34
+ }
35
+ this.subscriptions.forEach(subscription => subscription.unsubscribe());
36
+ }
37
+ initializeServices() {
38
+ this.services.forEach(service => {
39
+ service.initialize();
40
+ });
41
+ this.cleanupServices();
42
+ }
43
+ cleanupServices() {
44
+ const services = this.services.map(service => service.service);
45
+ this.accessory.services
46
+ .filter(service => !services.includes(service))
47
+ .forEach(service => {
48
+ this.platform.log.info(`Removing obsolete service from accessory '${this.config.name}':`, service.displayName);
49
+ this.accessory.removeService(service);
50
+ });
51
+ }
52
+ async connectMqtt() {
53
+ await this.initMqtt();
54
+ this.reconnectMqttTimeoutId = setInterval(async () => {
55
+ // Check MQTT is connected every minute
56
+ if (!this.isMqttConnected) {
57
+ await this.initMqtt();
58
+ }
59
+ }, 60 * 1000);
60
+ }
61
+ async initMqtt() {
62
+ try {
63
+ await this.mqttApi.subscribe('/open/<certificateAccount>/<sn>/quota', this.config.serialNumber);
64
+ this.isMqttConnected = true;
65
+ }
66
+ catch (e) {
67
+ if (e instanceof Error) {
68
+ this.log.error(e.message);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ export class EcoFlowAccessoryWithQuota extends EcoFlowAccessory {
74
+ initialData = null;
75
+ async initialize() {
76
+ if (!this.initialData) {
77
+ this.initialData = await this.httpApi.getAllQuotas();
78
+ }
79
+ await super.initialize();
80
+ this.updateInitialValues(this.initialData);
81
+ }
82
+ }
83
+ //# sourceMappingURL=ecoFlowAccessory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecoFlowAccessory.js","sourceRoot":"","sources":["../../src/accessories/ecoFlowAccessory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI1D,MAAM,OAAgB,gBAAgB;IAUlB;IACA;IACA;IAXF,GAAG,CAAU;IACb,OAAO,CAAiB;IACrB,OAAO,CAAiB;IACnC,QAAQ,GAAkB,EAAE,CAAC;IAC7B,sBAAsB,GAA0B,IAAI,CAAC;IACrD,eAAe,GAAY,KAAK,CAAC;IACjC,aAAa,GAAmB,EAAE,CAAC;IAE3C,YACkB,QAAmC,EACnC,SAA4B,EAC5B,MAAoB;QAFpB,aAAQ,GAAR,QAAQ,CAA2B;QACnC,cAAS,GAAT,SAAS,CAAmB;QAC5B,WAAM,GAAN,MAAM,CAAc;QAEpC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,GAAG,IAAI,cAAc,CA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}
@@ -0,0 +1,6 @@
1
+ import { Service } from 'homebridge';
2
+ import { ServiceBase } from './serviceBase.js';
3
+ export declare class AccessoryInformationService extends ServiceBase {
4
+ protected createService(): Service;
5
+ private getVersion;
6
+ }
@@ -0,0 +1,24 @@
1
+ import { ServiceBase } from './serviceBase.js';
2
+ import { fileURLToPath } from 'url';
3
+ import path from 'path';
4
+ import fs from 'fs';
5
+ export class AccessoryInformationService extends ServiceBase {
6
+ createService() {
7
+ const service = this.ecoFlowAccessory.accessory.getService(this.ecoFlowAccessory.platform.Service.AccessoryInformation) ||
8
+ this.ecoFlowAccessory.accessory.addService(this.ecoFlowAccessory.platform.Service.AccessoryInformation);
9
+ service
10
+ .setCharacteristic(this.ecoFlowAccessory.platform.Characteristic.Manufacturer, 'EcoFlow')
11
+ .setCharacteristic(this.ecoFlowAccessory.platform.Characteristic.Model, this.ecoFlowAccessory.config.model)
12
+ .setCharacteristic(this.ecoFlowAccessory.platform.Characteristic.SerialNumber, this.ecoFlowAccessory.config.serialNumber)
13
+ .setCharacteristic(this.ecoFlowAccessory.platform.Characteristic.FirmwareRevision, this.getVersion());
14
+ return service;
15
+ }
16
+ getVersion() {
17
+ const filename = fileURLToPath(import.meta.url);
18
+ const dirname = path.dirname(filename);
19
+ const packageJsonPath = path.resolve(dirname, '../../../package.json');
20
+ const packageData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
21
+ return packageData?.version;
22
+ }
23
+ }
24
+ //# sourceMappingURL=accessoryInformationService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessoryInformationService.js","sourceRoot":"","sources":["../../../src/accessories/services/accessoryInformationService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,OAAO,2BAA4B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;CACF"}
@@ -0,0 +1,8 @@
1
+ import { Service } from 'homebridge';
2
+ import { ServiceBase } from './serviceBase.js';
3
+ export declare class BatteryService extends ServiceBase {
4
+ protected createService(): Service;
5
+ updateStatusLowBattery(batteryLevel: number): void;
6
+ updateBatteryLevel(batteryLevel: number): void;
7
+ updateChargingState(chargingPower: number): void;
8
+ }
@@ -0,0 +1,29 @@
1
+ import { ServiceBase } from './serviceBase.js';
2
+ export class BatteryService extends ServiceBase {
3
+ createService() {
4
+ const service = this.ecoFlowAccessory.accessory.getService(this.ecoFlowAccessory.platform.Service.Battery) ||
5
+ this.ecoFlowAccessory.accessory.addService(this.ecoFlowAccessory.platform.Service.Battery, this.ecoFlowAccessory.config.name);
6
+ return service;
7
+ }
8
+ updateStatusLowBattery(batteryLevel) {
9
+ const statusLowBattery = batteryLevel < 20;
10
+ this.log.debug('Status Low Battery ->', statusLowBattery);
11
+ this.service
12
+ .getCharacteristic(this.ecoFlowAccessory.platform.Characteristic.StatusLowBattery)
13
+ .updateValue(statusLowBattery
14
+ ? this.ecoFlowAccessory.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
15
+ : this.ecoFlowAccessory.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL);
16
+ }
17
+ updateBatteryLevel(batteryLevel) {
18
+ this.log.debug('BatteryLevel ->', batteryLevel);
19
+ this.service
20
+ .getCharacteristic(this.ecoFlowAccessory.platform.Characteristic.BatteryLevel)
21
+ .updateValue(batteryLevel);
22
+ }
23
+ updateChargingState(chargingPower) {
24
+ const isCharging = chargingPower > 0;
25
+ this.log.debug('ChargingState ->', isCharging);
26
+ this.service.getCharacteristic(this.ecoFlowAccessory.platform.Characteristic.ChargingState).updateValue(isCharging);
27
+ }
28
+ }
29
+ //# sourceMappingURL=batteryService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batteryService.js","sourceRoot":"","sources":["../../../src/accessories/services/batteryService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,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,MAAM,UAAU,GAAG,aAAa,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACtH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { OutletsServiceBase } from './outletServiceBase.js';
2
+ import { EcoFlowAccessory } from 'accessories/ecoFlowAccessory.js';
3
+ export declare class OutletAcService extends OutletsServiceBase {
4
+ constructor(ecoFlowAccessory: EcoFlowAccessory);
5
+ protected setOn(value: boolean): Promise<void>;
6
+ }
@@ -0,0 +1,15 @@
1
+ import { OutletsServiceBase } from './outletServiceBase.js';
2
+ export class OutletAcService extends OutletsServiceBase {
3
+ constructor(ecoFlowAccessory) {
4
+ super('AC', ecoFlowAccessory);
5
+ }
6
+ setOn(value) {
7
+ return this.publishEnabled(3, 'acOutCfg', {
8
+ out_voltage: 4294967295,
9
+ out_freq: 1,
10
+ xboost: Number(true),
11
+ enabled: Number(value),
12
+ });
13
+ }
14
+ }
15
+ //# sourceMappingURL=outletAcService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outletAcService.js","sourceRoot":"","sources":["../../../src/accessories/services/outletAcService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAG5D,MAAM,OAAO,eAAgB,SAAQ,kBAAkB;IACrD,YAAY,gBAAkC;QAC5C,KAAK,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAChC,CAAC;IAEkB,KAAK,CAAC,KAAc;QACrC,OAAO,IAAI,CAAC,cAAc,CAAgC,CAAC,EAAE,UAAU,EAAE;YACvE,WAAW,EAAE,UAAU;YACvB,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC;YACpB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;SACvB,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { OutletsServiceBase } from './outletServiceBase.js';
2
+ import { EcoFlowAccessory } from 'accessories/ecoFlowAccessory.js';
3
+ export declare class OutletCarService extends OutletsServiceBase {
4
+ constructor(ecoFlowAccessory: EcoFlowAccessory);
5
+ protected setOn(value: boolean): Promise<void>;
6
+ }
@@ -0,0 +1,10 @@
1
+ import { OutletsServiceBase } from './outletServiceBase.js';
2
+ export class OutletCarService extends OutletsServiceBase {
3
+ constructor(ecoFlowAccessory) {
4
+ super('CAR', ecoFlowAccessory);
5
+ }
6
+ setOn(value) {
7
+ return this.publishEnabled(5, 'mpptCar', { enabled: Number(value) });
8
+ }
9
+ }
10
+ //# sourceMappingURL=outletCarService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outletCarService.js","sourceRoot":"","sources":["../../../src/accessories/services/outletCarService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAG5D,MAAM,OAAO,gBAAiB,SAAQ,kBAAkB;IACtD,YAAY,gBAAkC;QAC5C,KAAK,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACjC,CAAC;IAEkB,KAAK,CAAC,KAAc;QACrC,OAAO,IAAI,CAAC,cAAc,CAA8B,CAAC,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACpG,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import { Service } from 'homebridge';
2
+ import { ServiceBase } from './serviceBase.js';
3
+ import { MqttSetMessageParams } from 'accessories/apis/interfaces/ecoFlowMqttContacts.js';
4
+ import { EcoFlowAccessory } from 'accessories/ecoFlowAccessory.js';
5
+ export declare abstract class OutletsServiceBase extends ServiceBase {
6
+ private readonly serviceSubType;
7
+ constructor(serviceSubType: string, ecoFlowAccessory: EcoFlowAccessory);
8
+ updateState(state: boolean): void;
9
+ updateInUse(isInUse: boolean): void;
10
+ protected createService(): Service;
11
+ protected abstract setOn(value: boolean): Promise<void>;
12
+ protected publishEnabled<TParams extends MqttSetMessageParams>(moduleType: number, operateType: string, params: TParams): Promise<void>;
13
+ private addCharacteristics;
14
+ private getOrAddService;
15
+ }
@@ -0,0 +1,44 @@
1
+ import { ServiceBase } from './serviceBase.js';
2
+ export class OutletsServiceBase extends ServiceBase {
3
+ serviceSubType;
4
+ constructor(serviceSubType, ecoFlowAccessory) {
5
+ super(ecoFlowAccessory);
6
+ this.serviceSubType = serviceSubType;
7
+ }
8
+ updateState(state) {
9
+ this.log.debug(`${this.serviceSubType} State ->`, state);
10
+ this.service.getCharacteristic(this.ecoFlowAccessory.platform.Characteristic.On).updateValue(state);
11
+ }
12
+ updateInUse(isInUse) {
13
+ this.log.debug(`${this.serviceSubType} InUse ->`, isInUse);
14
+ this.service.getCharacteristic(this.ecoFlowAccessory.platform.Characteristic.OutletInUse).updateValue(isInUse);
15
+ }
16
+ createService() {
17
+ const service = this.getOrAddService(this.ecoFlowAccessory.config.name, this.serviceSubType);
18
+ this.addCharacteristics(service);
19
+ return service;
20
+ }
21
+ async publishEnabled(moduleType, operateType, params) {
22
+ const data = {
23
+ id: Math.floor(Math.random() * 1000000),
24
+ version: '1.0',
25
+ moduleType,
26
+ operateType,
27
+ params,
28
+ };
29
+ await this.ecoFlowAccessory.mqttApi.publish('/open/<certificateAccount>/<sn>/set', this.ecoFlowAccessory.config.serialNumber, data);
30
+ }
31
+ addCharacteristics(service) {
32
+ service
33
+ .getCharacteristic(this.ecoFlowAccessory.platform.Characteristic.On)
34
+ .onSet(value => this.setOn(value));
35
+ }
36
+ getOrAddService(deviceName, serviceSubType) {
37
+ const serviceName = deviceName + ' ' + serviceSubType;
38
+ const service = this.ecoFlowAccessory.accessory.getServiceById(this.ecoFlowAccessory.platform.Service.Outlet, serviceSubType) ||
39
+ this.ecoFlowAccessory.accessory.addService(this.ecoFlowAccessory.platform.Service.Outlet, serviceName, serviceSubType);
40
+ service.setCharacteristic(this.ecoFlowAccessory.platform.Characteristic.Name, serviceName);
41
+ return service;
42
+ }
43
+ }
44
+ //# sourceMappingURL=outletServiceBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outletServiceBase.js","sourceRoot":"","sources":["../../../src/accessories/services/outletServiceBase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C,MAAM,OAAgB,kBAAmB,SAAQ,WAAW;IAC7B;IAA7B,YAA6B,cAAsB,EAAE,gBAAkC;QACrF,KAAK,CAAC,gBAAgB,CAAC,CAAC;QADG,mBAAc,GAAd,cAAc,CAAQ;IAEnD,CAAC;IAEM,WAAW,CAAC,KAAc;QAC/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,cAAc,WAAW,EAAE,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACtG,CAAC;IAEM,WAAW,CAAC,OAAgB;QACjC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,cAAc,WAAW,EAAE,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjH,CAAC;IAEkB,aAAa;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAC7F,IAAI,CAAC,kBAAkB,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C;CACF"}
@@ -0,0 +1,6 @@
1
+ import { OutletsServiceBase } from './outletServiceBase.js';
2
+ import { EcoFlowAccessory } from 'accessories/ecoFlowAccessory.js';
3
+ export declare class OutletUsbService extends OutletsServiceBase {
4
+ constructor(ecoFlowAccessory: EcoFlowAccessory);
5
+ protected setOn(value: boolean): Promise<void>;
6
+ }
@@ -0,0 +1,10 @@
1
+ import { OutletsServiceBase } from './outletServiceBase.js';
2
+ export class OutletUsbService extends OutletsServiceBase {
3
+ constructor(ecoFlowAccessory) {
4
+ super('USB', ecoFlowAccessory);
5
+ }
6
+ setOn(value) {
7
+ return this.publishEnabled(1, 'dcOutCfg', { enabled: Number(value) });
8
+ }
9
+ }
10
+ //# sourceMappingURL=outletUsbService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outletUsbService.js","sourceRoot":"","sources":["../../../src/accessories/services/outletUsbService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAG5D,MAAM,OAAO,gBAAiB,SAAQ,kBAAkB;IACtD,YAAY,gBAAkC;QAC5C,KAAK,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACjC,CAAC;IAEkB,KAAK,CAAC,KAAc;QACrC,OAAO,IAAI,CAAC,cAAc,CAA8B,CAAC,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrG,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import { Logging, Service } from 'homebridge';
2
+ import { EcoFlowAccessory } from 'accessories/ecoFlowAccessory.js';
3
+ export declare abstract class ServiceBase {
4
+ protected ecoFlowAccessory: EcoFlowAccessory;
5
+ protected readonly log: Logging;
6
+ private _service;
7
+ constructor(ecoFlowAccessory: EcoFlowAccessory);
8
+ initialize(): void;
9
+ get service(): Service;
10
+ protected abstract createService(): Service;
11
+ }
@@ -0,0 +1,20 @@
1
+ export class ServiceBase {
2
+ ecoFlowAccessory;
3
+ log;
4
+ _service = null;
5
+ constructor(ecoFlowAccessory) {
6
+ this.ecoFlowAccessory = ecoFlowAccessory;
7
+ this.log = ecoFlowAccessory.log;
8
+ }
9
+ initialize() {
10
+ this._service = this.createService();
11
+ }
12
+ // Getter for service
13
+ get service() {
14
+ if (!this._service) {
15
+ throw new Error('Service is not initialized');
16
+ }
17
+ return this._service;
18
+ }
19
+ }
20
+ //# sourceMappingURL=serviceBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serviceBase.js","sourceRoot":"","sources":["../../../src/accessories/services/serviceBase.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,WAAW;IAIT;IAHH,GAAG,CAAU;IACxB,QAAQ,GAAmB,IAAI,CAAC;IAExC,YAAsB,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;QACtD,IAAI,CAAC,GAAG,GAAG,gBAAgB,CAAC,GAAG,CAAC;IAClC,CAAC;IAEM,UAAU;QACf,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IACvC,CAAC;IAED,qBAAqB;IACrB,IAAW,OAAO;QAChB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CAGF"}
@@ -0,0 +1,13 @@
1
+ import { AccessoryConfig, PlatformConfig } from 'homebridge';
2
+ export interface EcoFlowConfig extends PlatformConfig {
3
+ devices: DeviceConfig[];
4
+ }
5
+ export declare enum DeviceModel {
6
+ Delta2Max = "Delta 2 Max"
7
+ }
8
+ export interface DeviceConfig extends AccessoryConfig {
9
+ model: DeviceModel;
10
+ serialNumber: string;
11
+ accessKey: string;
12
+ secretKey: string;
13
+ }
package/dist/config.js ADDED
@@ -0,0 +1,5 @@
1
+ export var DeviceModel;
2
+ (function (DeviceModel) {
3
+ DeviceModel["Delta2Max"] = "Delta 2 Max";
4
+ })(DeviceModel || (DeviceModel = {}));
5
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,wCAAyB,CAAA;AAC3B,CAAC,EAFW,WAAW,KAAX,WAAW,QAEtB"}
@@ -0,0 +1,2 @@
1
+ import { Logging } from 'homebridge';
2
+ export declare function getMachineId(log: Logging): Promise<string>;
@@ -0,0 +1,15 @@
1
+ import { createRequire } from 'module';
2
+ import { v4 as uuidV4 } from 'uuid';
3
+ const require = createRequire(import.meta.url);
4
+ const { machineId } = require('./machineIdHelper.cjs');
5
+ export async function getMachineId(log) {
6
+ try {
7
+ const id = await machineId();
8
+ return id;
9
+ }
10
+ catch (error) {
11
+ log.warn('Can not get Machine ID. Using UUID instead', error);
12
+ return uuidV4();
13
+ }
14
+ }
15
+ //# sourceMappingURL=machineId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"machineId.js","sourceRoot":"","sources":["../../src/helpers/machineId.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAY;IAC7C,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,MAAM,SAAS,EAAE,CAAC;QAC7B,OAAO,EAAE,CAAC;IACZ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,IAAI,CAAC,4CAA4C,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,MAAM,EAAE,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ const { machineId } = require('node-machine-id');
2
+
3
+ module.exports = {
4
+ machineId,
5
+ };
@@ -0,0 +1,6 @@
1
+ import { API } from 'homebridge';
2
+ /**
3
+ * This method registers the platform with Homebridge
4
+ */
5
+ declare const _default: (api: API) => void;
6
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { PLATFORM_NAME } from './settings.js';
2
+ import { EcoFlowHomebridgePlatform } from './platform.js';
3
+ /**
4
+ * This method registers the platform with Homebridge
5
+ */
6
+ export default (api) => {
7
+ api.registerPlatform(PLATFORM_NAME, EcoFlowHomebridgePlatform);
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D;;GAEG;AACH,eAAe,CAAC,GAAQ,EAAE,EAAE;IAC1B,GAAG,CAAC,gBAAgB,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;AACjE,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { API, DynamicPlatformPlugin, Logging, PlatformAccessory, PlatformConfig, Service, Characteristic, UnknownContext } from 'homebridge';
2
+ import { DeviceConfig } from './config.js';
3
+ import { EcoFlowAccessory } from './accessories/ecoFlowAccessory.js';
4
+ /**
5
+ * HomebridgePlatform
6
+ * This class is the main constructor for your plugin, this is where you should
7
+ * parse the user config and discover/register accessories with Homebridge.
8
+ */
9
+ export declare class EcoFlowHomebridgePlatform implements DynamicPlatformPlugin {
10
+ readonly log: Logging;
11
+ readonly config: PlatformConfig;
12
+ readonly api: API;
13
+ private readonly ecoFlowConfig;
14
+ readonly Service: typeof Service;
15
+ readonly Characteristic: typeof Characteristic;
16
+ readonly accessories: PlatformAccessory[];
17
+ constructor(log: Logging, config: PlatformConfig, api: API);
18
+ /**
19
+ * This function is invoked when homebridge restores cached accessories from disk at startup.
20
+ * It should be used to set up event handlers for characteristics and update respective values.
21
+ */
22
+ configureAccessory(accessory: PlatformAccessory): void;
23
+ registerDevices(): void;
24
+ cleanupDevices(configuredAccessories: PlatformAccessory[]): void;
25
+ createAccessory(accessory: PlatformAccessory<UnknownContext>, config: DeviceConfig): EcoFlowAccessory;
26
+ }