Skip to content

Commit 9b78ff0

Browse files
committed
Added feature to enable de
1 parent 53f4fec commit 9b78ff0

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- Added time slots for TLXH
66
- Added Inverter On Off for TLX und TLXH
7-
7+
- Added feature to enable debug
88

99
### 0.7.5: Maintenance Release
1010

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,41 @@ set DEBUG=growatt:verbose
3333
set DEBUG=growatt:queue
3434
```
3535

36+
In code:
37+
there are the following functions:
38+
39+
setDebugApi
40+
41+
| Parameter | Type | Default | Description |
42+
| --------- | ------- | ------- | ------------------------------------------------------------ |
43+
| enable | boolean | | "true" enables API debugging, "false" disables all debugging |
44+
45+
setDebugVerbose
46+
47+
| Parameter | Type | Default | Description |
48+
| --------- | ------- | ------- | ------------------------------------------------------------------------ |
49+
| enable | boolean | | "true" enables API and Verbose debugging, "false" disables all debugging |
50+
51+
```
52+
"use strict"
53+
const api = require('growatt')
54+
api.setDebugApi(true);
55+
```
56+
57+
or
58+
59+
```
60+
"use strict"
61+
const api = require('growatt')
62+
api.setDebugVerbose(true); //
63+
```
64+
65+
...
66+
67+
```
68+
api.setDebugApi(false); //All debug is always turned off. So it's similar to api.setDebugVerbose(false)
69+
```
70+
3671
---
3772

3873
### Promise

lib/growatt.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
const Url = require('url');
2222
const https = require('https');
23-
const debugApi = require('debug')('growatt:api');
24-
const debugVerbose = require('debug')('growatt:verbose');
23+
const debug = require('debug');
24+
const debugApi = debug('growatt:api');
25+
const debugVerbose = debug('growatt:verbose');
2526
const Axios = require('axios');
2627
const MD5 = require('md5');
2728
const QUEUE = require('./queue');
@@ -1122,5 +1123,30 @@ module.exports = class growatt {
11221123
}
11231124
};
11241125

1126+
function setDebugApi(enable) {
1127+
if (enable) {
1128+
debug.enable('growatt:api');
1129+
debugApi('Debug growatt:api is on');
1130+
} else {
1131+
debugVerbose('Debug growatt:verbose turned off');
1132+
debugApi('Debug growatt:api turned off');
1133+
debug.disable();
1134+
}
1135+
}
1136+
1137+
function setDebugVerbose(enable) {
1138+
if (enable) {
1139+
setDebugApi(enable);
1140+
debug.enable('growatt:verbose');
1141+
debugVerbose('Debug growatt:verbose is on');
1142+
} else {
1143+
debugVerbose('Debug growatt:verbose turned off');
1144+
debugApi('Debug growatt:api turned off');
1145+
debug.disable();
1146+
}
1147+
}
1148+
11251149
module.exports.LOGGERREGISTER = LOGGERREGISTER;
11261150
module.exports.LOGGERFUNCTION = LOGGERFUNCTION;
1151+
module.exports.setDebugApi = setDebugApi;
1152+
module.exports.setDebugVerbose = setDebugVerbose;

0 commit comments

Comments
 (0)