homebridge-solaxcloud-api 1.5.1 → 2.0.3
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 +28 -18
- package/config.schema.json +28 -0
- package/dist/lightSensorAccessory.d.ts +36 -0
- package/dist/lightSensorAccessory.d.ts.map +1 -0
- package/dist/lightSensorAccessory.js +60 -0
- package/dist/lightSensorAccessory.js.map +1 -0
- package/dist/outletAccessory.d.ts +23 -4
- package/dist/outletAccessory.d.ts.map +1 -1
- package/dist/outletAccessory.js +69 -17
- package/dist/outletAccessory.js.map +1 -1
- package/dist/platform.d.ts +45 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +231 -67
- package/dist/platform.js.map +1 -1
- package/dist/platformAccessory.d.ts +5 -0
- package/dist/platformAccessory.d.ts.map +1 -1
- package/dist/platformAccessory.js +10 -3
- package/dist/platformAccessory.js.map +1 -1
- package/dist/platformMeters.d.ts +53 -0
- package/dist/platformMeters.d.ts.map +1 -0
- package/dist/platformMeters.js +3 -0
- package/dist/platformMeters.js.map +1 -0
- package/dist/solaxcloudfetch.d.ts +2 -0
- package/dist/solaxcloudfetch.d.ts.map +1 -0
- package/dist/solaxcloudfetch.js +19 -0
- package/dist/solaxcloudfetch.js.map +1 -0
- package/dist/statistics.d.ts +36 -1
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +86 -16
- package/dist/statistics.js.map +1 -1
- package/images/homebridge-ui.png +0 -0
- package/images/plugin-accessories-home-pure.png +0 -0
- package/images/plugin-accessories-home.png +0 -0
- package/images/plugin-outlet-consumption.png +0 -0
- package/package.json +3 -3
- package/test/solaxcloudapi.test.ts +1 -1
- package/test/statistics.test.ts +51 -0
package/dist/statistics.js
CHANGED
|
@@ -1,19 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
exports.Statistics = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Statistics.
|
|
6
|
+
* This class is used for statistical calculations for the purpose of smoothing a series of value.
|
|
7
|
+
*/
|
|
8
|
+
class Statistics {
|
|
9
|
+
/**
|
|
10
|
+
* Simple moving average calculation from a series of values.
|
|
11
|
+
* Formula is
|
|
12
|
+
* SMA = (V1 + V2 + ... + Vn) / n
|
|
13
|
+
* where
|
|
14
|
+
* Vn = Series value for period n
|
|
15
|
+
* n = number values in period
|
|
16
|
+
* @param {number[]} series Array with series of values.
|
|
17
|
+
* @param {number} windowSize Size of moving average window.
|
|
18
|
+
* @param {number} maxCalculations Maximum calculations to be performed.
|
|
19
|
+
* @returns {number[]} Array with simple moving averages from series.
|
|
20
|
+
*/
|
|
21
|
+
static simpleMovingAverage(series, windowSize, maxCalculations = Infinity) {
|
|
22
|
+
const result = [];
|
|
23
|
+
// sanity check
|
|
24
|
+
if (!series || !windowSize || series.length < windowSize) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
// first index to compute
|
|
28
|
+
let index = windowSize - 1;
|
|
29
|
+
// max series lenght
|
|
30
|
+
const length = series.length + 1;
|
|
31
|
+
// number of simple moving averages calculated
|
|
32
|
+
let numberOfSMAsCalculated = 0;
|
|
33
|
+
// loop over series array
|
|
34
|
+
while (++index < length && numberOfSMAsCalculated++ < maxCalculations) {
|
|
35
|
+
// create array with window slice only
|
|
36
|
+
const windowSlice = series.slice(index - windowSize, index);
|
|
37
|
+
// compute slice sum
|
|
38
|
+
const sum = windowSlice.reduce((prev, curr) => prev + curr, 0);
|
|
39
|
+
// push new moving average to result
|
|
40
|
+
result.push(sum / windowSize);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Exponential moving average calculation from a series of values.
|
|
46
|
+
* Formula is
|
|
47
|
+
* EMAn = (Vn - EMAn-1) * weight + EMAn-1
|
|
48
|
+
* where
|
|
49
|
+
* EMAn = Exponential Moving Average for period n
|
|
50
|
+
* EMAn-1 = Exponential Moving Average for period n - 1
|
|
51
|
+
* Vn = Series value for period n
|
|
52
|
+
* weight = multiplier to use lower weights for older value
|
|
53
|
+
* w = window size
|
|
54
|
+
* and
|
|
55
|
+
* weight = 2 / (w + 1)
|
|
56
|
+
* @param {number[]} series Array with series of values.
|
|
57
|
+
* @param {number} windowSize Size of moving average window.
|
|
58
|
+
* @returns {number[]} Array with exponential moving averages from series.
|
|
59
|
+
*/
|
|
60
|
+
static exponentialMovingAverage(series, windowSize) {
|
|
61
|
+
const result = [];
|
|
62
|
+
// sanity check
|
|
63
|
+
if (!series || !windowSize || series.length < windowSize) {
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
// first index to compute
|
|
67
|
+
let index = windowSize - 1;
|
|
68
|
+
// set previous EMA index
|
|
69
|
+
let previousEmaIndex = 0;
|
|
70
|
+
// setup smoothing factor
|
|
71
|
+
const smoothingFactor = 2 / (windowSize + 1);
|
|
72
|
+
// calculate first EMA using SMA
|
|
73
|
+
const [SMA] = Statistics.simpleMovingAverage(series, windowSize, 1);
|
|
74
|
+
result.push(SMA);
|
|
75
|
+
// loop over series array
|
|
76
|
+
while (++index < series.length) {
|
|
77
|
+
// get current value
|
|
78
|
+
const value = series[index];
|
|
79
|
+
// get previous EMA
|
|
80
|
+
const previousEMA = result[previousEmaIndex++];
|
|
81
|
+
// calculate current EMA
|
|
82
|
+
const currentEMA = (value - previousEMA) * smoothingFactor + previousEMA;
|
|
83
|
+
result.push(currentEMA);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.Statistics = Statistics;
|
|
19
89
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"statistics.js","sourceRoot":"","sources":["../src/statistics.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,UAAU;IAErB;;;;;;;;;;;SAWK;IACE,MAAM,CAAC,mBAAmB,CAAC,MAAgB,EAAE,UAAkB,EAAE,eAAe,GAAG,QAAQ;QAChG,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,eAAe;QACf,IAAI,CAAC,MAAM,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,GAAG,UAAU,EAAE;YACxD,OAAO,MAAM,CAAC;SACf;QAED,yBAAyB;QACzB,IAAI,KAAK,GAAG,UAAU,GAAG,CAAC,CAAC;QAE3B,oBAAoB;QACpB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAEjC,8CAA8C;QAC9C,IAAI,sBAAsB,GAAG,CAAC,CAAC;QAE/B,yBAAyB;QACzB,OAAO,EAAE,KAAK,GAAG,MAAM,IAAI,sBAAsB,EAAE,GAAG,eAAe,EAAE;YACrE,sCAAsC;YACtC,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,EAAE,KAAK,CAAC,CAAC;YAE5D,oBAAoB;YACpB,MAAM,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC;YAE/D,oCAAoC;YACpC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC;SAC/B;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;;;;;;;;;SAeK;IACE,MAAM,CAAC,wBAAwB,CAAC,MAAgB,EAAE,UAAkB;QACzE,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,eAAe;QACf,IAAI,CAAC,MAAM,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,GAAG,UAAU,EAAE;YACxD,OAAO,MAAM,CAAC;SACf;QAED,yBAAyB;QACzB,IAAI,KAAK,GAAG,UAAU,GAAG,CAAC,CAAC;QAE3B,yBAAyB;QACzB,IAAI,gBAAgB,GAAG,CAAC,CAAC;QAEzB,yBAAyB;QACzB,MAAM,eAAe,GAAG,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QAE7C,gCAAgC;QAChC,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QACpE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEjB,yBAAyB;QACzB,OAAO,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE;YAC9B,oBAAoB;YACpB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAE5B,mBAAmB;YACnB,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;YAE/C,wBAAwB;YACxB,MAAM,UAAU,GAAG,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,eAAe,GAAG,WAAW,CAAC;YAEzE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SACzB;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CAEF;AApGD,gCAoGC"}
|
package/images/homebridge-ui.png
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"private": false,
|
|
3
3
|
"displayName": "Homebridge Solax Cloud API",
|
|
4
4
|
"name": "homebridge-solaxcloud-api",
|
|
5
|
-
"version": "
|
|
6
|
-
"description": "Integrates solar production info using public Solax Cloud API into Homebrigde
|
|
5
|
+
"version": "2.0.3",
|
|
6
|
+
"description": "Integrates solar production info using public Solax Cloud API into Homebrigde accessories.",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"main": "dist/index.js",
|
|
20
20
|
"scripts": {
|
|
21
|
-
"test": "mocha --
|
|
21
|
+
"test": "mocha --require ts-node/register test/**/*.test.ts",
|
|
22
22
|
"lint": "eslint src/**.ts --max-warnings=0",
|
|
23
23
|
"watch": "npm run build && npm link && nodemon",
|
|
24
24
|
"build": "rimraf ./dist && tsc",
|
|
@@ -2,7 +2,7 @@ import { SolaxCloudAPI, SolaxCloudAPIResponse } from '../src/solaxcloudapi';
|
|
|
2
2
|
|
|
3
3
|
import assert = require('assert');
|
|
4
4
|
|
|
5
|
-
describe('Static methods', () => {
|
|
5
|
+
describe('SolaxCloudAPI: Static methods', () => {
|
|
6
6
|
|
|
7
7
|
const sampleReply: SolaxCloudAPIResponse = {
|
|
8
8
|
success: true,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Statistics } from '../src/statistics';
|
|
2
|
+
|
|
3
|
+
import assert = require('assert');
|
|
4
|
+
|
|
5
|
+
describe('Statistics: Smoothing methods', () => {
|
|
6
|
+
const sampleSeries = [1, 3, 5, 3, 7, 6, 8, 5, 8, 8, 4, 5];
|
|
7
|
+
|
|
8
|
+
it('Simple Moving Average (sanity checks)', () => {
|
|
9
|
+
// window size too big
|
|
10
|
+
assert.deepEqual(Statistics.simpleMovingAverage(sampleSeries, 100), []);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('Simple Moving Average', () => {
|
|
14
|
+
assert.deepEqual(
|
|
15
|
+
Statistics.simpleMovingAverage(sampleSeries, 4),
|
|
16
|
+
[
|
|
17
|
+
3,
|
|
18
|
+
4.5,
|
|
19
|
+
5.25,
|
|
20
|
+
6,
|
|
21
|
+
6.5,
|
|
22
|
+
6.75,
|
|
23
|
+
7.25,
|
|
24
|
+
6.25,
|
|
25
|
+
6.25],
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('Exponential Moving Average (sanity checks)', () => {
|
|
30
|
+
// window size too big
|
|
31
|
+
assert.deepEqual(Statistics.exponentialMovingAverage(sampleSeries, 100), []);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('Exponential Moving Average', () => {
|
|
35
|
+
assert.deepEqual(
|
|
36
|
+
Statistics.exponentialMovingAverage(sampleSeries, 4),
|
|
37
|
+
[
|
|
38
|
+
3,
|
|
39
|
+
4.6,
|
|
40
|
+
5.16,
|
|
41
|
+
6.296,
|
|
42
|
+
5.7776000000000005,
|
|
43
|
+
6.6665600000000005,
|
|
44
|
+
7.199936,
|
|
45
|
+
5.9199616,
|
|
46
|
+
5.55197696,
|
|
47
|
+
],
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
});
|