homebridge-solaxcloud-api 1.3.1 → 1.4.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -17
- package/config.sample +1 -1
- package/config.schema.json +7 -4
- package/dist/motionAccessory.d.ts +1 -1
- package/dist/motionAccessory.d.ts.map +1 -1
- package/dist/motionAccessory.js +2 -2
- 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 +29 -36
- package/dist/platform.js.map +1 -1
- package/dist/platformAccessory.d.ts +7 -6
- package/dist/platformAccessory.d.ts.map +1 -1
- package/dist/platformAccessory.js +16 -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/images/plugin-accessories-eve.png +0 -0
- package/package.json +5 -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
|
|
|
@@ -73,11 +73,11 @@ This will allow some important non-standard characteristics to be visible (like
|
|
|
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
|
}
|
|
@@ -17,7 +17,7 @@ export declare class SolaxMotionAccessory extends SolaxPlatformAccessory impleme
|
|
|
17
17
|
* Update interval to turn motion back off (in seconds).
|
|
18
18
|
*/
|
|
19
19
|
private motionTimeout;
|
|
20
|
-
constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string);
|
|
20
|
+
constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string, serial: string);
|
|
21
21
|
sleep: typeof import("timers/promises").setTimeout;
|
|
22
22
|
/**
|
|
23
23
|
* Gets the motion sensor state Characteristic.
|
|
@@ -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,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;IAevF,KAAK,8CAA8B;IAEnC;;;OAGG;IACI,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAM1D;;;OAGG;IACI,QAAQ,CAAC,MAAM,EAAE,OAAO;IAmB/B,WAAW,IAAI,OAAO,EAAE;CAOzB"}
|
package/dist/motionAccessory.js
CHANGED
|
@@ -16,8 +16,8 @@ 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) {
|
|
20
|
+
super(platform, log, name, serial);
|
|
21
21
|
/**
|
|
22
22
|
* Whether motion is detected (Solax Cloud data updated).
|
|
23
23
|
*/
|
|
@@ -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;IAc9D,YAAY,QAA+B,EAAE,GAAY,EAAE,IAAY;
|
|
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;IAc9D,YAAY,QAA+B,EAAE,GAAY,EAAE,IAAY,EAAE,MAAc;QACrF,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAXrC;;WAEG;QACK,WAAM,GAAG,KAAK,CAAC;QAEvB;;WAEG;QACK,kBAAa,GAAW,cAAc,CAAC;Q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CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;SACxE;IACH,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO;YACL,IAAI,CAAC,kBAAkB;YACvB,IAAI,CAAC,aAAa;SACnB,CAAC;IACJ,CAAC;CAEF;AAvED,oDAuEC"}
|
|
@@ -7,6 +7,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);
|
|
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;IAmCvF;;;;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;IAYnD;;OAEG;IACI,yBAAyB,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAQ3E;;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) {
|
|
13
|
+
super(platform, log, name, serial);
|
|
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' });
|
|
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,11 @@ 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 */ });
|
|
60
72
|
}
|
|
61
73
|
/**
|
|
62
74
|
* Gets the total energy consumpion.
|
|
@@ -64,6 +76,7 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
|
|
|
64
76
|
getTotalEnergyConsumption(callback) {
|
|
65
77
|
this.log.debug(`${this.name}: GET Total Energy (energy=${this.totalEnergyConsumption}kWh)`);
|
|
66
78
|
callback(null, this.totalEnergyConsumption);
|
|
79
|
+
//this.log.debug(JSON.stringify(this.energyHistoryService));
|
|
67
80
|
}
|
|
68
81
|
/**
|
|
69
82
|
* Sets the total energy consumption.
|
|
@@ -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;QACrF,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAlBrC;;WAEG;QACK,qBAAgB,GAAG,CAAC,CAAC;QAE7B;;WAEG;QACK,2BAAsB,GAAG,GAAG,CAAC;QAYnC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;QAElC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,oBAAoB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAEjD,6BAA6B;QAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEtE,sBAAsB;QACtB,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,kBAAmC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3H,SAAS;QACT,sIAAsI;QAEtI,sBAAsB;QACtB,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,kBAAkB,CAAC;aACvF,EAAE,kBAAmC,IAAI,C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GG;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;IAwD3D,KAAK,8CAA8B;IAEnC;;OAEG;YACW,qBAAqB;IA+CnC,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,31 @@ 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
|
+
// setup outlet accessories
|
|
52
|
+
this.outletPV =
|
|
53
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} PV`, `pv-${inverterSN}`);
|
|
54
|
+
this.outletInverterAC =
|
|
55
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Inverter AC`, `inv-ac-${inverterSN}`);
|
|
56
|
+
this.outletInverterToGrid =
|
|
57
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Inverter to Grid`, `inv-grid-${inverterSN}`);
|
|
58
|
+
this.outletInverterToHouse =
|
|
59
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Inverter to House`, `inv-house-${inverterSN}`);
|
|
60
|
+
this.outletGridToHouse =
|
|
61
|
+
new outletAccessory_1.SolaxOutletAccessory(this, this.log, `${this.config.name} Grid to House`, `grid-house-${inverterSN}`);
|
|
62
|
+
// setup update motion sensor
|
|
63
|
+
this.motionUpdate =
|
|
64
|
+
new motionAccessory_1.SolaxMotionAccessory(this, this.log, `${this.config.name} Update`, `update-${inverterSN}`);
|
|
65
|
+
// start data fetching
|
|
66
|
+
this.fetchDataPeriodically();
|
|
54
67
|
this.log.debug('Finished initializing platform.'),
|
|
55
68
|
// When this event is fired it means Homebridge has created all accessories.
|
|
56
69
|
this.api.on("didFinishLaunching" /* DID_FINISH_LAUNCHING */, () => {
|
|
@@ -60,32 +73,26 @@ class SolaxCloudAPIPlatform {
|
|
|
60
73
|
/**
|
|
61
74
|
* Periodically retrieves inverter data from Solax Cloud API using configured tokenID and SN.
|
|
62
75
|
*/
|
|
63
|
-
async
|
|
76
|
+
async fetchDataPeriodically() {
|
|
64
77
|
try {
|
|
65
78
|
this.log.debug('Retrieving data from Solax Cloud API.');
|
|
66
|
-
this.apiData =
|
|
79
|
+
this.apiData = this.solaxCloudAPI.getAPIData();
|
|
67
80
|
if (this.apiData.success) {
|
|
68
81
|
this.log.debug(`Retrieved inverter status: ${JSON.stringify(this.apiData.result)}`);
|
|
69
82
|
// update outlets
|
|
70
83
|
this.outletPV.setPowerConsumption(solaxcloudapi_1.SolaxCloudAPI.getPVPower(this.apiData.result));
|
|
71
|
-
this.outletPV.setSerial(`pv-${this.apiData.result.inverterSN}`);
|
|
72
84
|
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
87
|
this.outletInverterAC.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
77
88
|
this.outletInverterToGrid.setPowerConsumption(solaxcloudapi_1.SolaxCloudAPI.getInverterPowerToGrid(this.apiData.result));
|
|
78
|
-
this.outletInverterToGrid.setSerial(`inv-grid-${this.apiData.result.inverterSN}`);
|
|
79
89
|
this.outletInverterToGrid.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
80
90
|
this.outletInverterToHouse.setPowerConsumption(solaxcloudapi_1.SolaxCloudAPI.getInverterPowerToHouse(this.apiData.result));
|
|
81
|
-
this.outletInverterToHouse.setSerial(`inv-house-${this.apiData.result.inverterSN}`);
|
|
82
91
|
this.outletInverterToHouse.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
83
92
|
this.outletGridToHouse.setPowerConsumption(solaxcloudapi_1.SolaxCloudAPI.getGridPowerToHouse(this.apiData.result));
|
|
84
|
-
this.outletGridToHouse.setSerial(`grid-house-${this.apiData.result.inverterSN}`);
|
|
85
93
|
this.outletGridToHouse.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
86
94
|
// update motion sensor
|
|
87
95
|
this.motionUpdate.setState(true);
|
|
88
|
-
this.motionUpdate.setSerial(`update-${this.apiData.result.inverterSN}`);
|
|
89
96
|
this.motionUpdate.setModel(solaxcloudapi_1.SolaxCloudAPI.getInverterType(this.apiData.result.inverterType));
|
|
90
97
|
}
|
|
91
98
|
else {
|
|
@@ -97,23 +104,9 @@ class SolaxCloudAPIPlatform {
|
|
|
97
104
|
}
|
|
98
105
|
finally {
|
|
99
106
|
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
|
-
});
|
|
107
|
+
this.sleep(this.config.pollingFrequency * 1000)
|
|
108
|
+
.then(async () => await this.fetchDataPeriodically());
|
|
115
109
|
}
|
|
116
|
-
return this.apiData;
|
|
117
110
|
}
|
|
118
111
|
/*
|
|
119
112
|
* 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;QAwD3D,UAAK,GAAG,cAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAvDjC,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,GAA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C,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBACjC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,6BAAa,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;aAC7F;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;aACzC;SACF;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,+CAA+C,KAAK,EAAE,CAAC,CAAC;SACxE;gBAAS;YACR,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mDAAmD,IAAI,CAAC,MAAM,CAAC,gBAAgB,WAAW,CAAC,CAAC;YAE1G,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;iBAC5C,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC;SACzD;IACH,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,QAAuD;QACjE,QAAQ,CAAC,CAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB;YAC7C,IAAI,CAAC,oBAAoB,EAAE,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC,iBAAiB;YAC7E,IAAI,CAAC,YAAY,CAAE,CAAC,CAAC;IACzB,CAAC;CACF;AAjKD,sDAiKC"}
|
|
@@ -5,13 +5,14 @@ import { SolaxCloudAPIPlatform } from './platform';
|
|
|
5
5
|
* Generic platform accessory to store accessory name, manufacturer (Solax), inverter model and serial number.
|
|
6
6
|
*/
|
|
7
7
|
export declare class SolaxPlatformAccessory implements AccessoryPlugin {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
readonly platform: SolaxCloudAPIPlatform;
|
|
9
|
+
readonly log: Logging;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly displayName: string;
|
|
12
|
+
serialNumber: string;
|
|
13
|
+
model: string;
|
|
11
14
|
protected readonly informationService: Service;
|
|
12
|
-
|
|
13
|
-
protected serial: string;
|
|
14
|
-
constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string);
|
|
15
|
+
constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string, serialNumber: 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;AAE/D,OAAO,EAAE,qBAAqB,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;AAE/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAInD;;;GAGG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAC5D,SAAgB,QAAQ,EAAE,qBAAqB,CAAC;IAChD,SAAgB,GAAG,EAAE,OAAO,CAAC;IAC7B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,WAAW,EAAE,MAAM,CAAC;IAE7B,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,SAAoB;IAEhC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;gBAEnC,QAAQ,EAAE,qBAAqB,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAuB7F;;;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,31 @@
|
|
|
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 fs_1 = __importDefault(require("fs"));
|
|
4
8
|
/**
|
|
5
9
|
* Platform Accessory.
|
|
6
10
|
* Generic platform accessory to store accessory name, manufacturer (Solax), inverter model and serial number.
|
|
7
11
|
*/
|
|
8
12
|
class SolaxPlatformAccessory {
|
|
9
|
-
constructor(platform, log, name) {
|
|
13
|
+
constructor(platform, log, name, serialNumber) {
|
|
10
14
|
this.model = 'Solax inverter';
|
|
11
|
-
this.serial = 'Default serial';
|
|
12
15
|
this.platform = platform;
|
|
13
16
|
this.log = log;
|
|
14
17
|
this.name = name;
|
|
18
|
+
this.displayName = name;
|
|
19
|
+
this.serialNumber = serialNumber;
|
|
20
|
+
const plugin = JSON.parse(fs_1.default.readFileSync('package.json').toString());
|
|
15
21
|
const hap = this.platform.api.hap;
|
|
16
22
|
// information service
|
|
17
23
|
this.informationService =
|
|
18
24
|
new hap.Service.AccessoryInformation()
|
|
19
25
|
.setCharacteristic(hap.Characteristic.Name, this.name)
|
|
20
|
-
.setCharacteristic(hap.Characteristic.Manufacturer, 'Solax')
|
|
26
|
+
.setCharacteristic(hap.Characteristic.Manufacturer, 'Solax')
|
|
27
|
+
.setCharacteristic(hap.Characteristic.FirmwareRevision, plugin.version)
|
|
28
|
+
.setCharacteristic(hap.Characteristic.SerialNumber, this.serialNumber);
|
|
21
29
|
this.informationService.getCharacteristic(hap.Characteristic.SerialNumber).onGet(this.getSerial.bind(this));
|
|
22
30
|
this.informationService.getCharacteristic(hap.Characteristic.Model).onGet(this.getModel.bind(this));
|
|
23
31
|
}
|
|
@@ -36,14 +44,15 @@ class SolaxPlatformAccessory {
|
|
|
36
44
|
setModel(model) {
|
|
37
45
|
this.log.debug(`${this.name}: SET Model (model=${model})`);
|
|
38
46
|
this.model = model;
|
|
47
|
+
this.informationService.setCharacteristic(this.platform.api.hap.Characteristic.Model, model);
|
|
39
48
|
}
|
|
40
49
|
/**
|
|
41
50
|
* Handle requests to get the current value of the "SerialNumber" characteristic.
|
|
42
51
|
* @returns {string} The inverter serial number.
|
|
43
52
|
*/
|
|
44
53
|
getSerial() {
|
|
45
|
-
this.log.debug(`${this.name}: GET Serial (serial=${this.
|
|
46
|
-
return this.
|
|
54
|
+
this.log.debug(`${this.name}: GET Serial (serial=${this.serialNumber})`);
|
|
55
|
+
return this.serialNumber;
|
|
47
56
|
}
|
|
48
57
|
/**
|
|
49
58
|
* Sets model serial information for this outlet.
|
|
@@ -51,7 +60,8 @@ class SolaxPlatformAccessory {
|
|
|
51
60
|
*/
|
|
52
61
|
setSerial(serial) {
|
|
53
62
|
this.log.debug(`${this.name}: SET Serial (serial=${serial})`);
|
|
54
|
-
this.
|
|
63
|
+
this.serialNumber = serial;
|
|
64
|
+
this.informationService.setCharacteristic(this.platform.api.hap.Characteristic.SerialNumber, serial);
|
|
55
65
|
}
|
|
56
66
|
/*
|
|
57
67
|
* 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":";;;;;;AAIA,4CAAoB;AAEpB;;;GAGG;AACH,MAAa,sBAAsB;IAWjC,YAAY,QAA+B,EAAE,GAAY,EAAE,IAAY,EAA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
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;IACnB,kEAAkE;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,aAAa,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,kCAAkC;IAClC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kCAAkC;IAClC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kCAAkC;IAClC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,yBAAyB;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,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,EAAE,MAAM,GAAG,MAAM;IAiCvD;;;;SAIK;WACS,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAmC3D;;;;OAIG;WACW,UAAU,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM;IAI3D;;;;OAIG;WACW,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM;IAInE;;;;OAIG;WACW,aAAa,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM;IAI9D;;;;OAIG;WACW,aAAa,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM;IAI9D;;;;OAIG;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,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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,CAAC;AAEnF,GAAG,CAAC,UAAU,EAAE,CAAC
|
|
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,CAAC;AAEnF,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;AAEhC,OAAO,CAAC,GAAG,CAAC,aAAa,6BAAa,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACrE,OAAO,CAAC,GAAG,CAAC,sBAAsB,6BAAa,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtF,OAAO,CAAC,GAAG,CAAC,wBAAwB,6BAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACzF,OAAO,CAAC,GAAG,CAAC,2BAA2B,6BAAa,CAAC,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC/F,OAAO,CAAC,GAAG,CAAC,4BAA4B,6BAAa,CAAC,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAEjG,OAAO,CAAC,GAAG,CAAC,gBAAgB,6BAAa,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC7E,OAAO,CAAC,GAAG,CAAC,gBAAgB,6BAAa,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC"}
|
|
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-beta.0",
|
|
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,9 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"jshint": "^2.13.1",
|
|
35
|
-
"
|
|
36
|
-
"homebridge-lib": "^5.1.21"
|
|
35
|
+
"sync-fetch": "^0.3.1",
|
|
36
|
+
"homebridge-lib": "^5.1.21",
|
|
37
|
+
"fakegato-history": "^0.6.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@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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