Skip to content

Commit

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

- Add switch indexCandI to the config Objekt.
  - Set to true if your Growatt page Plant is a C&I Plant page with indexbC or plantDo in the Path from the Growatt webinterface.
  • Loading branch information
PLCHome committed Aug 8, 2023
1 parent 5b3166c commit 878b61d
Show file tree
Hide file tree
Showing 5 changed files with 845 additions and 114 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### 0.6.0: Maintenance Release

**Enhancements**

- Add switch indexCandI to the config Objekt.
- Set to true if your Growatt page Plant is a C&I Plant page with indexbC or plantDo in the Path from the Growatt webinterface.

### 0.5.6: Maintenance Release

**Fixes**
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ The constructor has a config object as parameter. This is optional.

### Config

| config | Type | Default | Description |
| ---------------- | -------- | ---------------------------- | ------------------------------------------------- |
| server | String | 'https://server.growatt.com' | The Growatt server |
| timeout | Integer | 5000 | Session timeout in ms. |
| headers | Object | {} | custom header like {'X-Custom-Header': 'foobar'}. |
| lifeSignCallback | function | undefined | Called before each Axios call. |
| config | Type | Default | Description |
| ---------------- | -------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| server | String | 'https://server.growatt.com' | The Growatt server |
| indexCandI | Boolean | false | Set to true if your Growatt page Plant is a C&I Plant page with indexbC or plantDo in the Path from the Growatt webinterface. |
| timeout | Integer | 5000 | Session timeout in ms. |
| headers | Object | {} | custom header like {'X-Custom-Header': 'foobar'}. |
| lifeSignCallback | function | undefined | Called before each Axios call. |

```
const api = require('growatt')
Expand Down
19 changes: 14 additions & 5 deletions lib/growatt.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

const Url = require('url');
const https = require('https');
const debugApi = require('debug')('growatt:api');
const debugVerbose = require('debug')('growatt:verbose');
const Axios = require('axios');
const Url = require('url');
const https = require('https');
const QUEUE = require('./queue');
const GROWATTTYPE = require('./growatttype');
const PARSEIN = require('./parsein');

const server = 'https://server.growatt.com';
const index = 'index';
const indexbC = 'indexbC';
const timeout = 50000;
const headers = {};

Expand Down Expand Up @@ -66,10 +68,12 @@ const getJSONCircularReplacer = () => {
module.exports = class growatt {
constructor(conf) {
this.config = conf;
debugApi('constructor in config:', this.config);
if (typeof this.config !== 'object') this.config = {};
if (typeof this.config.timeout === 'undefined') this.config.timeout = timeout;
if (typeof this.config.headers === 'undefined') this.config.headers = headers;
if (typeof this.config.server === 'undefined' || this.config.server === '') this.config.server = server;
if (typeof this.config.indexCandI === 'undefined') this.config.indexCandI = false;
this.queue = new QUEUE();
this.connected = false;
this.cookie = '';
Expand All @@ -81,12 +85,17 @@ module.exports = class growatt {
httpsAgent,
});
if (typeof this.config.lifeSignCallback !== 'undefined') this.lifeSignCallback = this.config.lifeSignCallback;
debugApi('constructor config:', this.config);
}

getUrl(path) {
return this.config.server + path;
}

getIndex() {
return this.config.indexCandI ? indexbC : index;
}

isConnected() {
return this.connected;
}
Expand Down Expand Up @@ -114,7 +123,7 @@ module.exports = class growatt {
//
} else {
head.cookie = this.cookie;
head.Referer = `${this.config.server}/index;jsessionid=${this.extractSession()}`;
head.Referer = `${this.config.server}/${this.getIndex()};jsessionid=${this.extractSession()}`;
// head.Accept = 'application/json, text/javascript, */*; q=0.01'
// head['Content-Length'] = 64
// head['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
Expand Down Expand Up @@ -248,7 +257,7 @@ module.exports = class growatt {
debugApi('getPlatList:');
if (this.lifeSignCallback) this.lifeSignCallback();
this.axios
.post(this.getUrl('/index/getPlantListTitle'), null, { headers: this.makeCallHeader() })
.post(this.getUrl(`/${this.getIndex()}/getPlantListTitle`), null, { headers: this.makeCallHeader() })
.then(res => {
debugVerbose('getPlatList result:', res);
if (Array.isArray(res.data)) {
Expand Down Expand Up @@ -342,7 +351,7 @@ module.exports = class growatt {
const params = new Url.URLSearchParams({ plantId });
if (this.lifeSignCallback) this.lifeSignCallback();
this.axios
.post(this.getUrl('/index/getWeatherByPlantId'), params.toString(), { headers: this.makeCallHeader() })
.post(this.getUrl(`/${this.getIndex()}/getWeatherByPlantId`), params.toString(), { headers: this.makeCallHeader() })
.then(res => {
debugVerbose('getWeatherByPlantId result:', res);
if (res.data && res.data.result && res.data.result === 1) {
Expand Down
Loading

0 comments on commit 878b61d

Please sign in to comment.