Skip to content

Commit

Permalink
The array will be converted into timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
PLCHome committed Jan 27, 2024
1 parent 5f336cd commit 931baa9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ This function can be controlled via an option so that you don't always have to c
| plantData | Boolean | true | True calls the description dataset of the plant. |
| deviceData | Boolean | true | True calls the description dataset of the plantdevice. |
| weather | Boolean | true | True calls the weather dataset of the plant. |
| faultlog | Boolean | false | True retrieves the plant's fault logs. An array with the most recent event first is returned. |
| 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'. |
| faultlog | Boolean | false | True retrieves the plant's fault logs. An array with the most recent event first is returned. |
| 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'. |
| faultlogdateindex | Boolean | true | It is only taken into account if faultlog is true. The array is converted into timestampsobjects. |
| plantId | Integer | undefined | The ID of a plant. So that the output can be restricted. Attention, the ID is constantly changing on demologin. |
| totalData | Boolean | true | Retrieves the data integrals. The sums since start time. |
| 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. |
Expand Down
22 changes: 21 additions & 1 deletion lib/growatt.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,9 @@ module.exports = class growatt {
if (typeof options.faultlogdate === 'undefined') {
options.faultlogdate = new Date().getFullYear().toString();
}
if (typeof options.faultlogdateindex === 'undefined') {
options.faultlogdateindex = true;
}
debugApi('getAllPlantData', 'options:', options);
const plants = await this.getPlatList().catch(e => {
debugApi('getAllPlantData getPlatList err:', e);
Expand Down Expand Up @@ -915,7 +918,24 @@ module.exports = class growatt {
reject(e);
});
if (faultlog && faultlog.obj && faultlog.obj.datas) {
result[plant.id].faultlog = faultlog.obj.datas;
if (options.faultlogdateindex) {
let c = 0;
for (let l = faultlog.obj.datas.length - 1; l >= 0; l -= 1) {
if (faultlog.obj.datas[l].time) {
if (result[plant.id].faultlog[faultlog.obj.datas[l].time]) {
c += 1;
result[plant.id].faultlog[`${faultlog.obj.datas[l].time}_${c}`] = faultlog.obj.datas[l];
} else {
c = 0;
result[plant.id].faultlog[faultlog.obj.datas[l].time] = faultlog.obj.datas[l];
}
} else {
result[plant.id].faultlog[l] = faultlog.obj.datas[l];
}
}
} else {
result[plant.id].faultlog = faultlog.obj.datas;
}
}
}
/* eslint-disable-next-line no-await-in-loop */
Expand Down

0 comments on commit 931baa9

Please sign in to comment.