homebridge-solaxcloud-api 2.3.3 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +140 -131
  2. package/LICENSE +175 -175
  3. package/config.sample +15 -15
  4. package/config.schema.json +105 -105
  5. package/dist/batteryAccessory.d.ts +70 -70
  6. package/dist/batteryAccessory.d.ts.map +1 -1
  7. package/dist/batteryAccessory.js +124 -123
  8. package/dist/batteryAccessory.js.map +1 -1
  9. package/dist/index.d.ts +6 -6
  10. package/dist/index.js +6 -6
  11. package/dist/lightSensorAccessory.d.ts +34 -34
  12. package/dist/lightSensorAccessory.js +58 -58
  13. package/dist/motionAccessory.d.ts +53 -53
  14. package/dist/motionAccessory.js +93 -93
  15. package/dist/outletAccessory.d.ts +100 -100
  16. package/dist/outletAccessory.js +187 -187
  17. package/dist/platform.d.ts +62 -56
  18. package/dist/platform.d.ts.map +1 -1
  19. package/dist/platform.js +294 -265
  20. package/dist/platform.js.map +1 -1
  21. package/dist/platformAccessory.d.ts +70 -70
  22. package/dist/platformAccessory.js +102 -102
  23. package/dist/platformInverter.d.ts +180 -176
  24. package/dist/platformInverter.d.ts.map +1 -1
  25. package/dist/platformInverter.js +348 -343
  26. package/dist/platformInverter.js.map +1 -1
  27. package/dist/platformMeters.d.ts +68 -68
  28. package/dist/platformMeters.js +2 -2
  29. package/dist/settings.d.ts +8 -8
  30. package/dist/settings.js +11 -11
  31. package/dist/solaxcloudfetch.d.ts +1 -1
  32. package/dist/solaxcloudfetch.js +21 -21
  33. package/dist/solaxcloudfetch.js.map +1 -1
  34. package/dist/statistics.d.ts +36 -36
  35. package/dist/statistics.js +88 -88
  36. package/dist/util.d.ts +23 -23
  37. package/dist/util.js +42 -42
  38. package/package.json +55 -54
  39. package/config.json +0 -16
  40. package/dist/solaxcloudapi.d.ts +0 -163
  41. package/dist/solaxcloudapi.d.ts.map +0 -1
  42. package/dist/solaxcloudapi.js +0 -226
  43. package/dist/solaxcloudapi.js.map +0 -1
  44. package/test/solaxcloudapi.test.ts +0 -164
