homebridge-envoy-solar-sensor 0.1.4 → 0.1.6
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/index.js +18 -11
- package/package.json +4 -1
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { Agent } = require('undici');
|
|
3
|
+
const { Agent, request } = require('undici');
|
|
4
4
|
|
|
5
5
|
const PLUGIN_NAME = 'homebridge-envoy-solar-sensor';
|
|
6
6
|
const PLATFORM_NAME = 'EnvoySolarSensor';
|
|
@@ -203,10 +203,7 @@ class EnvoySolarPlatform {
|
|
|
203
203
|
const candidate = eim || production || inverters || productionArray[0];
|
|
204
204
|
const wNow = candidate && candidate.wNow;
|
|
205
205
|
|
|
206
|
-
if (typeof wNow !== 'number')
|
|
207
|
-
throw new Error('production.json mist wNow in production items');
|
|
208
|
-
}
|
|
209
|
-
|
|
206
|
+
if (typeof wNow !== 'number') throw new Error('production.json mist wNow in production items');
|
|
210
207
|
return Math.max(0, wNow);
|
|
211
208
|
}
|
|
212
209
|
|
|
@@ -232,13 +229,23 @@ class EnvoySolarPlatform {
|
|
|
232
229
|
? new Agent({ connect: { rejectUnauthorized: !allowInsecureTLS } })
|
|
233
230
|
: undefined;
|
|
234
231
|
|
|
235
|
-
|
|
232
|
+
try {
|
|
233
|
+
const res = await request(url, { method: 'GET', headers, dispatcher });
|
|
236
234
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
235
|
+
if (res.statusCode === 401 || res.statusCode === 403) {
|
|
236
|
+
throw new Error(`HTTP ${res.statusCode} unauthorized. Check token and that you pasted token only, without 'Bearer'.`);
|
|
237
|
+
}
|
|
241
238
|
|
|
242
|
-
|
|
239
|
+
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
240
|
+
const body = await res.body.text().catch(() => '');
|
|
241
|
+
throw new Error(`HTTP ${res.statusCode} op ${url} ${body}`);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const text = await res.body.text();
|
|
245
|
+
return JSON.parse(text);
|
|
246
|
+
} catch (e) {
|
|
247
|
+
const msg = e && e.message ? e.message : String(e);
|
|
248
|
+
throw new Error(`fetch failed: ${msg} url=${url} insecureTLS=${allowInsecureTLS}`);
|
|
249
|
+
}
|
|
243
250
|
}
|
|
244
251
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-envoy-solar-sensor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Expose Enphase Envoy solar production as a HomeKit sensor for daylight-based automations",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,9 @@
|
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"homebridge": ">=1.6.0"
|
|
36
36
|
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"undici": "^6.20.1"
|
|
39
|
+
},
|
|
37
40
|
"files": [
|
|
38
41
|
"index.js",
|
|
39
42
|
"config.schema.json",
|