homebridge-solaxcloud-api 1.3.0 → 1.4.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 +20 -18
- package/config.sample +1 -1
- package/config.schema.json +7 -4
- package/dist/motionAccessory.d.ts +15 -2
- package/dist/motionAccessory.d.ts.map +1 -1
- package/dist/motionAccessory.js +17 -3
- package/dist/motionAccessory.js.map +1 -1
- package/dist/outletAccessory.d.ts +8 -1
- package/dist/outletAccessory.d.ts.map +1 -1
- package/dist/outletAccessory.js +24 -10
- package/dist/outletAccessory.js.map +1 -1
- package/dist/platform.d.ts +4 -8
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +30 -42
- package/dist/platform.js.map +1 -1
- package/dist/platformAccessory.d.ts +4 -3
- package/dist/platformAccessory.d.ts.map +1 -1
- package/dist/platformAccessory.js +23 -6
- package/dist/platformAccessory.js.map +1 -1
- package/dist/solaxcloudapi.d.ts +1 -1
- package/dist/solaxcloudapi.d.ts.map +1 -1
- package/dist/solaxcloudapi.js +15 -5
- package/dist/solaxcloudapi.js.map +1 -1
- package/dist/statistics.js +8 -9
- package/dist/statistics.js.map +1 -1
- package/dist/util.d.ts +18 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +35 -0
- package/dist/util.js.map +1 -0
- package/images/plugin-accessories-eve.png +0 -0
- package/images/plugin-outlet-consumption.png +0 -0
- package/package.json +6 -4
- package/dist/request.d.ts +0 -29
- package/dist/request.d.ts.map +0 -1
- package/dist/request.js +0 -75
- package/dist/request.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
<img src="https://github.com/homebridge/branding/raw/master/logos/homebridge-wordmark-logo-vertical.png" width="150">
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
<table>
|
|
3
|
+
<tr>
|
|
4
|
+
<td align="center"><img src="https://github.com/homebridge/branding/raw/master/logos/homebridge-wordmark-logo-vertical.png" width="150"></td>
|
|
5
|
+
<td align="center"><img src="https://www.solaxpower.com/wp-content/uploads/2020/03/weblogo5.png" width="300"></td>
|
|
6
|
+
<tr>
|
|
7
|
+
</table>
|
|
8
8
|
|
|
9
9
|
# Solax Cloud Plugin for Homebridge
|
|
10
10
|
|
|
11
11
|
 
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
The Solax Cloud Plugin for [Homebridge](https://homebridge.io/) was created as a platform plugin to gather data exposed by Solax inverters to the cloud through the [Solax Cloud API](https://www.eu.solaxcloud.com/phoebus/resource/files/userGuide/Solax_API_for_End-user_V1.0.pdf).
|
|
15
15
|
|
|
16
|
-
HomeKit is still clueless about what a solar panel is
|
|
16
|
+
As HomeKit is still clueless about what a solar panel is, this plugin exposes a set of standard HomeKit accessories though Homebridge that will allow interacting and automating your smart home based on the data made available from the Solax platform:
|
|
17
17
|
|
|
18
|
-
- Inverter PV (outlet with power consumption)
|
|
19
|
-
- Inverter AC (outlet with power
|
|
20
|
-
- Inverter to Grid (outlet with power consumption)
|
|
21
|
-
- Inverter to House (outlet with power consumption)
|
|
22
|
-
- Grid To House (outlet with power consumption)
|
|
23
|
-
- Update (Motion sensor)
|
|
18
|
+
- **Inverter PV** (outlet with power consumption)
|
|
19
|
+
- **Inverter AC** (outlet with power and total energy consumptions)
|
|
20
|
+
- **Inverter to Grid** (outlet with power consumption)
|
|
21
|
+
- **Inverter to House** (outlet with power consumption)
|
|
22
|
+
- **Grid To House** (outlet with power consumption)
|
|
23
|
+
- **Update** (Motion sensor)
|
|
24
24
|
|
|
25
25
|

|
|
26
26
|
|
|
@@ -67,17 +67,17 @@ Configuration through the the use of [Homebridge UI](https://github.com/oznu/hom
|
|
|
67
67
|
|
|
68
68
|
Non-standard accessory characteristics are available through the use of [Eve for HomeKit app](https://apps.apple.com/us/app/eve-for-homekit/id917695792) you may download from the App Store.
|
|
69
69
|
|
|
70
|
-
This will allow some important non-standard characteristics to be visible (like consumption), as depicted in the image below:
|
|
70
|
+
This will allow some important non-standard characteristics to be visible (like power or total energy consumption), as depicted in the image below:
|
|
71
71
|
|
|
72
72
|

|
|
73
73
|
|
|
74
74
|
# Automation
|
|
75
75
|
|
|
76
|
-
Automation can be achieved with the help of the virtual "Update" motion sensor that was specifically tailored for this effect. This motion sensor will be triggered whenever data gets updated from the Solax Cloud API (
|
|
76
|
+
Automation can be achieved with the help of the virtual "Update" motion sensor that was specifically tailored for this effect. This motion sensor will be triggered whenever data gets updated from the Solax Cloud API (according to what is defined on the `pollingFrequency` configuration setting).
|
|
77
77
|
|
|
78
78
|

|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
Motion is detected by the **Update** motion sensor whenever there is newly fetched data from Solax Cloud. Using this sensor as a trigger combined with power and energy data from the virtual outlets enumerated above forms the basic building blocks for defining an automation.
|
|
81
81
|
|
|
82
82
|
## Automation example
|
|
83
83
|
|
|
@@ -87,4 +87,6 @@ As an automation example...
|
|
|
87
87
|
|
|
88
88
|
Next planned plugin releases should include:
|
|
89
89
|
|
|
90
|
-
-
|
|
90
|
+
- [X] **Inverter AC** to include Yield Energy
|
|
91
|
+
- [ ] Consumption history through the [fakegato-history](https://github.com/simont77/fakegato-history) module
|
|
92
|
+
- [ ] Accessories for battery state and consumptions (do not have one available)
|
package/config.sample
CHANGED
package/config.schema.json
CHANGED
|
@@ -37,10 +37,13 @@
|
|
|
37
37
|
"title": "Polling frequency (seconds)",
|
|
38
38
|
"type": "integer",
|
|
39
39
|
"required": false,
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
"default": 300,
|
|
41
|
+
"oneOf": [
|
|
42
|
+
{ "title": "300 (5 minutes)", "enum": [ 300 ] },
|
|
43
|
+
{ "title": "600 (10 minutes)", "enum": [ 600 ] },
|
|
44
|
+
{ "title": "900 (15 minutes)", "enum": [ 900 ] }
|
|
45
|
+
],
|
|
46
|
+
"description": "Plugin data polling frequency from Solax Cloud in seconds."
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
}
|
|
@@ -8,16 +8,19 @@ import { SolaxPlatformAccessory } from './platformAccessory';
|
|
|
8
8
|
* Sensor will automatically clear itself after MOTION_TIMEOUT seconds (5 seconds).
|
|
9
9
|
*/
|
|
10
10
|
export declare class SolaxMotionAccessory extends SolaxPlatformAccessory implements AccessoryPlugin {
|
|
11
|
+
/**
|
|
12
|
+
* Homekit Motion Service for this accessory.
|
|
13
|
+
*/
|
|
11
14
|
private readonly motionService;
|
|
12
15
|
/**
|
|
13
16
|
* Whether motion is detected (Solax Cloud data updated).
|
|
14
17
|
*/
|
|
15
18
|
private motion;
|
|
16
19
|
/**
|
|
17
|
-
*
|
|
20
|
+
* Interval before clearing motion (in seconds).
|
|
18
21
|
*/
|
|
19
22
|
private motionTimeout;
|
|
20
|
-
constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string);
|
|
23
|
+
constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string, serial: string, model: string);
|
|
21
24
|
sleep: typeof import("timers/promises").setTimeout;
|
|
22
25
|
/**
|
|
23
26
|
* Gets the motion sensor state Characteristic.
|
|
@@ -29,6 +32,16 @@ export declare class SolaxMotionAccessory extends SolaxPlatformAccessory impleme
|
|
|
29
32
|
* @param {boolean} motion Whether motion was detected.
|
|
30
33
|
*/
|
|
31
34
|
setState(motion: boolean): void;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the motion timeout.
|
|
37
|
+
* @param {number} timeout Number of seconds before clearing motion.
|
|
38
|
+
*/
|
|
39
|
+
setMotionTimeout(timeout: number): void;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the motion timeout.
|
|
42
|
+
* @return {number} Number of seconds before clearing motion.
|
|
43
|
+
*/
|
|
44
|
+
getMotionTimeout(): number;
|
|
32
45
|
getServices(): Service[];
|
|
33
46
|
}
|
|
34
47
|
//# sourceMappingURL=motionAccessory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"motionAccessory.d.ts","sourceRoot":"","sources":["../src/motionAccessory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAI1F,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAO7D;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,sBAAuB,YAAW,eAAe;IAEzF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAU;IAExC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAS;IAEvB;;OAEG;IACH,OAAO,CAAC,aAAa,CAA0B;gBAEnC,QAAQ,EAAE,qBAAqB,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"motionAccessory.d.ts","sourceRoot":"","sources":["../src/motionAccessory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAI1F,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAO7D;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,sBAAuB,YAAW,eAAe;IAEzF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAU;IAExC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAS;IAEvB;;OAEG;IACH,OAAO,CAAC,aAAa,CAA0B;gBAEnC,QAAQ,EAAE,qBAAqB,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAetG,KAAK,8CAA8B;IAEnC;;;OAGG;IACI,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAM1D;;;OAGG;IACI,QAAQ,CAAC,MAAM,EAAE,OAAO;IAe/B;;;OAGG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM;IAIhC;;;OAGG;IACH,gBAAgB,IAAI,MAAM;IAQ1B,WAAW,IAAI,OAAO,EAAE;CAOzB"}
|
package/dist/motionAccessory.js
CHANGED
|
@@ -16,14 +16,14 @@ const MOTION_TIMEOUT = 5;
|
|
|
16
16
|
* Sensor will automatically clear itself after MOTION_TIMEOUT seconds (5 seconds).
|
|
17
17
|
*/
|
|
18
18
|
class SolaxMotionAccessory extends platformAccessory_1.SolaxPlatformAccessory {
|
|
19
|
-
constructor(platform, log, name) {
|
|
20
|
-
super(platform, log, name);
|
|
19
|
+
constructor(platform, log, name, serial, model) {
|
|
20
|
+
super(platform, log, name, serial, model);
|
|
21
21
|
/**
|
|
22
22
|
* Whether motion is detected (Solax Cloud data updated).
|
|
23
23
|
*/
|
|
24
24
|
this.motion = false;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Interval before clearing motion (in seconds).
|
|
27
27
|
*/
|
|
28
28
|
this.motionTimeout = MOTION_TIMEOUT;
|
|
29
29
|
this.sleep = util_1.default.promisify(setTimeout);
|
|
@@ -58,6 +58,20 @@ class SolaxMotionAccessory extends platformAccessory_1.SolaxPlatformAccessory {
|
|
|
58
58
|
this.sleep(this.motionTimeout * 1000).then(() => this.setState(false));
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Sets the motion timeout.
|
|
63
|
+
* @param {number} timeout Number of seconds before clearing motion.
|
|
64
|
+
*/
|
|
65
|
+
setMotionTimeout(timeout) {
|
|
66
|
+
this.motionTimeout = timeout;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets the motion timeout.
|
|
70
|
+
* @return {number} Number of seconds before clearing motion.
|
|
71
|
+
*/
|
|
72
|
+
getMotionTimeout() {
|
|
73
|
+
return this.motionTimeout;
|
|
74
|
+
}
|
|
61
75
|
/*
|
|
62
76
|
* This method is called directly after creation of this instance.
|
|
63
77
|
* It should return all services which should be added to the accessory.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"motionAccessory.js","sourceRoot":"","sources":["../src/motionAccessory.ts"],"names":[],"mappings":";;;;;;AAEA,gDAAwB;AAGxB,2DAA6D;AAE7D;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,0CAAsB;
|
|
1
|
+
{"version":3,"file":"motionAccessory.js","sourceRoot":"","sources":["../src/motionAccessory.ts"],"names":[],"mappings":";;;;;;AAEA,gDAAwB;AAGxB,2DAA6D;AAE7D;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,0CAAsB;IAiB9D,YAAY,QAA+B,EAAE,GAAY,EAAE,IAAY,EAAE,MAAc,EAAE,KAAa;QACpG,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAX5C;;WAEG;QACK,WAAM,GAAG,KAAK,CAAC;QAEvB;;WAEG;QACK,kBAAa,GAAW,cAAc,CAAC;QAiB/C,UAAK,GAAG,cAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAZjC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;QAElC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,2BAA2B,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAExD,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7D,IAAI,CAAC,aAAa;aACf,iBAAiB,CAAC,GAAG,CAAC,cAAc,CAAC,cAAc,CAAC;aACpD,EAAE,kBAAmC,I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,9 @@ import { SolaxPlatformAccessory } from './platformAccessory';
|
|
|
7
7
|
* Outlet use is inferred from a positive power comsumption.
|
|
8
8
|
*/
|
|
9
9
|
export declare class SolaxOutletAccessory extends SolaxPlatformAccessory implements AccessoryPlugin {
|
|
10
|
+
/**
|
|
11
|
+
* Outlet service with power meter.
|
|
12
|
+
*/
|
|
10
13
|
private readonly outletService;
|
|
11
14
|
/**
|
|
12
15
|
* Current power reading in Watt.
|
|
@@ -16,7 +19,11 @@ export declare class SolaxOutletAccessory extends SolaxPlatformAccessory impleme
|
|
|
16
19
|
* Total energy readings in KWh.
|
|
17
20
|
*/
|
|
18
21
|
private totalEnergyConsumption;
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Elgato Eve fake history service for energy and status.
|
|
24
|
+
*/
|
|
25
|
+
private readonly loggingService;
|
|
26
|
+
constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string, serial: string, model: string);
|
|
20
27
|
/**
|
|
21
28
|
* Sets a characteristic value for a sepecific characteristic.
|
|
22
29
|
* @param {string} charName The characteristic name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outletAccessory.d.ts","sourceRoot":"","sources":["../src/outletAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,yBAAyB,EAAkB,MAAM,YAAY,CAAC;AAE1G,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"outletAccessory.d.ts","sourceRoot":"","sources":["../src/outletAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,yBAAyB,EAAkB,MAAM,YAAY,CAAC;AAE1G,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAI7D;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,sBAAuB,YAAW,eAAe;IAEzF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAU;IAExC;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAK;IAE7B;;OAEG;IACH,OAAO,CAAC,sBAAsB,CAAO;IAErC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;gBAI5C,QAAQ,EAAE,qBAAqB,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAmCtG;;;;OAIG;IACI,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAS7D;;OAEG;IACI,mBAAmB,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAMrE;;wEAEoE;IAC7D,mBAAmB,CAAC,gBAAgB,EAAE,MAAM;IAcnD;;OAEG;IACI,yBAAyB,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAM3E;;qFAEiF;IAC1E,yBAAyB,CAAC,sBAAsB,EAAE,MAAM;IAQ/D;;;OAGG;IACI,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAU1D,WAAW,IAAI,OAAO,EAAE;CAQzB"}
|
package/dist/outletAccessory.js
CHANGED
|
@@ -8,8 +8,9 @@ const platformAccessory_1 = require("./platformAccessory");
|
|
|
8
8
|
* Outlet use is inferred from a positive power comsumption.
|
|
9
9
|
*/
|
|
10
10
|
class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
//private services: Service[];
|
|
12
|
+
constructor(platform, log, name, serial, model) {
|
|
13
|
+
super(platform, log, name, serial, model);
|
|
13
14
|
/**
|
|
14
15
|
* Current power reading in Watt.
|
|
15
16
|
*/
|
|
@@ -20,15 +21,23 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
|
|
|
20
21
|
this.totalEnergyConsumption = 0.0;
|
|
21
22
|
const hap = this.platform.api.hap;
|
|
22
23
|
this.log.debug(`Creating outlet "${this.name}"`);
|
|
23
|
-
//
|
|
24
|
-
this.outletService = new
|
|
24
|
+
// create power meter service
|
|
25
|
+
this.outletService = new this.platform.eve.Services.Outlet(this.name);
|
|
25
26
|
// outlet on/off state
|
|
26
|
-
this.outletService.getCharacteristic(hap.Characteristic.On).
|
|
27
|
-
|
|
27
|
+
this.outletService.getCharacteristic(hap.Characteristic.On).on("get" /* GET */, this.getState.bind(this));
|
|
28
|
+
// in use
|
|
29
|
+
//this.outletService.getCharacteristic(hap.Characteristic.OutletInUse).on(hap.CharacteristicEventTypes.GET, this.getState.bind(this));
|
|
28
30
|
// current consumption
|
|
29
|
-
this.outletService.
|
|
31
|
+
this.outletService.getCharacteristic(this.platform.eve.Characteristics.CurrentConsumption)
|
|
32
|
+
.on("get" /* GET */, this.getPowerConsumption.bind(this));
|
|
30
33
|
// total consumption
|
|
31
|
-
this.outletService.
|
|
34
|
+
this.outletService.getCharacteristic(this.platform.eve.Characteristics.TotalConsumption)
|
|
35
|
+
.on("get" /* GET */, this.getTotalEnergyConsumption.bind(this));
|
|
36
|
+
// reset
|
|
37
|
+
//this.powerMeterService.addOptionalCharacteristic(this.platform.eve.Characteristics.ResetTotal);
|
|
38
|
+
// history logging services
|
|
39
|
+
this.loggingService = new this.platform.eveService('energy', this, { storage: 'fs', log: this.log });
|
|
40
|
+
//this.services.push(this.loggingService);
|
|
32
41
|
log.info(`Outlet "${name}" created!`);
|
|
33
42
|
}
|
|
34
43
|
/**
|
|
@@ -40,7 +49,7 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
|
|
|
40
49
|
// set up characteristic
|
|
41
50
|
const char = this.outletService.getCharacteristic(charName);
|
|
42
51
|
if (char) {
|
|
43
|
-
char.
|
|
52
|
+
char.updateValue(value);
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
/**
|
|
@@ -55,8 +64,12 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
|
|
|
55
64
|
* @param {number} powerConsumption The power consumption to set. */
|
|
56
65
|
setPowerConsumption(powerConsumption) {
|
|
57
66
|
this.log.debug(`${this.name}: SET Power (power=${powerConsumption}W)`);
|
|
58
|
-
this.powerConsumption = powerConsumption;
|
|
67
|
+
this.powerConsumption = powerConsumption >= 0 ? powerConsumption : 0;
|
|
59
68
|
this.setCharacteristicValue(this.platform.eve.Characteristics.CurrentConsumption, this.powerConsumption);
|
|
69
|
+
// add entries to history
|
|
70
|
+
this.loggingService.
|
|
71
|
+
addEntry({ time: Math.round(new Date().valueOf() / 1000), power: this.powerConsumption /*, status: this.powerConsumption > 0 */ });
|
|
72
|
+
//this.log.debug(JSON.stringify(this.loggingService));
|
|
60
73
|
}
|
|
61
74
|
/**
|
|
62
75
|
* Gets the total energy consumpion.
|
|
@@ -89,6 +102,7 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
|
|
|
89
102
|
return [
|
|
90
103
|
this.informationService,
|
|
91
104
|
this.outletService,
|
|
105
|
+
this.loggingService,
|
|
92
106
|
];
|
|
93
107
|
}
|
|
94
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outletAccessory.js","sourceRoot":"","sources":["../src/outletAccessory.ts"],"names":[],"mappings":";;;AAGA,2DAA6D;
|
|
1
|
+
{"version":3,"file":"outletAccessory.js","sourceRoot":"","sources":["../src/outletAccessory.ts"],"names":[],"mappings":";;;AAGA,2DAA6D;AAI7D;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,0CAAsB;IAsB9D,8BAA8B;IAE9B,YAAY,QAA+B,EAAE,GAAY,EAAE,IAAY,EAAE,MAAc,EAAE,KAAa;QACpG,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAA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IACI,yBAAyB,CAAC,QAAmC;QAClE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,8BAA8B,IAAI,CAAC,sBAAsB,MAAM,CAAC,CAAC;QAE5F,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC9C,CAAC;IAED;;qFAEiF;IAC1E,yBAAyB,CAAC,sBAA8B;QAC7D,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,8BAA8B,sBAAsB,MAAM,CAAC,CAAC;QAEvF,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;QAErD,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,gBAAgB,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC/G,CAAC;IAED;;;OAGG;IACI,QAAQ,CAAC,QAAmC;QACjD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,sBAAsB,IAAI,CAAC,gBAAgB,IAAI,CAAC,CAAC;QAE5E,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO;YACL,IAAI,CAAC,kBAAkB;YACvB,IAAI,CAAC,aAAa;YAClB,IAAI,CAAC,cAAc;SACpB,CAAC;IACJ,CAAC;CAEF;AA7ID,oDA6IC"}
|
package/dist/platform.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { AccessoryPlugin, API, StaticPlatformPlugin, Logging, PlatformConfig } from 'homebridge';
|
|
3
3
|
import { EveHomeKitTypes } from 'homebridge-lib';
|
|
4
|
-
import
|
|
4
|
+
import fakegato from 'fakegato-history';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* SolaxCloudAPIPlatform.
|
|
7
7
|
* This class is the main constructor for your plugin, this is where you should
|
|
8
8
|
* parse the user config and discover/register accessories with Homebridge.
|
|
9
9
|
*/
|
|
@@ -12,6 +12,7 @@ export declare class SolaxCloudAPIPlatform implements StaticPlatformPlugin {
|
|
|
12
12
|
private readonly config;
|
|
13
13
|
readonly api: API;
|
|
14
14
|
readonly eve: EveHomeKitTypes;
|
|
15
|
+
eveService: fakegato;
|
|
15
16
|
private readonly solaxCloudAPI;
|
|
16
17
|
private apiData;
|
|
17
18
|
/**
|
|
@@ -50,12 +51,7 @@ export declare class SolaxCloudAPIPlatform implements StaticPlatformPlugin {
|
|
|
50
51
|
/**
|
|
51
52
|
* Periodically retrieves inverter data from Solax Cloud API using configured tokenID and SN.
|
|
52
53
|
*/
|
|
53
|
-
private
|
|
54
|
-
/**
|
|
55
|
-
* Gets the latest API data available.
|
|
56
|
-
* @returns
|
|
57
|
-
*/
|
|
58
|
-
getAPIData(): SolaxCloudAPIResponse;
|
|
54
|
+
private fetchDataPeriodically;
|
|
59
55
|
accessories(callback: (foundAccessories: AccessoryPlugin[]) => void): void;
|
|
60
56
|
}
|
|
61
57
|
//# sourceMappingURL=platform.d.ts.map
|
package/dist/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAY,MAAM,YAAY,CAAC;AAE3G,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAY,MAAM,YAAY,CAAC;AAE3G,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,QAAQ,MAAM,kBAAkB,CAAC;AAcxC;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,oBAAoB;IAChE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAU;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,SAAgB,GAAG,EAAE,GAAG,CAAC;IAEzB,SAAgB,GAAG,EAAE,eAAe,CAAC;IAC9B,UAAU,EAAE,QAAQ,CAAC;IAE5B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAC/C,OAAO,CAAC,OAAO,CAAyB;IAExC;;MAEE;IACF,OAAO,CAAC,QAAQ,CAAwB;IAExC;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAwB;IAEhD;;OAEG;IACH,OAAO,CAAC,oBAAoB,CAAwB;IAEpD;;OAEG;IACH,OAAO,CAAC,qBAAqB,CAAwB;IAErD;;OAEG;IACH,OAAO,CAAC,iBAAiB,CAAwB;IAEjD;;OAEG;IACH,OAAO,CAAC,YAAY,CAAwB;IAE5C;;;;;;OAMG;gBACU,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG;IAyD3D,KAAK,8CAA8B;IAEnC;;OAEG;YACW,qBAAqB;IAyCnC,WAAW,CAAC,QAAQ,EAAE,CAAC,gBAAgB,EAAE,eAAe,EAAE,KAAK,IAAI,GAAG,IAAI;CAK3E"}
|
package/dist/platform.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SolaxCloudAPIPlatform = void 0;
|
|
7
7
|
const homebridge_lib_1 = require("homebridge-lib");
|
|
8
|
+
const fakegato_history_1 = __importDefault(require("fakegato-history"));
|
|
8
9
|
const outletAccessory_1 = require("./outletAccessory");
|
|
9
10
|
const util_1 = __importDefault(require("util"));
|
|
10
11
|
const solaxcloudapi_1 = require("./solaxcloudapi");
|
|
@@ -14,7 +15,7 @@ const motionAccessory_1 = require("./motionAccessory");
|
|
|
14
15
|
*/
|
|
15
16
|
const DEFAULT_POLLING_FREQUENCY = 300;
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
+
* SolaxCloudAPIPlatform.
|
|
18
19
|
* This class is the main constructor for your plugin, this is where you should
|
|
19
20
|
* parse the user config and discover/register accessories with Homebridge.
|
|
20
21
|
*/
|
|
@@ -38,19 +39,32 @@ class SolaxCloudAPIPlatform {
|
|
|
38
39
|
}
|
|
39
40
|
// setup default polling frequency
|
|
40
41
|
this.config.pollingFrequency = this.config.pollingFrequency || DEFAULT_POLLING_FREQUENCY;
|
|
41
|
-
this.eve = new homebridge_lib_1.EveHomeKitTypes(api);
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
this.outletPV = new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} PV`);
|
|
45
|
-
this.outletInverterAC = new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Inverter AC`);
|
|
46
|
-
this.outletInverterToGrid = new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Inverter to Grid`);
|
|
47
|
-
this.outletInverterToHouse = new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Inverter to House`);
|
|
48
|
-
this.outletGridToHouse = new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Grid to House`);
|
|
49
|
-
// setup update motion sensor
|
|
50
|
-
this.motionUpdate = new motionAccessory_1.SolaxMotionAccessory(this, this.log, `${this.config.name} Update`);
|
|
42
|
+
this.eve = new homebridge_lib_1.EveHomeKitTypes(this.api);
|
|
43
|
+
this.eveService = (0, fakegato_history_1.default)(this.api);
|
|
44
|
+
this.log.debug(`Config: ${JSON.stringify(config)}`);
|
|
51
45
|
// init new Solax Cloud API object with give tokenID and sn
|
|
52
46
|
this.solaxCloudAPI = new solaxcloudapi_1.SolaxCloudAPI(this.config.tokenId, this.config.sn);
|
|
53
|
-
|
|
47
|
+
// initial data set
|
|
48
|
+
this.apiData = this.solaxCloudAPI.getAPIData();
|
|
49
|
+
this.log.debug(`apiData = ${JSON.stringify(this.apiData)}`);
|
|
50
|
+
const inverterSN = this.apiData.result.inverterSN.toLowerCase();
|
|
51
|
+
const inverterModel = solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType);
|
|
52
|
+
// setup outlet accessories
|
|
53
|
+
this.outletPV =
|
|
54
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} PV`, `pv-${inverterSN}`, inverterModel);
|
|
55
|
+
this.outletInverterAC =
|
|
56
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Inverter AC`, `inv-ac-${inverterSN}`, inverterModel);
|
|
57
|
+
this.outletInverterToGrid =
|
|
58
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Inverter to Grid`, `inv-grid-${inverterSN}`, inverterModel);
|
|
59
|
+
this.outletInverterToHouse =
|
|
60
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Inverter to House`, `inv-house-${inverterSN}`, inverterModel);
|
|
61
|
+
this.outletGridToHouse =
|
|
62
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Grid to House`, `grid-house-${inverterSN}`, inverterModel);
|
|
63
|
+
// setup update motion sensor
|
|
64
|
+
this.motionUpdate =
|
|
65
|
+
new motionAccessory_1.SolaxMotionAccessory(this, this.log, `${this.config.name} Update`, `update-${inverterSN}`, inverterModel);
|
|
66
|
+
// start data fetching
|
|
67
|
+
this.fetchDataPeriodically();
|
|
54
68
|
this.log.debug('Finished initializing platform.'),
|
|
55
69
|
// When this event is fired it means Homebridge has created all accessories.
|
|
56
70
|
this.api.on("didFinishLaunching" /* DID_FINISH_LAUNCHING */, () => {
|
|
@@ -60,33 +74,21 @@ class SolaxCloudAPIPlatform {
|
|
|
60
74
|
/**
|
|
61
75
|
* Periodically retrieves inverter data from Solax Cloud API using configured tokenID and SN.
|
|
62
76
|
*/
|
|
63
|
-
async
|
|
77
|
+
async fetchDataPeriodically() {
|
|
64
78
|
try {
|
|
65
79
|
this.log.debug('Retrieving data from Solax Cloud API.');
|
|
66
|
-
this.apiData =
|
|
80
|
+
this.apiData = this.solaxCloudAPI.getAPIData();
|
|
67
81
|
if (this.apiData.success) {
|
|
68
82
|
this.log.debug(`Retrieved inverter status: ${JSON.stringify(this.apiData.result)}`);
|
|
69
83
|
// update outlets
|
|
70
84
|
this.outletPV.setPowerConsumption(solaxcloudapi_1.SolaxCloudAPI.getPVPower(this.apiData.result));
|
|
71
|
-
this.outletPV.setSerial(`pv-${this.apiData.result.inverterSN}`);
|
|
72
|
-
this.outletPV.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
73
85
|
this.outletInverterAC.setPowerConsumption(solaxcloudapi_1.SolaxCloudAPI.getInverterACPower(this.apiData.result));
|
|
74
86
|
this.outletInverterAC.setTotalEnergyConsumption(solaxcloudapi_1.SolaxCloudAPI.getYieldTotal(this.apiData.result));
|
|
75
|
-
this.outletInverterAC.setSerial(`inv-ac-${this.apiData.result.inverterSN}`);
|
|
76
|
-
this.outletInverterAC.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
77
87
|
this.outletInverterToGrid.setPowerConsumption(solaxcloudapi_1.SolaxCloudAPI.getInverterPowerToGrid(this.apiData.result));
|
|
78
|
-
this.outletInverterToGrid.setSerial(`inv-grid-${this.apiData.result.inverterSN}`);
|
|
79
|
-
this.outletInverterToGrid.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
80
88
|
this.outletInverterToHouse.setPowerConsumption(solaxcloudapi_1.SolaxCloudAPI.getInverterPowerToHouse(this.apiData.result));
|
|
81
|
-
this.outletInverterToHouse.setSerial(`inv-house-${this.apiData.result.inverterSN}`);
|
|
82
|
-
this.outletInverterToHouse.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
83
89
|
this.outletGridToHouse.setPowerConsumption(solaxcloudapi_1.SolaxCloudAPI.getGridPowerToHouse(this.apiData.result));
|
|
84
|
-
this.outletGridToHouse.setSerial(`grid-house-${this.apiData.result.inverterSN}`);
|
|
85
|
-
this.outletGridToHouse.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
86
90
|
// update motion sensor
|
|
87
91
|
this.motionUpdate.setState(true);
|
|
88
|
-
this.motionUpdate.setSerial(`update-${this.apiData.result.inverterSN}`);
|
|
89
|
-
this.motionUpdate.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
90
92
|
}
|
|
91
93
|
else {
|
|
92
94
|
throw new Error(this.apiData.exception);
|
|
@@ -97,23 +99,9 @@ class SolaxCloudAPIPlatform {
|
|
|
97
99
|
}
|
|
98
100
|
finally {
|
|
99
101
|
this.log.info(`Updated data from Solax Cloud API, sleeping for ${this.config.pollingFrequency} seconds.`);
|
|
100
|
-
this.sleep(this.config.pollingFrequency * 1000)
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Gets the latest API data available.
|
|
105
|
-
* @returns
|
|
106
|
-
*/
|
|
107
|
-
getAPIData() {
|
|
108
|
-
if (this.apiData) {
|
|
109
|
-
return this.apiData;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.getDataPeriodically().then(() => {
|
|
113
|
-
return this.getAPIData();
|
|
114
|
-
});
|
|
102
|
+
this.sleep(this.config.pollingFrequency * 1000)
|
|
103
|
+
.then(async () => await this.fetchDataPeriodically());
|
|
115
104
|
}
|
|
116
|
-
return this.apiData;
|
|
117
105
|
}
|
|
118
106
|
/*
|
|
119
107
|
* This method is called once at startup.
|
package/dist/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";;;;;;AAEA,mDAAiD;
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";;;;;;AAEA,mDAAiD;AACjD,wEAAwC;AAExC,uDAAyD;AAEzD,gDAAwB;AAExB,mDAAuE;AACvE,uDAAyD;AAEzD;;GAEG;AACH,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAEtC;;;;GAIG;AACH,MAAa,qBAAqB;IAyChC;;;;;;OAMG;IACH,YAAa,GAAY,EAAE,MAAsB,EAAE,GAAQ;QAyD3D,UAAK,GAAG,cAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAxDjC,6BAA6B;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAEf,eAAe;QACf,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE;YACnB,OAAO;SACR;QAED,kCAAkC;QAClC,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,IAAI,yBAAyB,CAAC;QAEzF,IAAI,CAAC,GAAG,GAAG,IAAI,gCAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,IAAA,0BAAQ,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAErC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAEpD,2DAA2D;QAC3D,IAAI,CAAC,aAAa,GAAG,IAAI,6BAAa,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAE5E,mBAAmB;QACn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,CAAC;IACzB,CAAC;CACF;AA5JD,sDA4JC"}
|
|
@@ -8,10 +8,11 @@ export declare class SolaxPlatformAccessory implements AccessoryPlugin {
|
|
|
8
8
|
protected readonly platform: SolaxCloudAPIPlatform;
|
|
9
9
|
protected readonly log: Logging;
|
|
10
10
|
protected readonly name: string;
|
|
11
|
-
protected readonly
|
|
11
|
+
protected readonly displayName: string;
|
|
12
|
+
protected serialNumber: string;
|
|
12
13
|
protected model: string;
|
|
13
|
-
protected
|
|
14
|
-
constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string);
|
|
14
|
+
protected readonly informationService: Service;
|
|
15
|
+
constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string, serialNumber: string, model: string);
|
|
15
16
|
/**
|
|
16
17
|
* Handle requests to get the current value of the "Model" characteristic.
|
|
17
18
|
* @returns {string} The model.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformAccessory.d.ts","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"platformAccessory.d.ts","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAI/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AASnD;;;GAGG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAC5D,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACnD,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IAChC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAChC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAEvC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,KAAK,SAAoB;IAEnC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;gBAEnC,QAAQ,EAAE,qBAAqB,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IA2B5G;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAMzB;;;OAGG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM;IAQ7B;;;OAGG;IACI,SAAS,IAAI,MAAM;IAM1B;;;OAGG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM;IAW/B,WAAW,IAAI,OAAO,EAAE;CAMzB"}
|
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.SolaxPlatformAccessory = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
const string_hash_64_1 = __importDefault(require("string-hash-64"));
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
11
|
+
const plugin = require('../package.json');
|
|
4
12
|
/**
|
|
5
13
|
* Platform Accessory.
|
|
6
14
|
* Generic platform accessory to store accessory name, manufacturer (Solax), inverter model and serial number.
|
|
7
15
|
*/
|
|
8
16
|
class SolaxPlatformAccessory {
|
|
9
|
-
constructor(platform, log, name) {
|
|
17
|
+
constructor(platform, log, name, serialNumber, model) {
|
|
10
18
|
this.model = 'Solax inverter';
|
|
11
|
-
this.serial = 'Default serial';
|
|
12
19
|
this.platform = platform;
|
|
13
20
|
this.log = log;
|
|
14
21
|
this.name = name;
|
|
22
|
+
this.displayName = name;
|
|
23
|
+
// hash "true" serial and hostname to 32 bit hex
|
|
24
|
+
this.serialNumber = (0, string_hash_64_1.default)(`${serialNumber}-${os_1.default.hostname()}`).toString(16);
|
|
25
|
+
this.model = util_1.Util.normalizeName(model);
|
|
15
26
|
const hap = this.platform.api.hap;
|
|
27
|
+
//this.uuid = hap.uuid.generate(this.serialNumber);
|
|
16
28
|
// information service
|
|
17
29
|
this.informationService =
|
|
18
30
|
new hap.Service.AccessoryInformation()
|
|
19
31
|
.setCharacteristic(hap.Characteristic.Name, this.name)
|
|
20
|
-
.setCharacteristic(hap.Characteristic.Manufacturer, 'Solax')
|
|
32
|
+
.setCharacteristic(hap.Characteristic.Manufacturer, 'Solax')
|
|
33
|
+
.setCharacteristic(hap.Characteristic.FirmwareRevision, plugin.version)
|
|
34
|
+
.setCharacteristic(hap.Characteristic.SerialNumber, this.serialNumber)
|
|
35
|
+
.setCharacteristic(hap.Characteristic.Model, this.model);
|
|
21
36
|
this.informationService.getCharacteristic(hap.Characteristic.SerialNumber).onGet(this.getSerial.bind(this));
|
|
22
37
|
this.informationService.getCharacteristic(hap.Characteristic.Model).onGet(this.getModel.bind(this));
|
|
23
38
|
}
|
|
@@ -36,14 +51,15 @@ class SolaxPlatformAccessory {
|
|
|
36
51
|
setModel(model) {
|
|
37
52
|
this.log.debug(`${this.name}: SET Model (model=${model})`);
|
|
38
53
|
this.model = model;
|
|
54
|
+
this.informationService.setCharacteristic(this.platform.api.hap.Characteristic.Model, model);
|
|
39
55
|
}
|
|
40
56
|
/**
|
|
41
57
|
* Handle requests to get the current value of the "SerialNumber" characteristic.
|
|
42
58
|
* @returns {string} The inverter serial number.
|
|
43
59
|
*/
|
|
44
60
|
getSerial() {
|
|
45
|
-
this.log.debug(`${this.name}: GET Serial (serial=${this.
|
|
46
|
-
return this.
|
|
61
|
+
this.log.debug(`${this.name}: GET Serial (serial=${this.serialNumber})`);
|
|
62
|
+
return this.serialNumber;
|
|
47
63
|
}
|
|
48
64
|
/**
|
|
49
65
|
* Sets model serial information for this outlet.
|
|
@@ -51,7 +67,8 @@ class SolaxPlatformAccessory {
|
|
|
51
67
|
*/
|
|
52
68
|
setSerial(serial) {
|
|
53
69
|
this.log.debug(`${this.name}: SET Serial (serial=${serial})`);
|
|
54
|
-
this.
|
|
70
|
+
this.serialNumber = serial;
|
|
71
|
+
this.informationService.setCharacteristic(this.platform.api.hap.Characteristic.SerialNumber, serial);
|
|
55
72
|
}
|
|
56
73
|
/*
|
|
57
74
|
* This method is called directly after creation of this instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformAccessory.js","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"platformAccessory.js","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":";;;;;;AAEA,4CAAoB;AAIpB,iCAA8B;AAE9B,oEAAkC;AAElC,8DAA8D;AAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE1C;;;GAGG;AACH,MAAa,sBAAsB;IAWjC,YAAY,QAA+B,EAAE,GAAY,EAAE,IAAY,EAAE,YAAoB,EAAE,KAAa;QAJlG,UAAK,GAAG,gBAAgB,CAAC;QAKjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,gDAAgD;QAChD,IAAI,CAAC,YAAY,GAAG,IAAA,wBAAI,EAAC,GAAG,YAAY,IAAI,YAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC1E,IAAI,CAAC,KAAK,GAAG,WAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAEvC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;QAElC,mDAAmD;QAEnD,s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B,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC/F,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,wBAAwB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QAEzE,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACI,SAAS,CAAC,MAAc;QAC7B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,wBAAwB,MAAM,GAAG,CAAC,CAAC;QAE9D,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;QAC3B,IAAI,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACvG,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO;YACL,IAAI,CAAC,kBAAkB;SACxB,CAAC;IACJ,CAAC;CAEF;AA3FD,wDA2FC"}
|
package/dist/solaxcloudapi.d.ts
CHANGED
|
@@ -120,6 +120,6 @@ export declare class SolaxCloudAPI {
|
|
|
120
120
|
* Retrieves inverter data using Solax Cloud "real-time" API.
|
|
121
121
|
* @returns {SolaxCloudAPIResponse} The response by Solax Cloud API.
|
|
122
122
|
*/
|
|
123
|
-
getAPIData():
|
|
123
|
+
getAPIData(): SolaxCloudAPIResponse;
|
|
124
124
|
}
|
|
125
125
|
//# sourceMappingURL=solaxcloudapi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solaxcloudapi.d.ts","sourceRoot":"","sources":["../src/solaxcloudapi.ts"],"names":[],"mappings":"AAEA;;KAEK;AACL,MAAM,WAAW,mBAAmB;IAChC,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC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IG;WACW,sBAAsB,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM;IAIvE;;;;OAIG;WACW,mBAAmB,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM;IAIpE;;;;OAIG;WACW,uBAAuB,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM;IAIxE;;;OAGG;IACI,UAAU,IAAI,qBAAqB;CAc3C"}
|
package/dist/solaxcloudapi.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.SolaxCloudAPI = void 0;
|
|
4
|
-
const
|
|
7
|
+
const sync_fetch_1 = __importDefault(require("sync-fetch"));
|
|
5
8
|
const SOLAX_CLOUD_URL = 'https://www.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do';
|
|
6
9
|
/**
|
|
7
10
|
* Main class to retrieve data from Solax API.
|
|
@@ -154,10 +157,17 @@ class SolaxCloudAPI {
|
|
|
154
157
|
* Retrieves inverter data using Solax Cloud "real-time" API.
|
|
155
158
|
* @returns {SolaxCloudAPIResponse} The response by Solax Cloud API.
|
|
156
159
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
getAPIData() {
|
|
161
|
+
try {
|
|
162
|
+
const response = (0, sync_fetch_1.default)(SOLAX_CLOUD_URL + '?tokenId=' + this.tokenId + '&sn=' + this.sn);
|
|
163
|
+
if (!response.ok) {
|
|
164
|
+
throw new Error(`unexpected response ${response.statusText}`);
|
|
165
|
+
}
|
|
166
|
+
return response.json();
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
return { exception: error, result: {}, success: false };
|
|
170
|
+
}
|
|
161
171
|
}
|
|
162
172
|
}
|
|
163
173
|
exports.SolaxCloudAPI = SolaxCloudAPI;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solaxcloudapi.js","sourceRoot":"","sources":["../src/solaxcloudapi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"solaxcloudapi.js","sourceRoot":"","sources":["../src/solaxcloudapi.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA+B;AAwD/B,MAAM,eAAe,GAAG,8DAA8D,CAAC;AAEvF;;GAEG;AACH,MAAa,aAAa;IAExB;;;;SAIK;IACL,YAA6B,OAAe,EAAkB,EAAU;QAA3C,YAAO,GAAP,OAAO,CAAQ;QAAkB,OAAE,GAAF,EAAE,CAAQ;QACtE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAED;;;;SAIK;IACE,MAAM,CAAC,eAAe,CAAC,QAAgB;QAC5C,QAAQ,QAAQ,EAAE;YAChB,KAAK,GAAG;gBACN,OAAO,OAAO,CAAC;YACjB,KAAK,GAAG;gBACN,OAAO,UAAU,CAAC;YACpB,KAAK,GAAG;gBACN,OAAO,eAAe,CAAC;YACzB,KAAK,GAAG;gBACN,OAAO,mBAAmB,CAAC;YAC7B,KAAK,GAAG;gBACN,OAAO,eAAe,CAAC;YACzB,KAAK,GAAG;gBACN,OAAO,YAAY,CAAC;YACtB,KAAK,GAAG;gBACN,OAAO,YAAY,CAAC;YACtB,KAAK,GAAG;gBACN,OAAO,UAAU,CAAC;YACpB,KAAK,GAAG;gBACN,OAAO,OAAO,CAAC;YACjB,KAAK,IAAI;gBACP,OAAO,WAAW,CAAC;YACrB,KAAK,IAAI;gBACP,OAAO,QAAQ,CAAC;YAClB,KAAK,IAAI;gBACP,OAAO,SAAS,CAAC;YACnB,KAAK,IAAI;gBACP,OAAO,QAAQ,CAAC;YAClB;gBACE,OAAO,SAAS,CAAC;SACpB;IACH,CAAC;IAED;;;;SAIK;IACE,MAAM,CAAC,iBAAiB,C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AAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,sBAAsB,CAAC,IAAyB;QAC5D,OAAO,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,IAAyB;QACzD,OAAO,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,uBAAuB,CAAC,IAAyB;QAC7D,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAE,GAAE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACI,UAAU;QACf,IAAI;YACF,MAAM,QAAQ,GAAG,IAAA,oBAAK,EAAC,eAAe,GAAG,WAAW,GAAG,IAAI,CAAC,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;YAExF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;gBAChB,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;aAC/D;YAED,OAA+B,QAAQ,CAAC,IAAI,EAAE,CAAC;SAChD;QAAC,OAAO,KAAK,EAAE;YACd,OAA+B,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;SACjF;IACH,CAAC;CAEF;AA3KD,sCA2KC"}
|
package/dist/statistics.js
CHANGED
|
@@ -8,13 +8,12 @@ const solaxcloudapi_1 = require("./solaxcloudapi");
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const config = JSON.parse(fs_1.default.readFileSync('config.json').toString());
|
|
10
10
|
const api = new solaxcloudapi_1.SolaxCloudAPI(config.platforms[0].tokenId, config.platforms[0].sn);
|
|
11
|
-
api.getAPIData()
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
11
|
+
const result = api.getAPIData();
|
|
12
|
+
console.log(`PV Power: ${solaxcloudapi_1.SolaxCloudAPI.getPVPower(result.result)}W`);
|
|
13
|
+
console.log(`Inverter AC Power: ${solaxcloudapi_1.SolaxCloudAPI.getInverterACPower(result.result)}W`);
|
|
14
|
+
console.log(`Grid Power to House: ${solaxcloudapi_1.SolaxCloudAPI.getGridPowerToHouse(result.result)}W`);
|
|
15
|
+
console.log(`Inverter Power to Grid: ${solaxcloudapi_1.SolaxCloudAPI.getInverterPowerToGrid(result.result)}W`);
|
|
16
|
+
console.log(`Inverter Power to House: ${solaxcloudapi_1.SolaxCloudAPI.getInverterPowerToHouse(result.result)}W`);
|
|
17
|
+
console.log(`Yield Today: ${solaxcloudapi_1.SolaxCloudAPI.getYieldToday(result.result)}KWh`);
|
|
18
|
+
console.log(`Yield Total: ${solaxcloudapi_1.SolaxCloudAPI.getYieldTotal(result.result)}KWh`);
|
|
20
19
|
//# sourceMappingURL=statistics.js.map
|
package/dist/statistics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statistics.js","sourceRoot":"","sources":["../src/statistics.ts"],"names":[],"mappings":";;;;;AAAA,+BAA+B;AAC/B,mDAAgD;AAEhD,4CAAoB;AAEpB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AACrE,MAAM,GAAG,GAAG,IAAI,6BAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC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,KAAK,CAAC,CAAC"}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Util {
|
|
5
|
+
/**
|
|
6
|
+
* Calculates 32 bit hash from a string.
|
|
7
|
+
* @param s {string} String to calculate 32 bit hash from.
|
|
8
|
+
* @returns {number} The 32 bit hash from the string.
|
|
9
|
+
*/
|
|
10
|
+
static hash32(s: string): number;
|
|
11
|
+
/**
|
|
12
|
+
* Removes non-standard alphanumeric characters from string.
|
|
13
|
+
* @param {string} s The original string.
|
|
14
|
+
* @returns {string} Resulting string without any non-standard chars.
|
|
15
|
+
*/
|
|
16
|
+
static normalizeName(s: string): string;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,qBAAa,IAAI;IAEf;;;;OAIG;WACW,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAiBvC;;;;OAIG;WACW,aAAa,CAAC,CAAC,EAAE,MAAM;CAItC"}
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Util = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Utility class.
|
|
6
|
+
*/
|
|
7
|
+
class Util {
|
|
8
|
+
/**
|
|
9
|
+
* Calculates 32 bit hash from a string.
|
|
10
|
+
* @param s {string} String to calculate 32 bit hash from.
|
|
11
|
+
* @returns {number} The 32 bit hash from the string.
|
|
12
|
+
*/
|
|
13
|
+
static hash32(s) {
|
|
14
|
+
let hash = 0;
|
|
15
|
+
if (s.length === 0) {
|
|
16
|
+
return hash;
|
|
17
|
+
}
|
|
18
|
+
for (let i = 0; i < s.length; i++) {
|
|
19
|
+
const chr = s.charCodeAt(i);
|
|
20
|
+
hash = ((hash << 5) - hash) + chr;
|
|
21
|
+
hash |= 0; // Convert to 32bit integer
|
|
22
|
+
}
|
|
23
|
+
return hash;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Removes non-standard alphanumeric characters from string.
|
|
27
|
+
* @param {string} s The original string.
|
|
28
|
+
* @returns {string} Resulting string without any non-standard chars.
|
|
29
|
+
*/
|
|
30
|
+
static normalizeName(s) {
|
|
31
|
+
return s.replace(/[^-_ a-zA-Z0-9]/gi, '');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Util = Util;
|
|
35
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AACA;;GAEG;AACH,MAAa,IAAI;IAEf;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,CAAS;QAC5B,IAAI,IAAI,GAAG,CAAC,CAAC;QAEb,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YAClB,OAAO,IAAI,CAAC;SACb;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACjC,MAAM,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAE5B,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC;YAClC,IAAI,IAAI,CAAC,CAAC,CAAC,2BAA2B;SACvC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,CAAS;QACnC,OAAO,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IAC5C,CAAC;CAEF;AAjCD,oBAiCC"}
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
|
-
"displayName": "Solax Cloud API",
|
|
3
|
+
"displayName": "Homebridge Solax Cloud API",
|
|
4
4
|
"name": "homebridge-solaxcloud-api",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.4.1",
|
|
6
6
|
"description": "Integrates solar production info using public Solax Cloud API into Homebrigde acessories.",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"repository": {
|
|
@@ -32,8 +32,10 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"jshint": "^2.13.1",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
35
|
+
"sync-fetch": "^0.3.1",
|
|
36
|
+
"string-hash-64": "^1.0.3",
|
|
37
|
+
"homebridge-lib": "^5.1.21",
|
|
38
|
+
"fakegato-history": "^0.6.2"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"@types/mocha": "^9.0.0",
|
package/dist/request.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
-
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
-
*/
|
|
6
|
-
export interface RequestOptions {
|
|
7
|
-
ignoreCache?: boolean;
|
|
8
|
-
headers?: {
|
|
9
|
-
[key: string]: string;
|
|
10
|
-
};
|
|
11
|
-
timeout?: number;
|
|
12
|
-
}
|
|
13
|
-
export declare const DEFAULT_REQUEST_OPTIONS: {
|
|
14
|
-
ignoreCache: boolean;
|
|
15
|
-
headers: {
|
|
16
|
-
Accept: string;
|
|
17
|
-
};
|
|
18
|
-
timeout: number;
|
|
19
|
-
};
|
|
20
|
-
export interface RequestResult {
|
|
21
|
-
ok: boolean;
|
|
22
|
-
status: number;
|
|
23
|
-
statusText: string;
|
|
24
|
-
data: string;
|
|
25
|
-
json: <T>() => T;
|
|
26
|
-
headers: string;
|
|
27
|
-
}
|
|
28
|
-
export declare function request(method: 'get' | 'post', url: string, queryParams?: object, body?: unknown, options?: RequestOptions): Promise<RequestResult>;
|
|
29
|
-
//# sourceMappingURL=request.d.ts.map
|
package/dist/request.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAE,MAAM,CAAA;KAAC,CAAC;IAEjC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAEH,eAAO,MAAM,uBAAuB;;;;;;CAOnC,CAAC;AAEF,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAmCH,wBAAgB,OAAO,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,EAC5C,GAAG,EAAE,MAAM,EACX,WAAW,GAAE,MAAW,EACxB,IAAI,GAAE,OAAc,EACpB,OAAO,GAAE,cAAwC,0BAuClD"}
|
package/dist/request.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.request = exports.DEFAULT_REQUEST_OPTIONS = void 0;
|
|
4
|
-
const xmlhttprequest_1 = require("xmlhttprequest");
|
|
5
|
-
exports.DEFAULT_REQUEST_OPTIONS = {
|
|
6
|
-
ignoreCache: false,
|
|
7
|
-
headers: {
|
|
8
|
-
Accept: 'application/json, text/javascript, text/plain',
|
|
9
|
-
},
|
|
10
|
-
// default max duration for a request
|
|
11
|
-
timeout: 5000,
|
|
12
|
-
};
|
|
13
|
-
function queryParams(params = {}) {
|
|
14
|
-
return Object.keys(params)
|
|
15
|
-
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
|
|
16
|
-
.join('&');
|
|
17
|
-
}
|
|
18
|
-
function withQuery(url, params = {}) {
|
|
19
|
-
const queryString = queryParams(params);
|
|
20
|
-
return queryString ? url + (url.indexOf('?') === -1 ? '?' : '&') + queryString : url;
|
|
21
|
-
}
|
|
22
|
-
function parseXHRResult(xhr) {
|
|
23
|
-
return {
|
|
24
|
-
ok: xhr.status >= 200 && xhr.status < 300,
|
|
25
|
-
status: xhr.status,
|
|
26
|
-
statusText: xhr.statusText,
|
|
27
|
-
headers: xhr.getAllResponseHeaders(),
|
|
28
|
-
data: xhr.responseText,
|
|
29
|
-
json: () => JSON.parse(xhr.responseText),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function errorResponse(xhr, message = null) {
|
|
33
|
-
return {
|
|
34
|
-
ok: false,
|
|
35
|
-
status: xhr.status,
|
|
36
|
-
statusText: xhr.statusText,
|
|
37
|
-
headers: xhr.getAllResponseHeaders(),
|
|
38
|
-
data: message || xhr.statusText,
|
|
39
|
-
json: () => JSON.parse(message || xhr.statusText),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function request(method, url, queryParams = {}, body = null, options = exports.DEFAULT_REQUEST_OPTIONS) {
|
|
43
|
-
const ignoreCache = options.ignoreCache || exports.DEFAULT_REQUEST_OPTIONS.ignoreCache;
|
|
44
|
-
const headers = options.headers || exports.DEFAULT_REQUEST_OPTIONS.headers;
|
|
45
|
-
const timeout = options.timeout || exports.DEFAULT_REQUEST_OPTIONS.timeout;
|
|
46
|
-
return new Promise((resolve) => {
|
|
47
|
-
const xhr = new xmlhttprequest_1.XMLHttpRequest();
|
|
48
|
-
xhr.open(method, withQuery(url, queryParams));
|
|
49
|
-
if (headers) {
|
|
50
|
-
Object.keys(headers).forEach(key => xhr.setRequestHeader(key, headers[key]));
|
|
51
|
-
}
|
|
52
|
-
if (ignoreCache) {
|
|
53
|
-
xhr.setRequestHeader('Cache-Control', 'no-cache');
|
|
54
|
-
}
|
|
55
|
-
xhr.timeout = timeout;
|
|
56
|
-
xhr.onload = () => {
|
|
57
|
-
resolve(parseXHRResult(xhr));
|
|
58
|
-
};
|
|
59
|
-
xhr.onerror = () => {
|
|
60
|
-
resolve(errorResponse(xhr, 'Failed to make request.'));
|
|
61
|
-
};
|
|
62
|
-
xhr.ontimeout = () => {
|
|
63
|
-
resolve(errorResponse(xhr, 'Request took longer than expected.'));
|
|
64
|
-
};
|
|
65
|
-
if (method === 'post' && body) {
|
|
66
|
-
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
67
|
-
xhr.send(JSON.stringify(body));
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
xhr.send();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
exports.request = request;
|
|
75
|
-
//# sourceMappingURL=request.js.map
|
package/dist/request.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAcnC,QAAA,uBAAuB,GAAG;IACrC,WAAW,EAAE,KAAK;IAClB,OAAO,EAAE;QACP,MAAM,EAAE,+CAA+C;KACxD;IACD,qCAAqC;IACrC,OAAO,EAAE,IAAI;CACd,CAAC;AAWF,SAAS,WAAW,CAAC,SAAiB,EAAE;IACtC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACvB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,GAAG,GAA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