Skip to content

Commit 5f336cd

Browse files
committed
### 0.7.2: Maintenance Release
**Enhancements** - a question to query logs #19
1 parent 9faad63 commit 5f336cd

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- max
77
- Time
88
- PV active power rate
9+
- a question to query logs #19
910

1011
### 0.7.1: Maintenance Release
1112

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ This function can be controlled via an option so that you don't always have to c
160160
| plantData | Boolean | true | True calls the description dataset of the plant. |
161161
| deviceData | Boolean | true | True calls the description dataset of the plantdevice. |
162162
| weather | Boolean | true | True calls the weather dataset of the plant. |
163+
| faultlog | Boolean | false | True retrieves the plant's fault logs. An array with the most recent event first is returned. |
164+
| faultlogdate | String | 'YYYY' | It is only taken into account if faultlog is true. It must be a string with the date in 'YYYY', 'YYYY-MM', 'YYYY-MM-DD'. |
163165
| plantId | Integer | undefined | The ID of a plant. So that the output can be restricted. Attention, the ID is constantly changing on demologin. |
164166
| totalData | Boolean | true | Retrieves the data integrals. The sums since start time. |
165167
| statusData | Boolean | true | This is not available for all systems. Here, the current operating status, fuel injection, battery charge and generation is called up. However, the data is also contained in historyLast. |
@@ -466,6 +468,48 @@ Therefore, the requests are placed in a queue and processed sequentially. If the
466468

467469
---
468470

471+
## getNewPlantFaultLog
472+
473+
| Parameter | Type | Default | Description |
474+
| --------- | ------- | ------- | -------------------------------------------------------------------- |
475+
| plantId | Integer | - | The plantId |
476+
| date | String | 'YYYY' | It must be a string with the date in 'YYYY', 'YYYY-MM', 'YYYY-MM-DD' |
477+
| deviceSn | String | '' | Inverters Serial number, can be an empty string to request all |
478+
| toPageNum | Integer | 1 | Go to a specific page |
479+
480+
It queries the fault log and returns the posts.
481+
482+
The answer is an object
483+
484+
| Parameter | Type | Description |
485+
| --------- | ------- | --------------- |
486+
| result | Integer | 1 => Ok |
487+
| obj | Object | Response object |
488+
489+
Response object
490+
491+
| Parameter | Type | Description |
492+
| --------- | --------------- | --------------------------------- |
493+
| pages | Integer | Number of possible pesponse pages |
494+
| currPage | Integer | Number of current pesponse page |
495+
| datas | Array of object | Message objects |
496+
| count | Integer | Messages in the array |
497+
498+
Response datas object as array
499+
500+
| Parameter | Type | Description |
501+
| ------------- | ------------- | ------------------------------------------------------ |
502+
| deviceType | String | Description of which device type |
503+
| eventId | String | Code for the event |
504+
| batSn | String | Serial number of the battery if the event came from it |
505+
| solution | String | A suggestion from Growatt |
506+
| eventSolution | String | Another suggestion from Growatt |
507+
| alias | String | The device's alias |
508+
| eventName | String | The name or description of the event |
509+
| sn | String | The serial number of the equipment |
510+
| time | String (date) | When it happened YYYY-MM-DD HH:MI:SS |
511+
| deviceSn | String | The serial number of the device |
512+
469513
## Speedup data interval new method
470514

471515
- Open the ShinePhone app

lib/growatt.js

+56
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,45 @@ module.exports = class growatt {
812812
}
813813
}
814814

815+
getNewPlantFaultLog(plantId, date = '', deviceSn = '', toPageNum = 1) {
816+
return new Promise((resolve, reject) => {
817+
const type = date === '' ? 4 : 4 - date.toString().split('-').length; // type = 1-day, 2-month, 3-year
818+
const params = new Url.URLSearchParams({
819+
plantId,
820+
date, // can be empty, YYYY, YYYY-MM, YYYY-MM-DD
821+
deviceSn, // to filter by device serial number
822+
toPageNum, // page of the logs
823+
type,
824+
});
825+
debugApi('getNewPlantFaultLog:', 'plantId:', plantId, 'date:', date, 'deviceSn:', deviceSn, 'toPageNum:', toPageNum, 'type:', type);
826+
if (this.lifeSignCallback) this.lifeSignCallback();
827+
this.axios
828+
.post(this.getUrl('/log/getNewPlantFaultLog'), params.toString(), { headers: this.makeCallHeader() })
829+
.then(res => {
830+
debugVerbose('getNewPlantFaultLog result:', res);
831+
if (res.data && res.data.result && res.data.result === 1) {
832+
debugApi('getNewPlantFaultLog resolve:', res);
833+
resolve(res.data);
834+
} else if (res.data && res.data.result) {
835+
debugApi('getPlantData reject:', res.data);
836+
reject(new Error(JSON.stringify(res.data, getJSONCircularReplacer())));
837+
} else {
838+
debugApi('getNewPlantFaultLog reject');
839+
if (res.request.path.match('errorMess')) {
840+
reject(new Error(`The server sent an unexpected response: ${res.request.path}`));
841+
} else {
842+
reject(new Error('The server sent an unexpected response, a fatal error has occurred'));
843+
}
844+
}
845+
})
846+
.catch(e => {
847+
this.connected = false;
848+
debugApi('getPlantData err:', JSON.stringify(e, getJSONCircularReplacer(), ' '));
849+
reject(e);
850+
});
851+
});
852+
}
853+
815854
getAllPlantData(opt) {
816855
/* eslint-disable-next-line no-async-promise-executor */
817856
return new Promise(async (resolve, reject) => {
@@ -830,6 +869,12 @@ module.exports = class growatt {
830869
if (typeof options.weather === 'undefined') {
831870
options.weather = true;
832871
}
872+
if (typeof options.faultlog === 'undefined') {
873+
options.faultlog = false;
874+
}
875+
if (typeof options.faultlogdate === 'undefined') {
876+
options.faultlogdate = new Date().getFullYear().toString();
877+
}
833878
debugApi('getAllPlantData', 'options:', options);
834879
const plants = await this.getPlatList().catch(e => {
835880
debugApi('getAllPlantData getPlatList err:', e);
@@ -862,6 +907,17 @@ module.exports = class growatt {
862907
result[plant.id].weather = weather.obj;
863908
}
864909
}
910+
if (options.faultlog) {
911+
result[plant.id].faultlog = {};
912+
/* eslint-disable-next-line no-await-in-loop */
913+
const faultlog = await this.getNewPlantFaultLog(plant.id, options.faultlogdate).catch(e => {
914+
debugApi('getAllPlantData getNewPlantFaultLog err:', e);
915+
reject(e);
916+
});
917+
if (faultlog && faultlog.obj && faultlog.obj.datas) {
918+
result[plant.id].faultlog = faultlog.obj.datas;
919+
}
920+
}
865921
/* eslint-disable-next-line no-await-in-loop */
866922
result[plant.id].devices = await this.getAllPlantDeviceData(plant.id, options).catch(e => {
867923
debugApi('getAllPlantData getAllPlantDeviceData err:', e);

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)