Skip to content

Commit

Permalink
### 0.7.2: Maintenance Release
Browse files Browse the repository at this point in the history
**Enhancements**

- a question to query logs #19
  • Loading branch information
PLCHome committed Jan 27, 2024
1 parent 9faad63 commit 5f336cd
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- max
- Time
- PV active power rate
- a question to query logs #19

### 0.7.1: Maintenance Release

Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ 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'. |
| 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 Expand Up @@ -466,6 +468,48 @@ Therefore, the requests are placed in a queue and processed sequentially. If the

---

## getNewPlantFaultLog

| Parameter | Type | Default | Description |
| --------- | ------- | ------- | -------------------------------------------------------------------- |
| plantId | Integer | - | The plantId |
| date | String | 'YYYY' | It must be a string with the date in 'YYYY', 'YYYY-MM', 'YYYY-MM-DD' |
| deviceSn | String | '' | Inverters Serial number, can be an empty string to request all |
| toPageNum | Integer | 1 | Go to a specific page |

It queries the fault log and returns the posts.

The answer is an object

| Parameter | Type | Description |
| --------- | ------- | --------------- |
| result | Integer | 1 => Ok |
| obj | Object | Response object |

Response object

| Parameter | Type | Description |
| --------- | --------------- | --------------------------------- |
| pages | Integer | Number of possible pesponse pages |
| currPage | Integer | Number of current pesponse page |
| datas | Array of object | Message objects |
| count | Integer | Messages in the array |

Response datas object as array

| Parameter | Type | Description |
| ------------- | ------------- | ------------------------------------------------------ |
| deviceType | String | Description of which device type |
| eventId | String | Code for the event |
| batSn | String | Serial number of the battery if the event came from it |
| solution | String | A suggestion from Growatt |
| eventSolution | String | Another suggestion from Growatt |
| alias | String | The device's alias |
| eventName | String | The name or description of the event |
| sn | String | The serial number of the equipment |
| time | String (date) | When it happened YYYY-MM-DD HH:MI:SS |
| deviceSn | String | The serial number of the device |

## Speedup data interval new method

- Open the ShinePhone app
Expand Down
56 changes: 56 additions & 0 deletions lib/growatt.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,45 @@ module.exports = class growatt {
}
}

getNewPlantFaultLog(plantId, date = '', deviceSn = '', toPageNum = 1) {
return new Promise((resolve, reject) => {
const type = date === '' ? 4 : 4 - date.toString().split('-').length; // type = 1-day, 2-month, 3-year
const params = new Url.URLSearchParams({
plantId,
date, // can be empty, YYYY, YYYY-MM, YYYY-MM-DD
deviceSn, // to filter by device serial number
toPageNum, // page of the logs
type,
});
debugApi('getNewPlantFaultLog:', 'plantId:', plantId, 'date:', date, 'deviceSn:', deviceSn, 'toPageNum:', toPageNum, 'type:', type);
if (this.lifeSignCallback) this.lifeSignCallback();
this.axios
.post(this.getUrl('/log/getNewPlantFaultLog'), params.toString(), { headers: this.makeCallHeader() })
.then(res => {
debugVerbose('getNewPlantFaultLog result:', res);
if (res.data && res.data.result && res.data.result === 1) {
debugApi('getNewPlantFaultLog resolve:', res);
resolve(res.data);
} else if (res.data && res.data.result) {
debugApi('getPlantData reject:', res.data);
reject(new Error(JSON.stringify(res.data, getJSONCircularReplacer())));
} else {
debugApi('getNewPlantFaultLog reject');
if (res.request.path.match('errorMess')) {
reject(new Error(`The server sent an unexpected response: ${res.request.path}`));
} else {
reject(new Error('The server sent an unexpected response, a fatal error has occurred'));
}
}
})
.catch(e => {
this.connected = false;
debugApi('getPlantData err:', JSON.stringify(e, getJSONCircularReplacer(), ' '));
reject(e);
});
});
}

getAllPlantData(opt) {
/* eslint-disable-next-line no-async-promise-executor */
return new Promise(async (resolve, reject) => {
Expand All @@ -830,6 +869,12 @@ module.exports = class growatt {
if (typeof options.weather === 'undefined') {
options.weather = true;
}
if (typeof options.faultlog === 'undefined') {
options.faultlog = false;
}
if (typeof options.faultlogdate === 'undefined') {
options.faultlogdate = new Date().getFullYear().toString();
}
debugApi('getAllPlantData', 'options:', options);
const plants = await this.getPlatList().catch(e => {
debugApi('getAllPlantData getPlatList err:', e);
Expand Down Expand Up @@ -862,6 +907,17 @@ module.exports = class growatt {
result[plant.id].weather = weather.obj;
}
}
if (options.faultlog) {
result[plant.id].faultlog = {};
/* eslint-disable-next-line no-await-in-loop */
const faultlog = await this.getNewPlantFaultLog(plant.id, options.faultlogdate).catch(e => {
debugApi('getAllPlantData getNewPlantFaultLog err:', e);
reject(e);
});
if (faultlog && faultlog.obj && faultlog.obj.datas) {
result[plant.id].faultlog = faultlog.obj.datas;
}
}
/* eslint-disable-next-line no-await-in-loop */
result[plant.id].devices = await this.getAllPlantDeviceData(plant.id, options).catch(e => {
debugApi('getAllPlantData getAllPlantDeviceData err:', e);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f336cd

Please sign in to comment.