homebridge-enphase-envoy 9.7.1 → 9.7.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/CHANGELOG.md +6 -0
- package/index.js +3 -3
- package/package.json +1 -1
- package/src/restful.js +16 -8
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [9.7.3] - (04.02.2025)
|
|
9
|
+
|
|
10
|
+
## Changes
|
|
11
|
+
|
|
12
|
+
- update RESTFul
|
|
13
|
+
|
|
8
14
|
## [9.7.0] - (16.01.2025)
|
|
9
15
|
|
|
10
16
|
## Changes
|
package/index.js
CHANGED
|
@@ -117,7 +117,7 @@ class EnvoyPlatform {
|
|
|
117
117
|
const emitLog = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
|
|
118
118
|
})
|
|
119
119
|
.on('warn', (warn) => {
|
|
120
|
-
const
|
|
120
|
+
const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, ${warn}.`);
|
|
121
121
|
})
|
|
122
122
|
.on('error', (error) => {
|
|
123
123
|
const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, ${error}.`);
|
|
@@ -128,7 +128,7 @@ class EnvoyPlatform {
|
|
|
128
128
|
impulseGenerator.on('start', async () => {
|
|
129
129
|
try {
|
|
130
130
|
const startDone = await envoyDevice.start();
|
|
131
|
-
const stopImpulseGenerator = startDone ? impulseGenerator.stop() : false;
|
|
131
|
+
const stopImpulseGenerator = startDone ? await impulseGenerator.stop() : false;
|
|
132
132
|
} catch (error) {
|
|
133
133
|
const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, ${error}, trying again.`);
|
|
134
134
|
};
|
|
@@ -137,7 +137,7 @@ class EnvoyPlatform {
|
|
|
137
137
|
});
|
|
138
138
|
|
|
139
139
|
//start impulse generator
|
|
140
|
-
impulseGenerator.start([{ name: 'start', sampling: 45000 }]);
|
|
140
|
+
await impulseGenerator.start([{ name: 'start', sampling: 45000 }]);
|
|
141
141
|
} catch (error) {
|
|
142
142
|
throw new Error(`Device: ${host} ${deviceName}, Did finish launching error: ${error}.`);
|
|
143
143
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"private": false,
|
|
3
3
|
"displayName": "Enphase Envoy",
|
|
4
4
|
"name": "homebridge-enphase-envoy",
|
|
5
|
-
"version": "9.7.
|
|
5
|
+
"version": "9.7.3",
|
|
6
6
|
"description": "Homebridge plugin for Photovoltaic Energy System manufactured by Enphase.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "grzegorz914",
|
package/src/restful.js
CHANGED
|
@@ -40,6 +40,8 @@ class RestFul extends EventEmitter {
|
|
|
40
40
|
const restFul = express();
|
|
41
41
|
restFul.set('json spaces', 2);
|
|
42
42
|
restFul.use(json());
|
|
43
|
+
|
|
44
|
+
// GET Routes
|
|
43
45
|
restFul.get('/token', (req, res) => { res.json(this.restFulData.token) });
|
|
44
46
|
restFul.get('/info', (req, res) => { res.json(this.restFulData.info) });
|
|
45
47
|
restFul.get('/home', (req, res) => { res.json(this.restFulData.home) });
|
|
@@ -63,24 +65,30 @@ class RestFul extends EventEmitter {
|
|
|
63
65
|
restFul.get('/plclevel', (req, res) => { res.json(this.restFulData.plcLevel) });
|
|
64
66
|
restFul.get('/datasampling', (req, res) => { res.json(this.restFulData.dataSampling) });
|
|
65
67
|
|
|
66
|
-
//
|
|
68
|
+
// POST Route
|
|
67
69
|
restFul.post('/', (req, res) => {
|
|
68
70
|
try {
|
|
69
71
|
const obj = req.body;
|
|
70
|
-
|
|
72
|
+
if (!obj || typeof obj !== 'object' || Object.keys(obj).length === 0) {
|
|
73
|
+
this.emit('warn', `RESTFul Invalid JSON payload`);
|
|
74
|
+
return res.status(400).json({ error: 'RESTFul Invalid JSON payload' });
|
|
75
|
+
}
|
|
71
76
|
const key = Object.keys(obj)[0];
|
|
72
|
-
const value =
|
|
77
|
+
const value = obj[key];
|
|
73
78
|
this.emit('set', key, value);
|
|
74
|
-
|
|
79
|
+
|
|
80
|
+
const emitDebug = this.restFulDebug ? this.emit('debug', `RESTFul post data: ${JSON.stringify(obj, null, 2)}`) : false;
|
|
81
|
+
res.json({ success: true, received: obj });
|
|
75
82
|
} catch (error) {
|
|
76
|
-
this.emit('warn', `RESTFul Parse
|
|
77
|
-
|
|
83
|
+
this.emit('warn', `RESTFul Parse error: ${error}`);
|
|
84
|
+
res.status(500).json({ error: 'RESTFul Internal Server Error' });
|
|
85
|
+
}
|
|
78
86
|
});
|
|
79
87
|
|
|
88
|
+
// Start server
|
|
80
89
|
restFul.listen(this.restFulPort, () => {
|
|
81
|
-
this.emit('connected', `RESTful started on port: ${this.restFulPort}`)
|
|
90
|
+
this.emit('connected', `RESTful started on port: ${this.restFulPort}`);
|
|
82
91
|
});
|
|
83
|
-
|
|
84
92
|
} catch (error) {
|
|
85
93
|
this.emit('warn', `RESTful Connect error: ${error}`)
|
|
86
94
|
}
|