homebridge-tauron-elicznik 0.0.2-beta6 → 0.0.2-beta63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +38 -29
- package/package.json +2 -1
- package/src/tauronAuth.js +35 -0
package/index.js
CHANGED
@@ -2,16 +2,20 @@
|
|
2
2
|
|
3
3
|
const path = require('path');
|
4
4
|
const axios = require('axios');
|
5
|
+
const axiosTauronAuth = require('./src/tauronAuth.js');
|
6
|
+
const https = require('https');
|
5
7
|
const fs = require('fs');
|
6
|
-
const fsPromises =
|
7
|
-
const qs = require('qs')
|
8
|
+
const fsPromises = fs.promises;
|
8
9
|
|
9
10
|
const PLUGIN_NAME = 'homebridge-tauron-elicznik';
|
10
11
|
const PLATFORM_NAME = 'tauroneLicznik';
|
11
12
|
|
12
13
|
const SERVICE_URL = 'https://elicznik.tauron-dystrybucja.pl';
|
13
|
-
const LOGIN_URL = 'https://logowanie.tauron-dystrybucja.pl/login';
|
14
|
+
const LOGIN_URL = 'https://logowanie.tauron-dystrybucja.pl/login?service=https://elicznik.tauron-dystrybucja.pl';
|
14
15
|
const CHARTS_URL = 'https://elicznik.tauron-dystrybucja.pl/index/charts';
|
16
|
+
const HEADERS = {
|
17
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'
|
18
|
+
};
|
15
19
|
|
16
20
|
let Accessory, Characteristic, Service, Categories, UUID;
|
17
21
|
|
@@ -130,22 +134,24 @@ class eLicznikDevice {
|
|
130
134
|
this.energyImport = 0;
|
131
135
|
this.energyExport = 0;
|
132
136
|
|
137
|
+
const data = {
|
138
|
+
username: this.user,
|
139
|
+
password: this.passwd
|
140
|
+
};
|
141
|
+
|
142
|
+
|
143
|
+
//digest auth installer
|
144
|
+
this.tauronAuth = new axiosTauronAuth({
|
145
|
+
data: data
|
146
|
+
});
|
147
|
+
|
133
148
|
const prefDir = path.join(api.user.storagePath(), 'eLicznik');
|
134
149
|
|
135
150
|
//check if the directory exists, if not then create it
|
136
|
-
if (fs.existsSync(prefDir)
|
151
|
+
if (!fs.existsSync(prefDir)) {
|
137
152
|
fsPromises.mkdir(prefDir);
|
138
153
|
}
|
139
154
|
|
140
|
-
this.axiosInstance = axios.create({
|
141
|
-
method: 'POST',
|
142
|
-
baseURL: LOGIN_URL,
|
143
|
-
headers: {
|
144
|
-
'content-type': 'application/x-www-form-urlencoded'
|
145
|
-
},
|
146
|
-
timeout: 5000,
|
147
|
-
});
|
148
|
-
|
149
155
|
//Check device state
|
150
156
|
setInterval(function () {
|
151
157
|
if (this.checkDeviceInfo) {
|
@@ -183,35 +189,38 @@ class eLicznikDevice {
|
|
183
189
|
|
184
190
|
async updateDeviceState() {
|
185
191
|
this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
|
192
|
+
const url = CHARTS_URL + '?dane[chartYear]=2021&dane[paramType]=year&dane[checkOZE]=on&dane[smartNr]=' + this.meterId;
|
186
193
|
try {
|
187
|
-
const
|
188
|
-
|
194
|
+
const options = {
|
195
|
+
method: 'POST',
|
196
|
+
url: CHARTS_URL,
|
197
|
+
headers: HEADERS,
|
198
|
+
data: {
|
199
|
+
"dane[chartYear]": '2021',
|
200
|
+
"dane[paramType]": 'year',
|
201
|
+
"dane[smartNr]": this.meterId,
|
202
|
+
"dane[checkOZE]": 'on'
|
203
|
+
},
|
204
|
+
httpsAgent: new https.Agent({
|
205
|
+
rejectUnauthorized: false
|
206
|
+
}),
|
189
207
|
};
|
208
|
+
const response = await this.tauronAuth.request(options);
|
190
209
|
|
191
|
-
|
192
|
-
|
193
|
-
'password': this.password,
|
194
|
-
'service': SERVICE_URL
|
195
|
-
});
|
196
|
-
|
197
|
-
const CHART_DATA_URL = 'https://elicznik.tauron-dystrybucja.pl/index/charts?dane[chartYear]=2020&dane[paramType]=year&dane[smartNr]=' + this.meterId + '&dane[checkOZE]=on';
|
198
|
-
|
199
|
-
const response = await this.axiosInstance(CHART_DATA_URL, options);
|
200
|
-
this.log.debug('Device: %s %s, debug response: %s', this.meterId, this.name, response.data);
|
201
|
-
const energyImport = response.data;
|
202
|
-
this.log(response.data)
|
210
|
+
this.log(response);
|
211
|
+
const energyImport = 0;
|
203
212
|
const energyExport = 0;
|
204
213
|
if (this.tauroneLicznikEnergyService) {
|
205
214
|
this.tauroneLicznikEnergyService
|
206
215
|
.updateCharacteristic(Characteristic.tauroneLicznikEnergyImport, energyImport)
|
207
|
-
.updateCharacteristic(Characteristic.
|
216
|
+
.updateCharacteristic(Characteristic.tauroneLicznikEnergyExport, energyExport);
|
208
217
|
}
|
209
218
|
this.energyImport = energyImport;
|
210
219
|
this.energyExport = energyExport;
|
211
220
|
|
212
221
|
this.checkDeviceState = true;
|
213
222
|
} catch (error) {
|
214
|
-
this.log.error('Device: %s %s, update Device state error: %s
|
223
|
+
this.log.error('Device: %s %s, update Device state error: %s', this.meterId, this.name, error);
|
215
224
|
this.checkDeviceState = false;
|
216
225
|
this.checkDeviceInfo = true;
|
217
226
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"displayName": "Tauron eLicznik",
|
3
3
|
"name": "homebridge-tauron-elicznik",
|
4
|
-
"version": "0.0.2-
|
4
|
+
"version": "0.0.2-beta63",
|
5
5
|
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to read data from Tauron eLicznik.",
|
6
6
|
"license": "MIT",
|
7
7
|
"author": "grzegorz914",
|
@@ -19,6 +19,7 @@
|
|
19
19
|
},
|
20
20
|
"main": "index.js",
|
21
21
|
"files": [
|
22
|
+
"src",
|
22
23
|
"index.js",
|
23
24
|
"config.schema.json",
|
24
25
|
"package.json",
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
const axios = require('axios');
|
3
|
+
|
4
|
+
const LOGIN_URL = 'https://logowanie.tauron-dystrybucja.pl/login?service=https://elicznik.tauron-dystrybucja.pl';
|
5
|
+
const SERVICE_URL = 'https://elicznik.tauron-dystrybucja.pl';
|
6
|
+
|
7
|
+
class axiosTauronAuth {
|
8
|
+
constructor({
|
9
|
+
data
|
10
|
+
}) {
|
11
|
+
this.username = data.username;
|
12
|
+
this.password = data.password;
|
13
|
+
}
|
14
|
+
|
15
|
+
async request() {
|
16
|
+
try {
|
17
|
+
const data = {
|
18
|
+
username: this.username,
|
19
|
+
password: this.password,
|
20
|
+
service: SERVICE_URL
|
21
|
+
};
|
22
|
+
|
23
|
+
const options = {
|
24
|
+
baseURL: LOGIN_URL,
|
25
|
+
data: data
|
26
|
+
};
|
27
|
+
const response = await axios.post(options);
|
28
|
+
console.log(response);
|
29
|
+
return response;
|
30
|
+
} catch (err) {
|
31
|
+
return err
|
32
|
+
}
|
33
|
+
};
|
34
|
+
}
|
35
|
+
module.exports = axiosTauronAuth;
|