package/config.sample CHANGED
@@ -1,16 +1,16 @@
1
- {
2
- "platforms": [
3
- {
4
- "platform": "SolaxCloudAPI",
5
- inverters: [
6
- {
7
- "brand": "solax",
8
- "tokenId": "20200722185111234567890",
9
- "name": "My Solax",
10
- "sn": "ABCDEFGHIJ"
11
- }
12
- ],
13
- "pollingFrequency": 300
14
- }
15
- ]
1
+ {
2
+ "platforms": [
3
+ {
4
+ "platform": "SolaxCloudAPI",
5
+ inverters: [
6
+ {
7
+ "brand": "solax",
8
+ "tokenId": "20200722185111234567890",
9
+ "name": "My Solax",
10
+ "sn": "ABCDEFGHIJ"
11
+ }
12
+ ],
13
+ "pollingFrequency": 300
14
+ }
15
+ ]
16
16
  }
@@ -1,106 +1,106 @@
1
- {
2
- "pluginAlias": "SolaxCloudAPI",
3
- "pluginType": "platform",
4
- "singular": false,
5
- "headerDisplay": "This Homebridge plugin uses Solax/QCells API cloud service to obtain real-time info of your inverters.",
6
- "schema": {
7
- "type": "object",
8
- "properties": {
9
- "inverters": {
10
- "title": "Inverters",
11
- "type": "array",
12
- "items": {
13
- "title": "Inverter",
14
- "type": "object",
15
- "properties": {
16
- "brand": {
17
- "title": "Inverter Brand",
18
- "type": "string",
19
- "required": true,
20
- "default": "solax",
21
- "oneOf": [
22
- { "title": "Solax", "enum": [ "solax" ] },
23
- { "title": "QCells", "enum": [ "qcells" ] }
24
- ],
25
- "description": "Brand for list of inverters below (API data fetch URL is brand dependent)."
26
- },
27
- "tokenId": {
28
- "title": "TokenID",
29
- "type": "string",
30
- "required": true,
31
- "description": "Users get information from the cloud API through the granted tokenID. Please obtain your tokenID on the API page of Solax/QCells cloud.",
32
- "default": "20200722185111234567890",
33
- "minLength": 23,
34
- "maxLength": 24
35
- },
36
- "name": {
37
- "title": "Inverter name (unique)",
38
- "type": "string",
39
- "required": true,
40
- "description": "Inverter name for description purposes.",
41
- "default": "My Solax Inverter",
42
- "minLength": 1,
43
- "maxLength": 30
44
- },
45
- "sn": {
46
- "title": "Inverter module SN",
47
- "type": "string",
48
- "required": true,
49
- "description": "Registration No. (inverter module SN)",
50
- "default": "ABCDEFGHIJ",
51
- "minLength": 10,
52
- "maxLength": 10
53
- },
54
- "hasBattery": {
55
- "title": "Battery installed?",
56
- "type": "boolean",
57
- "required": false,
58
- "description": "Whether this inverter has a battery installed.",
59
- "default": false
60
- }
61
- }
62
- }
63
- },
64
- "pollingFrequency": {
65
- "title": "Polling frequency (seconds)",
66
- "type": "integer",
67
- "required": false,
68
- "default": 300,
69
- "oneOf": [
70
- { "title": "300 (5 minutes)", "enum": [ 300 ] },
71
- { "title": "600 (10 minutes)", "enum": [ 600 ] },
72
- { "title": "900 (15 minutes)", "enum": [ 900 ] }
73
- ],
74
- "description": "Plugin data polling frequency from the cloud (in seconds)."
75
- },
76
- "smoothMeters": {
77
- "title": "Add accessories for smooth meters?",
78
- "type": "boolean",
79
- "required": false,
80
- "default": true,
81
- "description": "Enable this option to create accessories for smoothing raw values read from the cloud."
82
- },
83
- "smoothingMethod": {
84
- "title": "Smoothing method",
85
- "type": "string",
86
- "required": true,
87
- "default": "sma",
88
- "oneOf": [
89
- { "title": "Simple moving average", "enum": [ "sma" ] },
90
- { "title": "Exponential moving average", "enum": [ "ema" ] }
91
- ],
92
- "condition": {
93
- "functionBody": "return model.smoothMeters === true;"
94
- },
95
- "description": "Statistical method for smoothing power consumption data."
96
- },
97
- "pureHomeApp": {
98
- "title": "Add \"pure\" Home app accessories?",
99
- "type": "boolean",
100
- "required": false,
101
- "default": false,
102
- "description": "Enable this option to create light ambient sensors for power consumption."
103
- }
104
- }
105
- }
1
+ {
2
+ "pluginAlias": "SolaxCloudAPI",
3
+ "pluginType": "platform",
4
+ "singular": false,
5
+ "headerDisplay": "This Homebridge plugin uses Solax/QCells API cloud service to obtain real-time info of your inverters.",
6
+ "schema": {
7
+ "type": "object",
8
+ "properties": {
9
+ "inverters": {
10
+ "title": "Inverters",
11
+ "type": "array",
12
+ "items": {
13
+ "title": "Inverter",
14
+ "type": "object",
15
+ "properties": {
16
+ "brand": {
17
+ "title": "Inverter Brand",
18
+ "type": "string",
19
+ "required": true,
20
+ "default": "solax",
21
+ "oneOf": [
22
+ { "title": "Solax", "enum": [ "solax" ] },
23
+ { "title": "QCells", "enum": [ "qcells" ] }
24
+ ],
25
+ "description": "Brand for list of inverters below (API data fetch URL is brand dependent)."
26
+ },
27
+ "tokenId": {
28
+ "title": "TokenID",
29
+ "type": "string",
30
+ "required": true,
31
+ "description": "Users get information from the cloud API through the granted tokenID. Please obtain your tokenID on the API page of Solax/QCells cloud.",
32
+ "default": "20200722185111234567890",
33
+ "minLength": 23,
34
+ "maxLength": 24
35
+ },
36
+ "name": {
37
+ "title": "Inverter name (unique)",
38
+ "type": "string",
39
+ "required": true,
40
+ "description": "Inverter name for description purposes.",
41
+ "default": "My Solax Inverter",
42
+ "minLength": 1,
43
+ "maxLength": 30
44
+ },
45
+ "sn": {
46
+ "title": "Inverter module SN",
47
+ "type": "string",
48
+ "required": true,
49
+ "description": "Registration No. (inverter module SN)",
50
+ "default": "ABCDEFGHIJ",
51
+ "minLength": 10,
52
+ "maxLength": 10
53
+ },
54
+ "hasBattery": {
55
+ "title": "Battery installed?",
56
+ "type": "boolean",
57
+ "required": false,
58
+ "description": "Whether this inverter has a battery installed.",
59
+ "default": false
60
+ }
61
+ }
62
+ }
63
+ },
64
+ "pollingFrequency": {
65
+ "title": "Polling frequency (seconds)",
66
+ "type": "integer",
67
+ "required": false,
68
+ "default": 300,
69
+ "oneOf": [
70
+ { "title": "300 (5 minutes)", "enum": [ 300 ] },
71
+ { "title": "600 (10 minutes)", "enum": [ 600 ] },
72
+ { "title": "900 (15 minutes)", "enum": [ 900 ] }
73
+ ],
74
+ "description": "Plugin data polling frequency from the cloud (in seconds)."
75
+ },
76
+ "smoothMeters": {
77
+ "title": "Add accessories for smooth meters?",
78
+ "type": "boolean",
79
+ "required": false,
80
+ "default": true,
81
+ "description": "Enable this option to create accessories for smoothing raw values read from the cloud."
82
+ },
83
+ "smoothingMethod": {
84
+ "title": "Smoothing method",
85
+ "type": "string",
86
+ "required": true,
87
+ "default": "sma",
88
+ "oneOf": [
89
+ { "title": "Simple moving average", "enum": [ "sma" ] },
90
+ { "title": "Exponential moving average", "enum": [ "ema" ] }
91
+ ],
92
+ "condition": {
93
+ "functionBody": "return model.smoothMeters === true;"
94
+ },
95
+ "description": "Statistical method for smoothing power consumption data."
96
+ },
97
+ "pureHomeApp": {
98
+ "title": "Add \"pure\" Home app accessories?",
99
+ "type": "boolean",
100
+ "required": false,
101
+ "default": false,
102
+ "description": "Enable this option to create light ambient sensors for power consumption."
103
+ }
104
+ }
105
+ }
106
106
  }
@@ -1,71 +1,71 @@
1
- import { AccessoryPlugin, API, CharacteristicGetCallback, Logging, Service } from 'homebridge';
2
- import { SolaxPlatformAccessory } from './platformAccessory';
3
- /**
4
- * Enum with possible battery charging states.
5
- */
6
- export declare const BATTERY_CHARGING_STATE: {
7
- NOT_CHARGING: number;
8
- CHARGING: number;
9
- NOT_CHARGEABLE: number;
10
- };
11
- /**
12
- * Solax Battery Accessory.
13
- * Battery sensor used to monitor inverter battery state of charge (SoC).
14
- */
15
- export declare class SolaxBatteryAccessory extends SolaxPlatformAccessory implements AccessoryPlugin {
16
- /**
17
- * The battery service for Homekit.
18
- **/
19
- private readonly batteryService;
20
- /**
21
- * The battery charge level (in percentage).
22
- */
23
- private batteryLevel;
24
- /**
25
- * Ambient light level.
26
- */
27
- private batteryChargeState;
28
- /**
29
- * Solax virtual light sensor class constructor.
30
- * @param {Logging} log The platform logging for homebridge.
31
- * @param {API} api The platform API.
32
- * @param {string} name The accessory name.
33
- * @param {string} serial "Real world" serial number for this accessory.
34
- * @param {string} model Accessory model.
35
- */
36
- constructor(log: Logging, api: API, name: string, serial: string, model: string);
37
- /**
38
- * Handle requests to get the current value of the "Status Low Battery" characteristic.
39
- */
40
- getStatusLowBattery(): number;
41
- /**
42
- * Gets the battery level value.
43
- * @returns {number} Battery level value (as percentage).
44
- */
45
- getLevelValue(): number;
46
- /**
47
- * Handler for getting the current battery level (percentage).
48
- */
49
- getLevel(callback: CharacteristicGetCallback): void;
50
- /**
51
- * Sets the current battery level.
52
- * @param {number} percentage The battery percentage level to set.
53
- */
54
- setLevel(percentage: number): void;
55
- /**
56
- * Handler for getting the current battery charging state.
57
- */
58
- getChargeState(callback: CharacteristicGetCallback): void;
59
- /**
60
- * Sets the battery charging state according to predefined characteristic constants:
61
- * @param state {number} The desired charging state.
62
- */
63
- setChargeState(state: number): void;
64
- /**
65
- * Gets the battery current charge state.
66
- * @returns {number} The current battery charge state.
67
- */
68
- getChargeStateValue(): number;
69
- getServices(): Service[];
70
- }
1
+ import { AccessoryPlugin, API, CharacteristicGetCallback, Logging, Service } from 'homebridge';
2
+ import { SolaxPlatformAccessory } from './platformAccessory';
3
+ /**
4
+ * Enum with possible battery charging states.
5
+ */
6
+ export declare const BATTERY_CHARGING_STATE: {
7
+ NOT_CHARGING: number;
8
+ CHARGING: number;
9
+ NOT_CHARGEABLE: number;
10
+ };
11
+ /**
12
+ * Solax Battery Accessory.
13
+ * Battery sensor used to monitor inverter battery state of charge (SoC).
14
+ */
15
+ export declare class SolaxBatteryAccessory extends SolaxPlatformAccessory implements AccessoryPlugin {
16
+ /**
17
+ * The battery service for Homekit.
18
+ **/
19
+ private readonly batteryService;
20
+ /**
21
+ * The battery charge level (in percentage).
22
+ */
23
+ private batteryLevel;
24
+ /**
25
+ * Ambient light level.
26
+ */
27
+ private batteryChargeState;
28
+ /**
29
+ * Solax virtual light sensor class constructor.
30
+ * @param {Logging} log The platform logging for homebridge.
31
+ * @param {API} api The platform API.
32
+ * @param {string} name The accessory name.
33
+ * @param {string} serial "Real world" serial number for this accessory.
34
+ * @param {string} model Accessory model.
35
+ */
36
+ constructor(log: Logging, api: API, name: string, serial: string, model: string);
37
+ /**
38
+ * Handle requests to get the current value of the "Status Low Battery" characteristic.
39
+ */
40
+ getStatusLowBattery(): number;
41
+ /**
42
+ * Gets the battery level value.
43
+ * @returns {number} Battery level value (as percentage).
44
+ */
45
+ getLevelValue(): number;
46
+ /**
47
+ * Handler for getting the current battery level (percentage).
48
+ */
49
+ getLevel(callback: CharacteristicGetCallback): void;
50
+ /**
51
+ * Sets the current battery level.
52
+ * @param {number} percentage The battery percentage level to set.
53
+ */
54
+ setLevel(percentage: number): void;
55
+ /**
56
+ * Handler for getting the current battery charging state.
57
+ */
58
+ getChargeState(callback: CharacteristicGetCallback): void;
59
+ /**
60
+ * Sets the battery charging state according to predefined characteristic constants:
61
+ * @param state {number} The desired charging state.
62
+ */
63
+ setChargeState(state: number): void;
64
+ /**
65
+ * Gets the battery current charge state.
66
+ * @returns {number} The current battery charge state.
67
+ */
68
+ getChargeStateValue(): number;
69
+ getServices(): Service[];
70
+ }
71
71
  //# sourceMappingURL=batteryAccessory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"batteryAccessory.d.ts","sourceRoot":"","sources":["../src/batteryAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAA4B,yBAAyB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEzH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;CAIlC,CAAC;AAOF;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,sBAAuB,YAAW,eAAe;IAC1F;;QAEI;IACJ,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IAEzC;;OAEG;IACH,OAAO,CAAC,YAAY,CAAK;IAEzB;;OAEG;IACH,OAAO,CAAC,kBAAkB,CAAuC;IAEjE;;;;;;;OAOG;gBACS,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAwB/E;;OAEG;IACI,mBAAmB,IAAI,MAAM;IAepC;;;OAGG;IACI,aAAa,IAAI,MAAM;IAI9B;;OAEG;IACI,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAM1D;;;OAGG;IACI,QAAQ,CAAC,UAAU,EAAE,MAAM;IAQlC;;OAEG;IACI,cAAc,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAMhE;;;OAGG;IACI,cAAc,CAAC,KAAK,EAAE,MAAM;IAMnC;;;OAGG;IACI,mBAAmB,IAAI,MAAM;IAQpC,WAAW,IAAI,OAAO,EAAE;CAIzB"}
1
+ {"version":3,"file":"batteryAccessory.d.ts","sourceRoot":"","sources":["../src/batteryAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAA4B,yBAAyB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEzH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;CAIlC,CAAC;AAOF;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,sBAAuB,YAAW,eAAe;IAC1F;;QAEI;IACJ,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IAEzC;;OAEG;IACH,OAAO,CAAC,YAAY,CAAK;IAEzB;;OAEG;IACH,OAAO,CAAC,kBAAkB,CAAuC;IAEjE;;;;;;;OAOG;gBACS,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAwB/E;;OAEG;IACI,mBAAmB,IAAI,MAAM;IAepC;;;OAGG;IACI,aAAa,IAAI,MAAM;IAI9B;;OAEG;IACI,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAM1D;;;OAGG;IACI,QAAQ,CAAC,UAAU,EAAE,MAAM;IAQlC;;OAEG;IACI,cAAc,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAMhE;;;OAGG;IACI,cAAc,CAAC,KAAK,EAAE,MAAM;IAQnC;;;OAGG;IACI,mBAAmB,IAAI,MAAM;IAQpC,WAAW,IAAI,OAAO,EAAE;CAIzB"}
@@ -1,124 +1,125 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolaxBatteryAccessory = exports.BATTERY_CHARGING_STATE = void 0;
4
- const platformAccessory_1 = require("./platformAccessory");
5
- /**
6
- * Enum with possible battery charging states.
7
- */
8
- exports.BATTERY_CHARGING_STATE = {
9
- NOT_CHARGING: 0,
10
- CHARGING: 1,
11
- NOT_CHARGEABLE: 2,
12
- };
13
- /**
14
- * Minimum battery charge level for triggering a low battery level.
15
- */
16
- const LOW_BATTERY_THRESHOLD = 10;
17
- /**
18
- * Solax Battery Accessory.
19
- * Battery sensor used to monitor inverter battery state of charge (SoC).
20
- */
21
- class SolaxBatteryAccessory extends platformAccessory_1.SolaxPlatformAccessory {
22
- /**
23
- * Solax virtual light sensor class constructor.
24
- * @param {Logging} log The platform logging for homebridge.
25
- * @param {API} api The platform API.
26
- * @param {string} name The accessory name.
27
- * @param {string} serial "Real world" serial number for this accessory.
28
- * @param {string} model Accessory model.
29
- */
30
- constructor(log, api, name, serial, model) {
31
- super(log, api, name, serial, model);
32
- /**
33
- * The battery charge level (in percentage).
34
- */
35
- this.batteryLevel = 0;
36
- /**
37
- * Ambient light level.
38
- */
39
- this.batteryChargeState = exports.BATTERY_CHARGING_STATE.NOT_CHARGING;
40
- this.log.debug(`Creating battery "${this.name}"`);
41
- this.batteryService = new this.api.hap.Service.Battery(name);
42
- // handler for getting battery level
43
- this.batteryService
44
- .getCharacteristic(this.api.hap.Characteristic.BatteryLevel)
45
- .on("get" /* GET */, this.getLevel.bind(this));
46
- // handler for charging state
47
- this.batteryService
48
- .getCharacteristic(this.api.hap.Characteristic.ChargingState)
49
- .on("get" /* GET */, this.getChargeState.bind(this));
50
- // handler for low battery
51
- this.batteryService.getCharacteristic(this.api.hap.Characteristic.StatusLowBattery)
52
- .onGet(this.getStatusLowBattery.bind(this));
53
- log.info(`Battery "${name}" created!`);
54
- }
55
- /**
56
- * Handle requests to get the current value of the "Status Low Battery" characteristic.
57
- */
58
- getStatusLowBattery() {
59
- this.log.debug(`${this.name}: GET Status Low Battery`);
60
- let status;
61
- // set this to a valid value for StatusLowBattery
62
- if (this.getLevelValue() >= LOW_BATTERY_THRESHOLD) {
63
- status = this.api.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
64
- }
65
- else {
66
- status = this.api.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
67
- }
68
- return status;
69
- }
70
- /**
71
- * Gets the battery level value.
72
- * @returns {number} Battery level value (as percentage).
73
- */
74
- getLevelValue() {
75
- return this.batteryLevel;
76
- }
77
- /**
78
- * Handler for getting the current battery level (percentage).
79
- */
80
- getLevel(callback) {
81
- this.log.debug(`${this.name}: GET Level (percentage=${this.batteryLevel})`);
82
- callback(null, this.batteryLevel);
83
- }
84
- /**
85
- * Sets the current battery level.
86
- * @param {number} percentage The battery percentage level to set.
87
- */
88
- setLevel(percentage) {
89
- this.log.debug(`${this.name}: SET Level (percentage=${percentage})`);
90
- this.batteryLevel = percentage;
91
- this.batteryService.updateCharacteristic(this.api.hap.Characteristic.BatteryLevel, this.batteryLevel);
92
- }
93
- /**
94
- * Handler for getting the current battery charging state.
95
- */
96
- getChargeState(callback) {
97
- this.log.debug(`${this.name}: GET Charge State (status=${this.batteryChargeState})`);
98
- callback(null, this.batteryChargeState);
99
- }
100
- /**
101
- * Sets the battery charging state according to predefined characteristic constants:
102
- * @param state {number} The desired charging state.
103
- */
104
- setChargeState(state) {
105
- this.log.debug(`${this.name}: SET Charge State (state=${state})`);
106
- this.batteryService.updateCharacteristic(this.api.hap.Characteristic.ChargingState, state);
107
- }
108
- /**
109
- * Gets the battery current charge state.
110
- * @returns {number} The current battery charge state.
111
- */
112
- getChargeStateValue() {
113
- return this.batteryChargeState;
114
- }
115
- /*
116
- * This method is called directly after creation of this instance.
117
- * It should return all services which should be added to the accessory.
118
- */
119
- getServices() {
120
- return [this.informationService, this.batteryService];
121
- }
122
- }
123
- exports.SolaxBatteryAccessory = SolaxBatteryAccessory;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolaxBatteryAccessory = exports.BATTERY_CHARGING_STATE = void 0;
4
+ const platformAccessory_1 = require("./platformAccessory");
5
+ /**
6
+ * Enum with possible battery charging states.
7
+ */
8
+ exports.BATTERY_CHARGING_STATE = {
9
+ NOT_CHARGING: 0,
10
+ CHARGING: 1,
11
+ NOT_CHARGEABLE: 2,
12
+ };
13
+ /**
14
+ * Minimum battery charge level for triggering a low battery level.
15
+ */
16
+ const LOW_BATTERY_THRESHOLD = 10;
17
+ /**
18
+ * Solax Battery Accessory.
19
+ * Battery sensor used to monitor inverter battery state of charge (SoC).
20
+ */
21
+ class SolaxBatteryAccessory extends platformAccessory_1.SolaxPlatformAccessory {
22
+ /**
23
+ * Solax virtual light sensor class constructor.
24
+ * @param {Logging} log The platform logging for homebridge.
25
+ * @param {API} api The platform API.
26
+ * @param {string} name The accessory name.
27
+ * @param {string} serial "Real world" serial number for this accessory.
28
+ * @param {string} model Accessory model.
29
+ */
30
+ constructor(log, api, name, serial, model) {
31
+ super(log, api, name, serial, model);
32
+ /**
33
+ * The battery charge level (in percentage).
34
+ */
35
+ this.batteryLevel = 0;
36
+ /**
37
+ * Ambient light level.
38
+ */
39
+ this.batteryChargeState = exports.BATTERY_CHARGING_STATE.NOT_CHARGING;
40
+ this.log.debug(`Creating battery "${this.name}"`);
41
+ this.batteryService = new this.api.hap.Service.Battery(name);
42
+ // handler for getting battery level
43
+ this.batteryService
44
+ .getCharacteristic(this.api.hap.Characteristic.BatteryLevel)
45
+ .on("get" /* GET */, this.getLevel.bind(this));
46
+ // handler for charging state
47
+ this.batteryService
48
+ .getCharacteristic(this.api.hap.Characteristic.ChargingState)
49
+ .on("get" /* GET */, this.getChargeState.bind(this));
50
+ // handler for low battery
51
+ this.batteryService.getCharacteristic(this.api.hap.Characteristic.StatusLowBattery)
52
+ .onGet(this.getStatusLowBattery.bind(this));
53
+ log.info(`Battery "${name}" created!`);
54
+ }
55
+ /**
56
+ * Handle requests to get the current value of the "Status Low Battery" characteristic.
57
+ */
58
+ getStatusLowBattery() {
59
+ this.log.debug(`${this.name}: GET Status Low Battery`);
60
+ let status;
61
+ // set this to a valid value for StatusLowBattery
62
+ if (this.getLevelValue() >= LOW_BATTERY_THRESHOLD) {
63
+ status = this.api.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
64
+ }
65
+ else {
66
+ status = this.api.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
67
+ }
68
+ return status;
69
+ }
70
+ /**
71
+ * Gets the battery level value.
72
+ * @returns {number} Battery level value (as percentage).
73
+ */
74
+ getLevelValue() {
75
+ return this.batteryLevel;
76
+ }
77
+ /**
78
+ * Handler for getting the current battery level (percentage).
79
+ */
80
+ getLevel(callback) {
81
+ this.log.debug(`${this.name}: GET Level (percentage=${this.batteryLevel})`);
82
+ callback(null, this.batteryLevel);
83
+ }
84
+ /**
85
+ * Sets the current battery level.
86
+ * @param {number} percentage The battery percentage level to set.
87
+ */
88
+ setLevel(percentage) {
89
+ this.log.debug(`${this.name}: SET Level (percentage=${percentage})`);
90
+ this.batteryLevel = percentage;
91
+ this.batteryService.updateCharacteristic(this.api.hap.Characteristic.BatteryLevel, this.batteryLevel);
92
+ }
93
+ /**
94
+ * Handler for getting the current battery charging state.
95
+ */
96
+ getChargeState(callback) {
97
+ this.log.debug(`${this.name}: GET Charge State (status=${this.batteryChargeState})`);
98
+ callback(null, this.batteryChargeState);
99
+ }
100
+ /**
101
+ * Sets the battery charging state according to predefined characteristic constants:
102
+ * @param state {number} The desired charging state.
103
+ */
104
+ setChargeState(state) {
105
+ this.log.debug(`${this.name}: SET Charge State (state=${state})`);
106
+ this.batteryChargeState = state;
107
+ this.batteryService.updateCharacteristic(this.api.hap.Characteristic.ChargingState, state);
108
+ }
109
+ /**
110
+ * Gets the battery current charge state.
111
+ * @returns {number} The current battery charge state.
112
+ */
113
+ getChargeStateValue() {
114
+ return this.batteryChargeState;
115
+ }
116
+ /*
117
+ * This method is called directly after creation of this instance.
118
+ * It should return all services which should be added to the accessory.
119
+ */
120
+ getServices() {
121
+ return [this.informationService, this.batteryService];
122
+ }
123
+ }
124
+ exports.SolaxBatteryAccessory = SolaxBatteryAccessory;
124
125
  //# sourceMappingURL=batteryAccessory.js.map