homebridge-tauron-elicznik 0.0.2-beta7 → 0.0.2-beta73
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 +30 -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,25 @@ 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
|
+
service: SERVICE_URL
|
141
|
+
};
|
142
|
+
|
143
|
+
|
144
|
+
//auth
|
145
|
+
this.tauronAuth = new axiosTauronAuth({
|
146
|
+
data: data
|
147
|
+
});
|
148
|
+
|
133
149
|
const prefDir = path.join(api.user.storagePath(), 'eLicznik');
|
134
150
|
|
135
151
|
//check if the directory exists, if not then create it
|
136
|
-
if (fs.existsSync(prefDir)
|
152
|
+
if (!fs.existsSync(prefDir)) {
|
137
153
|
fsPromises.mkdir(prefDir);
|
138
154
|
}
|
139
155
|
|
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
156
|
//Check device state
|
150
157
|
setInterval(function () {
|
151
158
|
if (this.checkDeviceInfo) {
|
@@ -184,34 +191,28 @@ class eLicznikDevice {
|
|
184
191
|
async updateDeviceState() {
|
185
192
|
this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
|
186
193
|
try {
|
187
|
-
const
|
188
|
-
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'
|
189
|
-
};
|
194
|
+
const url = CHARTS_URL + '?dane[chartYear]=2021&dane[paramType]=year&dane[checkOZE]=on&dane[smartNr]=' + this.meterId;
|
190
195
|
|
191
|
-
const
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
'service': CHART_DATA_URL
|
197
|
-
});
|
196
|
+
const options = {
|
197
|
+
method: 'POST',
|
198
|
+
url: url
|
199
|
+
};
|
200
|
+
const response = await this.tauronAuth.request(options);
|
198
201
|
|
199
|
-
|
200
|
-
|
201
|
-
const energyImport = response.data;
|
202
|
-
this.log(response.data)
|
202
|
+
this.log('11112222', response.data);
|
203
|
+
const energyImport = 0;
|
203
204
|
const energyExport = 0;
|
204
205
|
if (this.tauroneLicznikEnergyService) {
|
205
206
|
this.tauroneLicznikEnergyService
|
206
207
|
.updateCharacteristic(Characteristic.tauroneLicznikEnergyImport, energyImport)
|
207
|
-
.updateCharacteristic(Characteristic.
|
208
|
+
.updateCharacteristic(Characteristic.tauroneLicznikEnergyExport, energyExport);
|
208
209
|
}
|
209
210
|
this.energyImport = energyImport;
|
210
211
|
this.energyExport = energyExport;
|
211
212
|
|
212
213
|
this.checkDeviceState = true;
|
213
214
|
} catch (error) {
|
214
|
-
this.log.error('Device: %s %s, update Device state error: %s
|
215
|
+
this.log.error('Device: %s %s, update Device state error: %s', this.meterId, this.name, error);
|
215
216
|
this.checkDeviceState = false;
|
216
217
|
this.checkDeviceInfo = true;
|
217
218
|
}
|
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-beta73",
|
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(returnUrl) {
|
16
|
+
try {
|
17
|
+
const data = {
|
18
|
+
username: this.username,
|
19
|
+
password: this.password,
|
20
|
+
service: SERVICE_URL
|
21
|
+
};
|
22
|
+
|
23
|
+
const options = {
|
24
|
+
data: data
|
25
|
+
};
|
26
|
+
const response = await axios.post(LOGIN_URL, options);
|
27
|
+
console.log('aaaaaaaaa', response.data);
|
28
|
+
|
29
|
+
return response.data;
|
30
|
+
} catch (err) {
|
31
|
+
return err
|
32
|
+
}
|
33
|
+
};
|
34
|
+
}
|
35
|
+
module.exports = axiosTauronAuth;
|