@pietrolubini/homebridge-ecoflow 1.1.0 → 1.2.1
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/README.md +32 -0
- package/config.schema.json +25 -0
- package/dist/accessories/batteries/batteryAccessory.js +11 -5
- package/dist/accessories/batteries/batteryAccessory.js.map +1 -1
- package/dist/accessories/ecoFlowAccessory.js +10 -1
- package/dist/accessories/ecoFlowAccessory.js.map +1 -1
- package/dist/apis/ecoFlowHttpApi.d.ts +2 -1
- package/dist/apis/ecoFlowHttpApi.js +7 -4
- package/dist/apis/ecoFlowHttpApi.js.map +1 -1
- package/dist/characteristics/CustomCharacteristic.d.ts +18 -0
- package/dist/characteristics/CustomCharacteristic.js +87 -0
- package/dist/characteristics/CustomCharacteristic.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +11 -0
- package/dist/config.js.map +1 -1
- package/dist/helpers/logger.js +6 -6
- package/dist/helpers/logger.js.map +1 -1
- package/dist/platform.d.ts +7 -3
- package/dist/platform.js +28 -11
- package/dist/platform.js.map +1 -1
- package/dist/services/accessoryInformationService.d.ts +2 -1
- package/dist/services/accessoryInformationService.js +16 -8
- package/dist/services/accessoryInformationService.js.map +1 -1
- package/dist/services/{batteryService.d.ts → batteryStatusService.d.ts} +3 -2
- package/dist/services/batteryStatusService.js +32 -0
- package/dist/services/batteryStatusService.js.map +1 -0
- package/dist/services/outletServiceBase.d.ts +11 -4
- package/dist/services/outletServiceBase.js +43 -19
- package/dist/services/outletServiceBase.js.map +1 -1
- package/dist/services/serviceBase.d.ts +14 -1
- package/dist/services/serviceBase.js +35 -0
- package/dist/services/serviceBase.js.map +1 -1
- package/docs/images/BatteryAdditionalCharacteristics.jpg +0 -0
- package/package.json +1 -1
- package/dist/services/batteryService.js +0 -29
- package/dist/services/batteryService.js.map +0 -1
package/README.md
CHANGED
|
@@ -54,6 +54,7 @@ Example configuration:
|
|
|
54
54
|
"name": "Battery",
|
|
55
55
|
"model": "Delta 2 Max",
|
|
56
56
|
"serialNumber": "R123ABCDEGHI321",
|
|
57
|
+
"location": "EU",
|
|
57
58
|
"accessKey": "IROcwtlejtHj4qY4MRgCZW0CxoCdPVs3",
|
|
58
59
|
"secretKey": "yBwYgZWqNnAlULKmF1Qrydy2Iheexj22"
|
|
59
60
|
}
|
|
@@ -64,6 +65,37 @@ Example configuration:
|
|
|
64
65
|
}
|
|
65
66
|
```
|
|
66
67
|
|
|
68
|
+
### Battery-specific Configuration
|
|
69
|
+
|
|
70
|
+
If `devices`.`model` is one of [`Delta 2`, `Delta 2 Max`] it is possible to set turn on/off additional characteristics:
|
|
71
|
+
|
|
72
|
+
- Input Consumption, W
|
|
73
|
+
- Output Consumption, W
|
|
74
|
+
- Battery Level, %
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
{
|
|
78
|
+
...
|
|
79
|
+
"devices": [
|
|
80
|
+
{
|
|
81
|
+
...,
|
|
82
|
+
"model": "Delta 2 Max",
|
|
83
|
+
"battery": {
|
|
84
|
+
"additionalCharacteristics": [
|
|
85
|
+
"Battery Level, %",
|
|
86
|
+
"Input Consumption, W",
|
|
87
|
+
"Output Consumption, W"
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The characteristics could be used as conditions in HomeKit Automation that uses Shortcuts:
|
|
96
|
+
|
|
97
|
+
<img src="docs/images/BatteryAdditionalCharacteristics.jpg" alt="Battery Additional Characteristics" width="300">
|
|
98
|
+
|
|
67
99
|
### AccessKey and SecretKey
|
|
68
100
|
|
|
69
101
|
For the plugin to work EcoFlow account's `AccessKey` and `SecretKey` is required. To retrieve them
|
package/config.schema.json
CHANGED
|
@@ -36,6 +36,14 @@
|
|
|
36
36
|
"required": true,
|
|
37
37
|
"description": "Serial number of the EcoFlow device"
|
|
38
38
|
},
|
|
39
|
+
"location": {
|
|
40
|
+
"title": "Location",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"default": "EU",
|
|
43
|
+
"required": true,
|
|
44
|
+
"enum": ["EU", "US"],
|
|
45
|
+
"description": "API host depends on device's location (EU: api-e.ecoflow.com, US: api-a.ecoflow.com)"
|
|
46
|
+
},
|
|
39
47
|
"accessKey": {
|
|
40
48
|
"title": "Access Key",
|
|
41
49
|
"type": "string",
|
|
@@ -47,6 +55,23 @@
|
|
|
47
55
|
"type": "string",
|
|
48
56
|
"required": true,
|
|
49
57
|
"description": "Secret Key from \"EcoFlow IoT Developer Platform\" (https://developer-eu.ecoflow.com)"
|
|
58
|
+
},
|
|
59
|
+
"battery": {
|
|
60
|
+
"title": "Battery Settings",
|
|
61
|
+
"type": "object",
|
|
62
|
+
"properties": {
|
|
63
|
+
"additionalCharacteristics": {
|
|
64
|
+
"title": "Additional characteristics",
|
|
65
|
+
"description": "List of additional characteristics for battery",
|
|
66
|
+
"type": "array",
|
|
67
|
+
"uniqueItems": true,
|
|
68
|
+
"items": {
|
|
69
|
+
"title": "Characteristic",
|
|
70
|
+
"type": "string",
|
|
71
|
+
"enum": ["Battery Level, %", "Input Consumption, W", "Output Consumption, W"]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
50
75
|
}
|
|
51
76
|
}
|
|
52
77
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MqttMessageType } from '../../apis/ecoFlowMqttApi.js';
|
|
2
|
-
import {
|
|
2
|
+
import { BatteryStatusService } from '../../services/batteryStatusService.js';
|
|
3
3
|
import { OutletAcService } from '../../services/outletAcService.js';
|
|
4
4
|
import { OutletCarService } from '../../services/outletCarService.js';
|
|
5
5
|
import { OutletUsbService } from '../../services/outletUsbService.js';
|
|
@@ -11,7 +11,7 @@ export class BatteryAccessory extends EcoFlowAccessoryWithQuota {
|
|
|
11
11
|
outletCarService;
|
|
12
12
|
constructor(platform, accessory, config, log) {
|
|
13
13
|
super(platform, accessory, config, log);
|
|
14
|
-
this.batteryService = new
|
|
14
|
+
this.batteryService = new BatteryStatusService(this);
|
|
15
15
|
this.outletUsbService = new OutletUsbService(this);
|
|
16
16
|
this.outletAcService = new OutletAcService(this);
|
|
17
17
|
this.outletCarService = new OutletCarService(this);
|
|
@@ -69,17 +69,23 @@ export class BatteryAccessory extends EcoFlowAccessoryWithQuota {
|
|
|
69
69
|
if (params.f32ShowSoc !== undefined) {
|
|
70
70
|
this.batteryService.updateStatusLowBattery(params.f32ShowSoc);
|
|
71
71
|
this.batteryService.updateBatteryLevel(params.f32ShowSoc);
|
|
72
|
+
this.outletAcService.updateBatteryLevel(params.f32ShowSoc);
|
|
73
|
+
this.outletUsbService.updateBatteryLevel(params.f32ShowSoc);
|
|
74
|
+
this.outletCarService.updateBatteryLevel(params.f32ShowSoc);
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
updateInvValues(params) {
|
|
75
78
|
if (params.inputWatts !== undefined) {
|
|
76
79
|
this.batteryService.updateChargingState(params.inputWatts);
|
|
80
|
+
this.outletAcService.updateInputConsumption(params.inputWatts);
|
|
81
|
+
this.outletUsbService.updateInputConsumption(params.inputWatts);
|
|
82
|
+
this.outletCarService.updateInputConsumption(params.inputWatts);
|
|
77
83
|
}
|
|
78
84
|
if (params.cfgAcEnabled !== undefined) {
|
|
79
85
|
this.outletAcService.updateState(params.cfgAcEnabled);
|
|
80
86
|
}
|
|
81
87
|
if (params.outputWatts !== undefined) {
|
|
82
|
-
this.outletAcService.
|
|
88
|
+
this.outletAcService.updateOutputConsumption(params.outputWatts);
|
|
83
89
|
}
|
|
84
90
|
}
|
|
85
91
|
updatePdValues(params) {
|
|
@@ -87,7 +93,7 @@ export class BatteryAccessory extends EcoFlowAccessoryWithQuota {
|
|
|
87
93
|
this.outletCarService.updateState(params.carState);
|
|
88
94
|
}
|
|
89
95
|
if (params.carWatts !== undefined) {
|
|
90
|
-
this.outletCarService.
|
|
96
|
+
this.outletCarService.updateOutputConsumption(params.carWatts);
|
|
91
97
|
}
|
|
92
98
|
if (params.dcOutState !== undefined) {
|
|
93
99
|
this.outletUsbService.updateState(params.dcOutState);
|
|
@@ -99,7 +105,7 @@ export class BatteryAccessory extends EcoFlowAccessoryWithQuota {
|
|
|
99
105
|
params.typec1Watts !== undefined ||
|
|
100
106
|
params.typec2Watts !== undefined) {
|
|
101
107
|
const usbWatts = this.getUsbWatts(params.usb1Watts, params.usb2Watts, params.qcUsb1Watts, params.qcUsb2Watts, params.typec1Watts, params.typec2Watts);
|
|
102
|
-
this.outletUsbService.
|
|
108
|
+
this.outletUsbService.updateOutputConsumption(usbWatts);
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
111
|
getUsbWatts(usb1Watts, usb2Watts, qcUsb1Watts, qcUsb2Watts, typec1Watts, typec2Watts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batteryAccessory.js","sourceRoot":"","sources":["../../../src/accessories/batteries/batteryAccessory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAgD,MAAM,8BAA8B,CAAC;AAG7G,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"batteryAccessory.js","sourceRoot":"","sources":["../../../src/accessories/batteries/batteryAccessory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAgD,MAAM,8BAA8B,CAAC;AAG7G,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,MAAM,OAAgB,gBAAiB,SAAQ,yBAA8C;IAC1E,cAAc,CAAuB;IACrC,gBAAgB,CAAmB;IACnC,eAAe,CAAuC;IACtD,gBAAgB,CAAmB;IAEpD,YAAY,QAA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etReplyMessage(message) {
|
|
56
56
|
const messageKey = this.getMqttSetMessageKey(message);
|
|
57
57
|
const command = this.setReplies[messageKey];
|
|
58
|
+
if (!command) {
|
|
59
|
+
this.log.debug('Received "SetReply" response was sent from another instance of homebridge. Ignore it:', message);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
58
62
|
delete this.setReplies[messageKey];
|
|
59
63
|
if (message.data.ack) {
|
|
60
64
|
this.log.warn('Failed to set a value. Reverts value back for:', command.requestMessage.operateType);
|
|
@@ -81,6 +85,9 @@ export class EcoFlowAccessory {
|
|
|
81
85
|
this.log.info('Removing obsolete service from accessory:', service.displayName);
|
|
82
86
|
this.accessory.removeService(service);
|
|
83
87
|
});
|
|
88
|
+
this.services
|
|
89
|
+
.filter(service => this.accessory.services.includes(service.service))
|
|
90
|
+
.forEach(service => service.cleanupCharacteristics());
|
|
84
91
|
}
|
|
85
92
|
async connectMqtt() {
|
|
86
93
|
await this.initMqtt();
|
|
@@ -104,7 +111,9 @@ export class EcoFlowAccessoryWithQuota extends EcoFlowAccessory {
|
|
|
104
111
|
this._quota = await this.httpApi.getAllQuotas();
|
|
105
112
|
}
|
|
106
113
|
await super.initialize();
|
|
107
|
-
|
|
114
|
+
if (this._quota) {
|
|
115
|
+
this.updateInitialValues(this._quota);
|
|
116
|
+
}
|
|
108
117
|
}
|
|
109
118
|
get quota() {
|
|
110
119
|
return this._quota;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecoFlowAccessory.js","sourceRoot":"","sources":["../../src/accessories/ecoFlowAccessory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACL,cAAc,GAKf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AAGzF,MAAM,OAAgB,gBAAgB;IAUlB;IACA;IACA;IACA;IAZC,OAAO,CAAiB;IACxB,OAAO,CAAiB;IACn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AK,IAAI,EAAE;YACnD,uCAAuC;YACvC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;gBAC1B,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxB,CAAC;QACH,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAChB,CAAC;IAEO,KAAK,CAAC,QAAQ;QACpB,IAAI,CAAC,eAAe;YAClB,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBAC/D,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IACvE,CAAC;CACF;AAED,MAAM,OAAgB,yBAAyC,SAAQ,gBAAgB;IAC7E,MAAM,GAAyB,IAAI,CAAC;IAE5B,KAAK,CAAC,UAAU;QAC9B,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,EAAiB,CAAC;QACjE,CAAC;QACD,MAAM,KAAK,CAAC,UAAU,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAO,CAAC;IACtB,CAAC;CAGF"}
|
|
@@ -33,9 +33,10 @@ export interface AcquireCertificateData {
|
|
|
33
33
|
export declare class EcoFlowHttpApi {
|
|
34
34
|
private readonly config;
|
|
35
35
|
private readonly log;
|
|
36
|
+
private readonly apiUrl;
|
|
36
37
|
constructor(config: DeviceConfig, log: Logging);
|
|
37
38
|
getQuotas<TData>(quotas: string[]): Promise<TData>;
|
|
38
|
-
getAllQuotas<TData>(): Promise<TData>;
|
|
39
|
+
getAllQuotas<TData>(): Promise<TData | null>;
|
|
39
40
|
acquireCertificate(): Promise<AcquireCertificateData | null>;
|
|
40
41
|
protected execute<TResponse extends CmdResponse>(relativeUrl: string, method: HttpMethod, queryParameters?: object | null, body?: object | null): Promise<TResponse>;
|
|
41
42
|
private getNonce;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as crypto from 'crypto';
|
|
2
|
-
|
|
2
|
+
import { LocationType } from '../config.js';
|
|
3
|
+
const ApiUrlUs = 'https://api-a.ecoflow.com';
|
|
4
|
+
const ApiUrlEu = 'https://api-e.ecoflow.com';
|
|
3
5
|
const QuotaPath = '/iot-open/sign/device/quota';
|
|
4
6
|
const QuotaAllPath = '/iot-open/sign/device/quota/all';
|
|
5
7
|
const CertificatePath = '/iot-open/sign/certification';
|
|
@@ -11,9 +13,11 @@ export var HttpMethod;
|
|
|
11
13
|
export class EcoFlowHttpApi {
|
|
12
14
|
config;
|
|
13
15
|
log;
|
|
16
|
+
apiUrl;
|
|
14
17
|
constructor(config, log) {
|
|
15
18
|
this.config = config;
|
|
16
19
|
this.log = log;
|
|
20
|
+
this.apiUrl = this.config.location === LocationType.US ? ApiUrlUs : ApiUrlEu;
|
|
17
21
|
}
|
|
18
22
|
async getQuotas(quotas) {
|
|
19
23
|
this.log.debug('Get quotas:', quotas);
|
|
@@ -42,19 +46,18 @@ export class EcoFlowHttpApi {
|
|
|
42
46
|
this.log.debug('All quotas:', data);
|
|
43
47
|
return data;
|
|
44
48
|
}
|
|
45
|
-
return
|
|
49
|
+
return null;
|
|
46
50
|
}
|
|
47
51
|
async acquireCertificate() {
|
|
48
52
|
this.log.debug('Acquire certificate for MQTT connection');
|
|
49
53
|
const response = await this.execute(CertificatePath, HttpMethod.Get);
|
|
50
54
|
if (!response.failed) {
|
|
51
|
-
this.log.debug('Certificate data:', response.data);
|
|
52
55
|
return response.data;
|
|
53
56
|
}
|
|
54
57
|
return null;
|
|
55
58
|
}
|
|
56
59
|
async execute(relativeUrl, method, queryParameters = null, body = null) {
|
|
57
|
-
const url = new URL(relativeUrl,
|
|
60
|
+
const url = new URL(relativeUrl, this.apiUrl);
|
|
58
61
|
const accessKey = this.config.accessKey;
|
|
59
62
|
const nonce = this.getNonce();
|
|
60
63
|
const timestamp = Date.now();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecoFlowHttpApi.js","sourceRoot":"","sources":["../../src/apis/ecoFlowHttpApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"ecoFlowHttpApi.js","sourceRoot":"","sources":["../../src/apis/ecoFlowHttpApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAgB,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,MAAM,QAAQ,GAAG,2BAA2B,CAAC;AAC7C,MAAM,QAAQ,GAAG,2BAA2B,CAAC;AAC7C,MAAM,SAAS,GAAG,6BAA6B,CAAC;AAChD,MAAM,YAAY,GAAG,iCAAiC,CAAC;AACvD,MAAM,eAAe,GAAG,8BAA8B,CAAC;AAEvD,MAAM,CAAN,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,2BAAa,CAAA;AACf,CAAC,EAHW,UAAU,KAAV,UAAU,QAGrB;AAuCD,MAAM,OAAO,cAAc;IAGN;IACA;IAHF,MAAM,CAAS;IAChC,YACmB,MAAoB,EACpB,GAAY;QADZ,WAAM,GAAN,MAAM,CAAc;QACpB,QAAG,GAAH,GAAG,CAAS;QAE7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC/E,CAAC;IAEM,KAAK,CAAC,SAAS,CAAQ,MAAgB;QAC5C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,a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ridge';
|
|
2
|
+
export declare const InputConsumptionWattFactory: (hap: HAP) => WithUUID<{
|
|
3
|
+
new (): Characteristic;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const OutputConsumptionWattFactory: (hap: HAP) => WithUUID<{
|
|
6
|
+
new (): Characteristic;
|
|
7
|
+
}>;
|
|
8
|
+
export declare class PowerConsumption {
|
|
9
|
+
static InputConsumptionWatts: WithUUID<{
|
|
10
|
+
new (): Characteristic;
|
|
11
|
+
}>;
|
|
12
|
+
static OutputConsumptionWatts: WithUUID<{
|
|
13
|
+
new (): Characteristic;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export declare class CustomCharacteristics {
|
|
17
|
+
static readonly PowerConsumption: typeof PowerConsumption;
|
|
18
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export const InputConsumptionWattFactory = (hap) => {
|
|
2
|
+
return class InputConsumptionWatt extends hap.Characteristic {
|
|
3
|
+
static UUID = '13172B0A-D346-4730-9732-32EF5B6EF8B7';
|
|
4
|
+
constructor() {
|
|
5
|
+
super('Input Consumption', InputConsumptionWatt.UUID, {
|
|
6
|
+
description: 'Input Consumption, W',
|
|
7
|
+
format: "float" /* Formats.FLOAT */,
|
|
8
|
+
perms: ["ev" /* Perms.NOTIFY */, "pr" /* Perms.PAIRED_READ */],
|
|
9
|
+
minValue: 0,
|
|
10
|
+
minStep: 1,
|
|
11
|
+
unit: "celsius" /* Units.CELSIUS */, // To allow setting numeric value for conditions in ShortCuts
|
|
12
|
+
});
|
|
13
|
+
this.value = this.getDefaultValue();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export const OutputConsumptionWattFactory = (hap) => {
|
|
18
|
+
return class OutputConsumptionWatt extends hap.Characteristic {
|
|
19
|
+
// Eve characteristic
|
|
20
|
+
static UUID = 'E863F10D-079E-48FF-8F27-9C2605A29F52';
|
|
21
|
+
constructor() {
|
|
22
|
+
super('Output Consumption', OutputConsumptionWatt.UUID, {
|
|
23
|
+
description: 'Output Consumption, W',
|
|
24
|
+
format: "float" /* Formats.FLOAT */,
|
|
25
|
+
perms: ["ev" /* Perms.NOTIFY */, "pr" /* Perms.PAIRED_READ */],
|
|
26
|
+
unit: "celsius" /* Units.CELSIUS */, // To allow setting numeric value for conditions in ShortCuts
|
|
27
|
+
minValue: 0,
|
|
28
|
+
minStep: 1,
|
|
29
|
+
});
|
|
30
|
+
this.value = this.getDefaultValue();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
// https://gist.github.com/simont77/3f4d4330fa55b83f8ca96388d9004e7d
|
|
35
|
+
// export const PowerConsumptionVoltFactory = (hap: HAP): WithUUID<{ new (): Characteristic }> => {
|
|
36
|
+
// return class PowerConsumptionVolt extends hap.Characteristic {
|
|
37
|
+
// public static readonly UUID: string = 'E863F10A-079E-48FF-8F27-9C2605A29F52';
|
|
38
|
+
// constructor() {
|
|
39
|
+
// super('Voltage', PowerConsumptionVolt.UUID, {
|
|
40
|
+
// description: '"Voltage, V" in Eve App',
|
|
41
|
+
// format: Formats.FLOAT,
|
|
42
|
+
// perms: [Perms.NOTIFY, Perms.PAIRED_READ],
|
|
43
|
+
// minValue: 0,
|
|
44
|
+
// maxValue: 300,
|
|
45
|
+
// });
|
|
46
|
+
// this.value = this.getDefaultValue();
|
|
47
|
+
// }
|
|
48
|
+
// };
|
|
49
|
+
// };
|
|
50
|
+
// export const PowerConsumptionAmpereFactory = (hap: HAP): WithUUID<{ new (): Characteristic }> => {
|
|
51
|
+
// return class PowerConsumptionAmpere extends hap.Characteristic {
|
|
52
|
+
// public static readonly UUID: string = 'E863F126-079E-48FF-8F27-9C2605A29F52';
|
|
53
|
+
// constructor() {
|
|
54
|
+
// super('Current', PowerConsumptionAmpere.UUID, {
|
|
55
|
+
// description: '"Current, A" in Eve App',
|
|
56
|
+
// format: Formats.FLOAT,
|
|
57
|
+
// perms: [Perms.NOTIFY, Perms.PAIRED_READ],
|
|
58
|
+
// minValue: 0,
|
|
59
|
+
// maxValue: 100,
|
|
60
|
+
// });
|
|
61
|
+
// this.value = this.getDefaultValue();
|
|
62
|
+
// }
|
|
63
|
+
// };
|
|
64
|
+
// };
|
|
65
|
+
// export const PowerConsumptionKilowattHourFactory = (hap: HAP): WithUUID<{ new (): Characteristic }> => {
|
|
66
|
+
// return class PowerConsumptionKilowattHour extends hap.Characteristic {
|
|
67
|
+
// public static readonly UUID: string = 'E863F10C-079E-48FF-8F27-9C2605A29F52';
|
|
68
|
+
// constructor() {
|
|
69
|
+
// super('Total Consumption', PowerConsumptionKilowattHour.UUID, {
|
|
70
|
+
// description: '"Total Consumption, kW/h" in Eve App',
|
|
71
|
+
// format: Formats.FLOAT,
|
|
72
|
+
// perms: [Perms.NOTIFY, Perms.PAIRED_READ],
|
|
73
|
+
// minValue: 0,
|
|
74
|
+
// maxValue: 50,
|
|
75
|
+
// });
|
|
76
|
+
// this.value = this.getDefaultValue();
|
|
77
|
+
// }
|
|
78
|
+
// };
|
|
79
|
+
// };
|
|
80
|
+
export class PowerConsumption {
|
|
81
|
+
static InputConsumptionWatts;
|
|
82
|
+
static OutputConsumptionWatts;
|
|
83
|
+
}
|
|
84
|
+
export class CustomCharacteristics {
|
|
85
|
+
static PowerConsumption = PowerConsumption;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=CustomCharacteristic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomCharacteristic.js","sourceRoot":"","sources":["../../src/characteristics/CustomCharacteristic.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAQ,EAAwC,EAAE;IAC5F,OAAO,MAAM,oBAAqB,SAAQ,GAAG,CAAC,cAAc;QACnD,MAAM,CAAU,IAAI,GAAW,sCAAsC,CAAC;QAC7E;YACE,KAAK,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,IAAI,EAAE;gBACpD,WAAW,EAAE,sBAAsB;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3E,oFAAoF;AACpF,sBAAsB;AACtB,wEAAwE;AACxE,+DAA+D;AAC/D,iCAAiC;AACjC,oDAAoD;AACpD,uBAAuB;AACvB,wBAAwB;AACxB,YAAY;AACZ,6CAA6C;AAC7C,QAAQ;AACR,OAAO;AACP,KAAK;AAEL,MAAM,OAAO,gBAAgB;IACpB,MAAM,CAAC,qBAAqB,CAAuC;IACnE,MAAM,CAAC,sBAAsB,CAAuC;CAC5E;AAED,MAAM,OAAO,qBAAqB;IACzB,MAAM,CAAU,gBAAgB,GAA4B,gBAAgB,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -6,9 +6,23 @@ export declare enum DeviceModel {
|
|
|
6
6
|
Delta2Max = "Delta 2 Max",
|
|
7
7
|
Delta2 = "Delta 2"
|
|
8
8
|
}
|
|
9
|
+
export declare enum LocationType {
|
|
10
|
+
EU = "EU",
|
|
11
|
+
US = "US"
|
|
12
|
+
}
|
|
9
13
|
export interface DeviceConfig extends AccessoryConfig {
|
|
10
14
|
model: DeviceModel;
|
|
11
15
|
serialNumber: string;
|
|
16
|
+
location: LocationType;
|
|
12
17
|
accessKey: string;
|
|
13
18
|
secretKey: string;
|
|
19
|
+
battery?: BatteryDeviceConfig;
|
|
20
|
+
}
|
|
21
|
+
export interface BatteryDeviceConfig {
|
|
22
|
+
additionalCharacteristics: AdditionalBatteryCharacteristicType[];
|
|
23
|
+
}
|
|
24
|
+
export declare enum AdditionalBatteryCharacteristicType {
|
|
25
|
+
BatteryLevel = "Battery Level, %",
|
|
26
|
+
InputConsumptionInWatts = "Input Consumption, W",
|
|
27
|
+
OutputConsumptionInWatts = "Output Consumption, W"
|
|
14
28
|
}
|
package/dist/config.js
CHANGED
|
@@ -3,4 +3,15 @@ export var DeviceModel;
|
|
|
3
3
|
DeviceModel["Delta2Max"] = "Delta 2 Max";
|
|
4
4
|
DeviceModel["Delta2"] = "Delta 2";
|
|
5
5
|
})(DeviceModel || (DeviceModel = {}));
|
|
6
|
+
export var LocationType;
|
|
7
|
+
(function (LocationType) {
|
|
8
|
+
LocationType["EU"] = "EU";
|
|
9
|
+
LocationType["US"] = "US";
|
|
10
|
+
})(LocationType || (LocationType = {}));
|
|
11
|
+
export var AdditionalBatteryCharacteristicType;
|
|
12
|
+
(function (AdditionalBatteryCharacteristicType) {
|
|
13
|
+
AdditionalBatteryCharacteristicType["BatteryLevel"] = "Battery Level, %";
|
|
14
|
+
AdditionalBatteryCharacteristicType["InputConsumptionInWatts"] = "Input Consumption, W";
|
|
15
|
+
AdditionalBatteryCharacteristicType["OutputConsumptionInWatts"] = "Output Consumption, W";
|
|
16
|
+
})(AdditionalBatteryCharacteristicType || (AdditionalBatteryCharacteristicType = {}));
|
|
6
17
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,iCAAkB,CAAA;AACpB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB"}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,iCAAkB,CAAA;AACpB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB;AAED,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,yBAAS,CAAA;IACT,yBAAS,CAAA;AACX,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAeD,MAAM,CAAN,IAAY,mCAIX;AAJD,WAAY,mCAAmC;IAC7C,wEAAiC,CAAA;IACjC,uFAAgD,CAAA;IAChD,yFAAkD,CAAA;AACpD,CAAC,EAJW,mCAAmC,KAAnC,mCAAmC,QAI9C"}
|
package/dist/helpers/logger.js
CHANGED
|
@@ -13,27 +13,27 @@ export class Logger {
|
|
|
13
13
|
}
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
15
|
info(message, ...parameters) {
|
|
16
|
-
this.logger.info(this.wrapMessage(message), parameters);
|
|
16
|
+
this.logger.info(this.wrapMessage(message), ...parameters);
|
|
17
17
|
}
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
19
|
success(message, ...parameters) {
|
|
20
|
-
this.logger.success(this.wrapMessage(message), parameters);
|
|
20
|
+
this.logger.success(this.wrapMessage(message), ...parameters);
|
|
21
21
|
}
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
23
|
warn(message, ...parameters) {
|
|
24
|
-
this.logger.warn(this.wrapMessage(message), parameters);
|
|
24
|
+
this.logger.warn(this.wrapMessage(message), ...parameters);
|
|
25
25
|
}
|
|
26
26
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
27
|
error(message, ...parameters) {
|
|
28
|
-
this.logger.error(this.wrapMessage(message), parameters);
|
|
28
|
+
this.logger.error(this.wrapMessage(message), ...parameters);
|
|
29
29
|
}
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
31
|
debug(message, ...parameters) {
|
|
32
|
-
this.logger.debug(this.wrapMessage(message), parameters);
|
|
32
|
+
this.logger.debug(this.wrapMessage(message), ...parameters);
|
|
33
33
|
}
|
|
34
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
35
|
log(level, message, ...parameters) {
|
|
36
|
-
this.logger.log(level, this.wrapMessage(message), parameters);
|
|
36
|
+
this.logger.log(level, this.wrapMessage(message), ...parameters);
|
|
37
37
|
}
|
|
38
38
|
wrapMessage(message) {
|
|
39
39
|
return `[${this.deviceName}] ${message}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/helpers/logger.ts"],"names":[],"mappings":"A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AE,GAAG,UAAU,CAAC,CAAC;IAChE,CAAC;IAED,8DAA8D;IACvD,IAAI,CAAC,OAAe,EAAE,GAAG,UAAiB;QAC/C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC;IAC7D,CAAC;IAED,8DAA8D;IACvD,KAAK,CAAC,OAAe,EAAE,GAAG,UAAiB;QAChD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC;IAC9D,CAAC;IAED,8DAA8D;IACvD,KAAK,CAAC,OAAe,EAAE,GAAG,UAAiB;QAChD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC;IAC9D,CAAC;IAED,8DAA8D;IACvD,GAAG,CAAC,KAAe,EAAE,OAAe,EAAE,GAAG,UAAiB;QAC/D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC;IACnE,CAAC;IAEO,WAAW,CAAC,OAAe;QACjC,OAAO,IAAI,IAAI,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;IAC3C,CAAC;CACF"}
|
package/dist/platform.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import { API, Characteristic, DynamicPlatformPlugin, Logging, PlatformAccessory, PlatformConfig, Service, UnknownContext } from 'homebridge';
|
|
2
|
+
import { EcoFlowAccessory } from './accessories/ecoFlowAccessory.js';
|
|
3
|
+
import { CustomCharacteristics } from './characteristics/CustomCharacteristic.js';
|
|
2
4
|
import { DeviceConfig } from './config.js';
|
|
3
5
|
/**
|
|
4
6
|
* HomebridgePlatform
|
|
5
7
|
* This class is the main constructor for your plugin, this is where you should
|
|
6
8
|
* parse the user config and discover/register accessories with Homebridge.
|
|
7
9
|
*/
|
|
10
|
+
export type EcoFlowCharacteristic = typeof Characteristic & typeof CustomCharacteristics;
|
|
8
11
|
export declare class EcoFlowHomebridgePlatform implements DynamicPlatformPlugin {
|
|
9
12
|
private readonly commonLog;
|
|
10
13
|
readonly config: PlatformConfig;
|
|
11
14
|
readonly api: API;
|
|
12
15
|
private readonly ecoFlowConfig;
|
|
13
16
|
readonly Service: typeof Service;
|
|
14
|
-
readonly Characteristic:
|
|
17
|
+
readonly Characteristic: EcoFlowCharacteristic;
|
|
15
18
|
readonly accessories: PlatformAccessory[];
|
|
16
19
|
constructor(commonLog: Logging, config: PlatformConfig, api: API);
|
|
20
|
+
private static InitCustomCharacteristics;
|
|
17
21
|
/**
|
|
18
22
|
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
|
19
23
|
* It should be used to set up event handlers for characteristics and update respective values.
|
|
20
24
|
*/
|
|
21
25
|
configureAccessory(accessory: PlatformAccessory): void;
|
|
22
26
|
registerDevices(): void;
|
|
23
|
-
cleanupDevices(configuredAccessories: PlatformAccessory[], logs: Record<string, Logging>): void;
|
|
24
|
-
createAccessory(accessory: PlatformAccessory<UnknownContext>, config: DeviceConfig, log: Logging):
|
|
27
|
+
cleanupDevices(configuredAccessories: PlatformAccessory[], configuredEcoFlowAccessories: EcoFlowAccessory[], logs: Record<string, Logging>): void;
|
|
28
|
+
createAccessory(accessory: PlatformAccessory<UnknownContext>, config: DeviceConfig, log: Logging): EcoFlowAccessory | null;
|
|
25
29
|
}
|
package/dist/platform.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { Delta2Accessory } from './accessories/batteries/delta2Accessory.js';
|
|
2
2
|
import { Delta2MaxAccessory } from './accessories/batteries/delta2maxAccessory.js';
|
|
3
|
+
import { CustomCharacteristics, InputConsumptionWattFactory, OutputConsumptionWattFactory, } from './characteristics/CustomCharacteristic.js';
|
|
3
4
|
import { DeviceModel } from './config.js';
|
|
4
5
|
import { Logger } from './helpers/logger.js';
|
|
5
6
|
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
|
|
6
|
-
/**
|
|
7
|
-
* HomebridgePlatform
|
|
8
|
-
* This class is the main constructor for your plugin, this is where you should
|
|
9
|
-
* parse the user config and discover/register accessories with Homebridge.
|
|
10
|
-
*/
|
|
11
7
|
export class EcoFlowHomebridgePlatform {
|
|
12
8
|
commonLog;
|
|
13
9
|
config;
|
|
@@ -21,9 +17,13 @@ export class EcoFlowHomebridgePlatform {
|
|
|
21
17
|
this.commonLog = commonLog;
|
|
22
18
|
this.config = config;
|
|
23
19
|
this.api = api;
|
|
20
|
+
EcoFlowHomebridgePlatform.InitCustomCharacteristics(api.hap);
|
|
24
21
|
this.ecoFlowConfig = this.config;
|
|
25
22
|
this.Service = api.hap.Service;
|
|
26
|
-
this.Characteristic =
|
|
23
|
+
this.Characteristic = {
|
|
24
|
+
...api.hap.Characteristic,
|
|
25
|
+
...CustomCharacteristics,
|
|
26
|
+
};
|
|
27
27
|
this.commonLog.debug('Finished initializing platform:', this.config.platform);
|
|
28
28
|
// Homebridge 1.8.0 introduced a `log.success` method that can be used to log success messages
|
|
29
29
|
// For users that are on a version prior to 1.8.0, we need a 'polyfill' for this method
|
|
@@ -39,6 +39,10 @@ export class EcoFlowHomebridgePlatform {
|
|
|
39
39
|
this.registerDevices();
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
+
static InitCustomCharacteristics(hap) {
|
|
43
|
+
CustomCharacteristics.PowerConsumption.InputConsumptionWatts = InputConsumptionWattFactory(hap);
|
|
44
|
+
CustomCharacteristics.PowerConsumption.OutputConsumptionWatts = OutputConsumptionWattFactory(hap);
|
|
45
|
+
}
|
|
42
46
|
/**
|
|
43
47
|
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
|
44
48
|
* It should be used to set up event handlers for characteristics and update respective values.
|
|
@@ -51,6 +55,7 @@ export class EcoFlowHomebridgePlatform {
|
|
|
51
55
|
registerDevices() {
|
|
52
56
|
const logs = {};
|
|
53
57
|
const configuredAccessories = [];
|
|
58
|
+
const configuredEcoFlowAccessories = [];
|
|
54
59
|
if (!this.ecoFlowConfig.devices) {
|
|
55
60
|
return;
|
|
56
61
|
}
|
|
@@ -68,29 +73,41 @@ export class EcoFlowHomebridgePlatform {
|
|
|
68
73
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
69
74
|
// the cached devices we stored in the `configureAccessory` method above
|
|
70
75
|
let accessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
76
|
+
let ecoFlowAccessory = null;
|
|
71
77
|
if (accessory) {
|
|
72
78
|
log.info('Restoring existing accessory from cache');
|
|
73
|
-
this.createAccessory(accessory, config, log);
|
|
79
|
+
ecoFlowAccessory = this.createAccessory(accessory, config, log);
|
|
74
80
|
}
|
|
75
81
|
else {
|
|
76
82
|
log.info('Adding new accessory');
|
|
77
83
|
accessory = new this.api.platformAccessory(config.name, uuid);
|
|
78
84
|
accessory.context.deviceConfig = config;
|
|
79
|
-
this.createAccessory(accessory, config, log);
|
|
85
|
+
ecoFlowAccessory = this.createAccessory(accessory, config, log);
|
|
80
86
|
// link the accessory to your platform
|
|
81
87
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
82
88
|
}
|
|
83
89
|
configuredAccessories.push(accessory);
|
|
90
|
+
if (ecoFlowAccessory) {
|
|
91
|
+
configuredEcoFlowAccessories.push(ecoFlowAccessory);
|
|
92
|
+
}
|
|
84
93
|
logs[accessory.displayName] = log;
|
|
85
94
|
}
|
|
86
|
-
this.cleanupDevices(configuredAccessories, logs);
|
|
95
|
+
this.cleanupDevices(configuredAccessories, configuredEcoFlowAccessories, logs);
|
|
87
96
|
}
|
|
88
|
-
cleanupDevices(configuredAccessories, logs) {
|
|
97
|
+
cleanupDevices(configuredAccessories, configuredEcoFlowAccessories, logs) {
|
|
98
|
+
const removedAccessories = [];
|
|
89
99
|
this.accessories
|
|
90
100
|
.filter(accessory => !configuredAccessories.includes(accessory))
|
|
91
101
|
.forEach(accessory => {
|
|
92
102
|
logs[accessory.displayName].info('Removing obsolete accessory');
|
|
93
103
|
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
104
|
+
removedAccessories.push(accessory);
|
|
105
|
+
});
|
|
106
|
+
configuredEcoFlowAccessories
|
|
107
|
+
.filter(ecoFlowAccessory => !removedAccessories.includes(ecoFlowAccessory.accessory))
|
|
108
|
+
.forEach(ecoFlowAccessory => {
|
|
109
|
+
logs[ecoFlowAccessory.accessory.displayName].info('Initializing accessory');
|
|
110
|
+
ecoFlowAccessory.initialize();
|
|
94
111
|
});
|
|
95
112
|
}
|
|
96
113
|
createAccessory(accessory, config, log) {
|
|
@@ -105,7 +122,7 @@ export class EcoFlowHomebridgePlatform {
|
|
|
105
122
|
default:
|
|
106
123
|
log.warn(`"${config.model}" is not supported. Ignoring the device`);
|
|
107
124
|
}
|
|
108
|
-
ecoFlowAccessory
|
|
125
|
+
return ecoFlowAccessory;
|
|
109
126
|
}
|
|
110
127
|
}
|
|
111
128
|
//# sourceMappingURL=platform.js.map
|
package/dist/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AAEnF,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAgB,WAAW,EAAiB,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,WAAW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 +1,7 @@
|
|
|
1
|
-
import { Service } from 'homebridge';
|
|
1
|
+
import { Characteristic, Service } from 'homebridge';
|
|
2
2
|
import { ServiceBase } from './serviceBase.js';
|
|
3
3
|
export declare class AccessoryInformationService extends ServiceBase {
|
|
4
4
|
protected createService(): Service;
|
|
5
|
+
protected addCharacteristics(): Characteristic[];
|
|
5
6
|
private getVersion;
|
|
6
7
|
}
|
|
@@ -4,14 +4,22 @@ import { fileURLToPath } from 'url';
|
|
|
4
4
|
import { ServiceBase } from './serviceBase.js';
|
|
5
5
|
export class AccessoryInformationService extends ServiceBase {
|
|
6
6
|
createService() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.
|
|
12
|
-
.
|
|
13
|
-
.
|
|
14
|
-
|
|
7
|
+
return this.getOrAddService(this.platform.Service.AccessoryInformation, 'Information');
|
|
8
|
+
}
|
|
9
|
+
addCharacteristics() {
|
|
10
|
+
const characteristics = [
|
|
11
|
+
this.addCharacteristic(this.platform.Characteristic.Manufacturer),
|
|
12
|
+
this.addCharacteristic(this.platform.Characteristic.Model),
|
|
13
|
+
this.addCharacteristic(this.platform.Characteristic.SerialNumber),
|
|
14
|
+
this.addCharacteristic(this.platform.Characteristic.FirmwareRevision),
|
|
15
|
+
this.addCharacteristic(this.platform.Characteristic.Identify),
|
|
16
|
+
];
|
|
17
|
+
this.service
|
|
18
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'EcoFlow')
|
|
19
|
+
.setCharacteristic(this.platform.Characteristic.Model, this.ecoFlowAccessory.config.model)
|
|
20
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, this.ecoFlowAccessory.config.serialNumber)
|
|
21
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.getVersion());
|
|
22
|
+
return characteristics;
|
|
15
23
|
}
|
|
16
24
|
getVersion() {
|
|
17
25
|
const filename = fileURLToPath(import.meta.url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessoryInformationService.js","sourceRoot":"","sources":["../../src/services/accessoryInformationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,2BAA4B,SAAQ,WAAW;IACvC,aAAa;QAC9B,
|
|
1
|
+
{"version":3,"file":"accessoryInformationService.js","sourceRoot":"","sources":["../../src/services/accessoryInformationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,2BAA4B,SAAQ,WAAW;IACvC,aAAa;QAC9B,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;IACzF,CAAC;IAEkB,kBAAkB;QACnC,MAAM,eAAe,GAAG;YACtB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,CAAC;YACjE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC;YAC1D,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,CAAC;YACjE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC;YACrE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC;SAC9D,CAAC;QAEF,IAAI,CAAC,OAAO;aACT,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,SAAS,CAAC;aACvE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC;aACzF,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,YAAY,CAAC;aACvG,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,gBAAgB,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QACvF,OAAO,eAAe,CAAC;IACzB,CAAC;IAEO,UAAU;QAChB,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvC,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;QACpE,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;QACzE,OAAO,WAAW,EAAE,OAAO,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Service } from 'homebridge';
|
|
1
|
+
import { Characteristic, Service } from 'homebridge';
|
|
2
2
|
import { ServiceBase } from './serviceBase.js';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class BatteryStatusService extends ServiceBase {
|
|
4
4
|
protected createService(): Service;
|
|
5
|
+
protected addCharacteristics(): Characteristic[];
|
|
5
6
|
updateStatusLowBattery(batteryLevel: number): void;
|
|
6
7
|
updateBatteryLevel(batteryLevel: number): void;
|
|
7
8
|
updateChargingState(chargingPower: number): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ServiceBase } from './serviceBase.js';
|
|
2
|
+
export class BatteryStatusService extends ServiceBase {
|
|
3
|
+
createService() {
|
|
4
|
+
return this.getOrAddService(this.platform.Service.Battery, this.ecoFlowAccessory.config.name);
|
|
5
|
+
}
|
|
6
|
+
addCharacteristics() {
|
|
7
|
+
return [
|
|
8
|
+
this.addCharacteristic(this.platform.Characteristic.StatusLowBattery),
|
|
9
|
+
this.addCharacteristic(this.platform.Characteristic.BatteryLevel),
|
|
10
|
+
this.addCharacteristic(this.platform.Characteristic.ChargingState),
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
updateStatusLowBattery(batteryLevel) {
|
|
14
|
+
const statusLowBattery = batteryLevel < 20;
|
|
15
|
+
this.log.debug('Status Low Battery ->', statusLowBattery);
|
|
16
|
+
this.service
|
|
17
|
+
.getCharacteristic(this.platform.Characteristic.StatusLowBattery)
|
|
18
|
+
.updateValue(statusLowBattery
|
|
19
|
+
? this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
20
|
+
: this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL);
|
|
21
|
+
}
|
|
22
|
+
updateBatteryLevel(batteryLevel) {
|
|
23
|
+
this.log.debug('BatteryLevel ->', batteryLevel);
|
|
24
|
+
this.service.getCharacteristic(this.platform.Characteristic.BatteryLevel).updateValue(batteryLevel);
|
|
25
|
+
}
|
|
26
|
+
updateChargingState(chargingPower) {
|
|
27
|
+
const isCharging = chargingPower > 0;
|
|
28
|
+
this.log.debug('ChargingState ->', isCharging);
|
|
29
|
+
this.service.getCharacteristic(this.platform.Characteristic.ChargingState).updateValue(isCharging);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=batteryStatusService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batteryStatusService.js","sourceRoot":"","sources":["../../src/services/batteryStatusService.ts"],"names":[],"mappings":"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,CAAC,CAAC;IACtG,CAAC;IAEM,mBAAmB,CAAC,aAAqB;QAC9C,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,QAAQ,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACrG,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Service } from 'homebridge';
|
|
1
|
+
import { Characteristic, CharacteristicValue, Service, WithUUID } from 'homebridge';
|
|
2
2
|
import { EcoFlowAccessory } from '../accessories/ecoFlowAccessory.js';
|
|
3
3
|
import { ServiceBase } from './serviceBase.js';
|
|
4
4
|
export interface MqttSetEnabledMessageParams {
|
|
@@ -8,10 +8,17 @@ export declare abstract class OutletsServiceBase extends ServiceBase {
|
|
|
8
8
|
private readonly serviceSubType;
|
|
9
9
|
constructor(serviceSubType: string, ecoFlowAccessory: EcoFlowAccessory);
|
|
10
10
|
updateState(state: boolean): void;
|
|
11
|
-
|
|
11
|
+
updateOutputConsumption(watt: number): void;
|
|
12
|
+
updateInputConsumption(watt: number): void;
|
|
13
|
+
updateBatteryLevel(batteryLevel: number): void;
|
|
12
14
|
protected createService(): Service;
|
|
15
|
+
protected addCharacteristics(): Characteristic[];
|
|
13
16
|
protected abstract setOn(value: boolean, revert: () => void): Promise<void>;
|
|
14
17
|
protected sendOn<TParams>(moduleType: number, operateType: string, params: TParams, revert: () => void): Promise<void>;
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
protected updateCharacteristic(characteristic: WithUUID<{
|
|
19
|
+
new (): Characteristic;
|
|
20
|
+
}>, name: string, value: CharacteristicValue): void;
|
|
21
|
+
private tryAddCustomCharacteristic;
|
|
22
|
+
private updateCustomCharacteristic;
|
|
23
|
+
private get serviceName();
|
|
17
24
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AdditionalBatteryCharacteristicType as CharacteristicType } from '../config.js';
|
|
1
2
|
import { ServiceBase } from './serviceBase.js';
|
|
2
3
|
export class OutletsServiceBase extends ServiceBase {
|
|
3
4
|
serviceSubType;
|
|
@@ -6,33 +7,56 @@ export class OutletsServiceBase extends ServiceBase {
|
|
|
6
7
|
this.serviceSubType = serviceSubType;
|
|
7
8
|
}
|
|
8
9
|
updateState(state) {
|
|
9
|
-
this.
|
|
10
|
-
this.service.getCharacteristic(this.ecoFlowAccessory.platform.Characteristic.On).updateValue(state);
|
|
10
|
+
this.updateCharacteristic(this.platform.Characteristic.On, 'State', state);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
12
|
+
updateOutputConsumption(watt) {
|
|
13
|
+
this.updateCharacteristic(this.platform.Characteristic.OutletInUse, 'InUse', watt > 0);
|
|
14
|
+
this.updateCustomCharacteristic(this.platform.Characteristic.PowerConsumption.OutputConsumptionWatts, 'Output Consumption, W', watt, CharacteristicType.OutputConsumptionInWatts);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.addCharacteristics(service);
|
|
19
|
-
return service;
|
|
16
|
+
updateInputConsumption(watt) {
|
|
17
|
+
this.updateCustomCharacteristic(this.platform.Characteristic.PowerConsumption.InputConsumptionWatts, 'Input Consumption, W', watt, CharacteristicType.InputConsumptionInWatts);
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
updateBatteryLevel(batteryLevel) {
|
|
20
|
+
this.updateCustomCharacteristic(this.platform.Characteristic.BatteryLevel, 'Battery Level, %', batteryLevel, CharacteristicType.BatteryLevel);
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
createService() {
|
|
23
|
+
return this.getOrAddServiceById(this.platform.Service.Outlet, this.serviceName, this.serviceSubType);
|
|
24
|
+
}
|
|
25
|
+
addCharacteristics() {
|
|
26
|
+
const onCharacteristic = this.addCharacteristic(this.platform.Characteristic.On);
|
|
27
|
+
onCharacteristic.onSet(value => {
|
|
26
28
|
const newValue = value;
|
|
27
29
|
this.setOn(newValue, () => this.updateState(!newValue));
|
|
28
30
|
});
|
|
31
|
+
const characteristics = [
|
|
32
|
+
this.addCharacteristic(this.platform.Characteristic.OutletInUse),
|
|
33
|
+
onCharacteristic,
|
|
34
|
+
this.tryAddCustomCharacteristic(this.platform.Characteristic.PowerConsumption.InputConsumptionWatts, CharacteristicType.InputConsumptionInWatts),
|
|
35
|
+
this.tryAddCustomCharacteristic(this.platform.Characteristic.PowerConsumption.OutputConsumptionWatts, CharacteristicType.OutputConsumptionInWatts),
|
|
36
|
+
this.tryAddCustomCharacteristic(this.platform.Characteristic.BatteryLevel, CharacteristicType.BatteryLevel),
|
|
37
|
+
];
|
|
38
|
+
this.service.setCharacteristic(this.platform.Characteristic.Name, this.serviceName);
|
|
39
|
+
return characteristics.filter(characteristic => characteristic !== null);
|
|
40
|
+
}
|
|
41
|
+
sendOn(moduleType, operateType, params, revert) {
|
|
42
|
+
return this.ecoFlowAccessory.sendSetCommand(moduleType, operateType, params, revert);
|
|
43
|
+
}
|
|
44
|
+
updateCharacteristic(characteristic, name, value) {
|
|
45
|
+
super.updateCharacteristic(characteristic, `${this.serviceSubType} ${name}`, value);
|
|
46
|
+
}
|
|
47
|
+
tryAddCustomCharacteristic(characteristic, characteristicType) {
|
|
48
|
+
if (this.ecoFlowAccessory.config.battery?.additionalCharacteristics?.includes(characteristicType)) {
|
|
49
|
+
return this.addCharacteristic(characteristic);
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
updateCustomCharacteristic(characteristic, name, value, characteristicType) {
|
|
54
|
+
if (this.ecoFlowAccessory.config.battery?.additionalCharacteristics?.includes(characteristicType)) {
|
|
55
|
+
super.updateCharacteristic(characteristic, name, value);
|
|
56
|
+
}
|
|
29
57
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const service = this.ecoFlowAccessory.accessory.getServiceById(this.ecoFlowAccessory.platform.Service.Outlet, serviceSubType) ||
|
|
33
|
-
this.ecoFlowAccessory.accessory.addService(this.ecoFlowAccessory.platform.Service.Outlet, serviceName, serviceSubType);
|
|
34
|
-
service.setCharacteristic(this.ecoFlowAccessory.platform.Characteristic.Name, serviceName);
|
|
35
|
-
return service;
|
|
58
|
+
get serviceName() {
|
|
59
|
+
return `${this.ecoFlowAccessory.config.name} ${this.serviceSubType}`;
|
|
36
60
|
}
|
|
37
61
|
}
|
|
38
62
|
//# sourceMappingURL=outletServiceBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outletServiceBase.js","sourceRoot":"","sources":["../../src/services/outletServiceBase.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAM/C,MAAM,OAAgB,kBAAmB,SAAQ,WAAW;IAEvC;IADnB,YACmB,cAAsB,EACvC,gBAAkC;QAElC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAHP,mBAAc,GAAd,cAAc,CAAQ;IAIzC,CAAC;IAEM,WAAW,CAAC,KAAc;QAC/B,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"outletServiceBase.js","sourceRoot":"","sources":["../../src/services/outletServiceBase.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mCAAmC,IAAI,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAM/C,MAAM,OAAgB,kBAAmB,SAAQ,WAAW;IAEvC;IADnB,YACmB,cAAsB,EACvC,gBAAkC;QAElC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAHP,mBAAc,GAAd,cAAc,CAAQ;IAIzC,CAAC;IAEM,WAAW,CAAC,KAAc;QAC/B,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CA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AAC,OAAO,EAAE,yBAAyB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAClG,OAAO,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,0BAA0B,CAChC,cAAoD,EACpD,IAAY,EACZ,KAA0B,EAC1B,kBAAsC;QAEtC,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,yBAAyB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAClG,KAAK,CAAC,oBAAoB,CAAC,cAAc,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,IAAY,WAAW;QACrB,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;IACvE,CAAC;CACF"}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import { Logging, Service } from 'homebridge';
|
|
1
|
+
import { Characteristic, CharacteristicValue, Logging, Service, WithUUID } from 'homebridge';
|
|
2
2
|
import { EcoFlowAccessory } from '../accessories/ecoFlowAccessory.js';
|
|
3
|
+
import { EcoFlowHomebridgePlatform } from '../platform.js';
|
|
3
4
|
export declare abstract class ServiceBase {
|
|
4
5
|
protected readonly ecoFlowAccessory: EcoFlowAccessory;
|
|
5
6
|
protected readonly log: Logging;
|
|
7
|
+
protected readonly platform: EcoFlowHomebridgePlatform;
|
|
8
|
+
protected characteristics: Characteristic[];
|
|
6
9
|
private _service;
|
|
7
10
|
constructor(ecoFlowAccessory: EcoFlowAccessory);
|
|
8
11
|
initialize(): void;
|
|
12
|
+
cleanupCharacteristics(): void;
|
|
9
13
|
get service(): Service;
|
|
10
14
|
protected abstract createService(): Service;
|
|
15
|
+
protected abstract addCharacteristics(): Characteristic[];
|
|
16
|
+
protected addCharacteristic(characteristic: WithUUID<{
|
|
17
|
+
new (): Characteristic;
|
|
18
|
+
}>): Characteristic;
|
|
19
|
+
protected getOrAddService(service: WithUUID<typeof Service>, displayName?: string): Service;
|
|
20
|
+
protected getOrAddServiceById(service: WithUUID<typeof Service>, serviceName: string, serviceSubType: string): Service;
|
|
21
|
+
protected updateCharacteristic(characteristic: WithUUID<{
|
|
22
|
+
new (): Characteristic;
|
|
23
|
+
}>, name: string, value: CharacteristicValue): void;
|
|
11
24
|
}
|
|
@@ -1,17 +1,52 @@
|
|
|
1
1
|
export class ServiceBase {
|
|
2
2
|
ecoFlowAccessory;
|
|
3
3
|
log;
|
|
4
|
+
platform;
|
|
5
|
+
characteristics = [];
|
|
4
6
|
_service = null;
|
|
5
7
|
constructor(ecoFlowAccessory) {
|
|
6
8
|
this.ecoFlowAccessory = ecoFlowAccessory;
|
|
7
9
|
this.log = ecoFlowAccessory.log;
|
|
10
|
+
this.platform = ecoFlowAccessory.platform;
|
|
8
11
|
}
|
|
9
12
|
initialize() {
|
|
10
13
|
this._service = this.createService();
|
|
14
|
+
this.characteristics = this.addCharacteristics();
|
|
15
|
+
this.characteristics.push(this.addCharacteristic(this.platform.Characteristic.Name));
|
|
16
|
+
}
|
|
17
|
+
cleanupCharacteristics() {
|
|
18
|
+
this.service.characteristics
|
|
19
|
+
.filter(characteristic => !this.characteristics.includes(characteristic))
|
|
20
|
+
.forEach(characteristic => {
|
|
21
|
+
this.log.warn(`[${this.service.displayName}] Removing obsolete characteristic:`, characteristic.displayName);
|
|
22
|
+
this.service.removeCharacteristic(characteristic);
|
|
23
|
+
});
|
|
11
24
|
}
|
|
12
25
|
// Getter for service
|
|
13
26
|
get service() {
|
|
14
27
|
return this._service;
|
|
15
28
|
}
|
|
29
|
+
addCharacteristic(characteristic) {
|
|
30
|
+
const existingCharacteristic = this.service.getCharacteristic(characteristic);
|
|
31
|
+
if (!existingCharacteristic) {
|
|
32
|
+
return this.service.addCharacteristic(characteristic);
|
|
33
|
+
}
|
|
34
|
+
return existingCharacteristic;
|
|
35
|
+
}
|
|
36
|
+
getOrAddService(service, displayName) {
|
|
37
|
+
const result = this.ecoFlowAccessory.accessory.getService(service) ||
|
|
38
|
+
this.ecoFlowAccessory.accessory.addService(service, displayName, service.UUID);
|
|
39
|
+
result.displayName = displayName ?? result.displayName;
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
getOrAddServiceById(service, serviceName, serviceSubType) {
|
|
43
|
+
const result = this.ecoFlowAccessory.accessory.getServiceById(service, serviceSubType) ||
|
|
44
|
+
this.ecoFlowAccessory.accessory.addService(service, serviceName, serviceSubType);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
updateCharacteristic(characteristic, name, value) {
|
|
48
|
+
this.log.debug(`${name} ->`, value);
|
|
49
|
+
this.service.getCharacteristic(characteristic).updateValue(value);
|
|
50
|
+
}
|
|
16
51
|
}
|
|
17
52
|
//# sourceMappingURL=serviceBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceBase.js","sourceRoot":"","sources":["../../src/services/serviceBase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serviceBase.js","sourceRoot":"","sources":["../../src/services/serviceBase.ts"],"names":[],"mappings":"AAIA,MAAM,OAAgB,WAAW;IAMA;IALZ,GAAG,CAAU;IACb,QAAQ,CAA4B;IAC7C,eAAe,GAAqB,EAAE,CAAC;IACzC,QAAQ,GAAmB,IAAI,CAAC;IAExC,YAA+B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAC/D,IAAI,CAAC,GAAG,GAAG,gBAAgB,CAAC,GAAG,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC;IAC5C,CAAC;IAEM,UAAU;QACf,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACrC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACjD,IAAI,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AES,mBAAmB,CAC3B,OAAiC,EACjC,WAAmB,EACnB,cAAsB;QAEtB,MAAM,MAAM,GACV,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC;YACvE,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;QAEnF,OAAO,MAAM,CAAC;IAChB,CAAC;IAES,oBAAoB,CAC5B,cAAoD,EACpD,IAAY,EACZ,KAA0B;QAE1B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,KAAK,EAAE,KAAK,CAAC,CAAC;QACpC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC;CACF"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batteryService.js","sourceRoot":"","sources":["../../src/services/batteryService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC1B,aAAa;QAC9B,MAAM,OAAO,GACX,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC;YAC1F,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CACxC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAC9C,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAClC,CAAC;QACJ,OAAO,OAAO,CAAC;IACjB,CAAC;IAEM,sBAAsB,CAAC,YAAoB;QAChD,MAAM,gBAAgB,GAAG,YAAY,GAAG,EAAE,CAAC;QAC3C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,EAAE,gBAAgB,CAAC,CAAC;QAC1D,IAAI,CAAC,OAAO;aACT,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,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