Skip to content

Commit 931baa9

Browse files
committed
The array will be converted into timestamps
1 parent 5f336cd commit 931baa9

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ 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'. |
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'. |
165+
| faultlogdateindex | Boolean | true | It is only taken into account if faultlog is true. The array is converted into timestampsobjects. |
165166
| plantId | Integer | undefined | The ID of a plant. So that the output can be restricted. Attention, the ID is constantly changing on demologin. |
166167
| totalData | Boolean | true | Retrieves the data integrals. The sums since start time. |
167168
| 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. |

lib/growatt.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,9 @@ module.exports = class growatt {
875875
if (typeof options.faultlogdate === 'undefined') {
876876
options.faultlogdate = new Date().getFullYear().toString();
877877
}
878+
if (typeof options.faultlogdateindex === 'undefined') {
879+
options.faultlogdateindex = true;
880+
}
878881
debugApi('getAllPlantData', 'options:', options);
879882
const plants = await this.getPlatList().catch(e => {
880883
debugApi('getAllPlantData getPlatList err:', e);
@@ -915,7 +918,24 @@ module.exports = class growatt {
915918
reject(e);
916919
});
917920
if (faultlog && faultlog.obj && faultlog.obj.datas) {
918-
result[plant.id].faultlog = faultlog.obj.datas;
921+
if (options.faultlogdateindex) {
922+
let c = 0;
923+
for (let l = faultlog.obj.datas.length - 1; l >= 0; l -= 1) {
924+
if (faultlog.obj.datas[l].time) {
925+
if (result[plant.id].faultlog[faultlog.obj.datas[l].time]) {
926+
c += 1;
927+
result[plant.id].faultlog[`${faultlog.obj.datas[l].time}_${c}`] = faultlog.obj.datas[l];
928+
} else {
929+
c = 0;
930+
result[plant.id].faultlog[faultlog.obj.datas[l].time] = faultlog.obj.datas[l];
931+
}
932+
} else {
933+
result[plant.id].faultlog[l] = faultlog.obj.datas[l];
934+
}
935+
}
936+
} else {
937+
result[plant.id].faultlog = faultlog.obj.datas;
938+
}
919939
}
920940
}
921941
/* eslint-disable-next-line no-await-in-loop */

0 commit comments

Comments
 (0)