homebridge-tauron-elicznik 0.0.2-beta8 → 0.0.2-beta80

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 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 = require('fs').promises;
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,29 +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
+ service: SERVICE_URL
141
+ };
142
+
143
+ //auth
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) == false) {
151
+ if (!fs.existsSync(prefDir)) {
137
152
  fsPromises.mkdir(prefDir);
138
153
  }
139
154
 
140
- const data = qs.stringify({
141
- 'username': this.user,
142
- 'password': this.password,
143
- 'service': CHARTS_URL
144
- });
145
-
146
- this.axiosInstance = axios.create({
147
- method: 'POST',
148
- baseURL: LOGIN_URL,
149
- headers: {
150
- 'content-type': 'application/x-www-form-urlencoded'
151
- },
152
- data: data,
153
- timeout: 5000,
154
- });
155
-
156
155
  //Check device state
157
156
  setInterval(function () {
158
157
  if (this.checkDeviceInfo) {
@@ -191,34 +190,34 @@ class eLicznikDevice {
191
190
  async updateDeviceState() {
192
191
  this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
193
192
  try {
194
- const headers = {
195
- 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'
196
- };
193
+ const url = CHARTS_URL + '?dane[chartYear]=2021&dane[paramType]=year&dane[checkOZE]=on&dane[smartNr]=' + this.meterId;
197
194
 
198
- const CHART_DATA_URL = 'https://elicznik.tauron-dystrybucja.pl/index/charts?dane[chartYear]=2020&dane[paramType]=year&dane[smartNr]=' + this.meterId + '&dane[checkOZE]=on';
195
+ const data = {
196
+ username: this.username,
197
+ password: this.password,
198
+ service: SERVICE_URL
199
+ };
200
+ const options = {
201
+ data: data
202
+ };
203
+ const response = await axios.post(LOGIN_URL, options);
199
204
 
200
- const options = qs.stringify({
201
- 'username': this.user,
202
- 'password': this.password,
203
- 'service': CHART_DATA_URL
204
- });
205
+ //const response = await this.tauronAuth.request(url);
205
206
 
206
- const response = await this.axiosInstance(options);
207
- this.log.debug('Device: %s %s, debug response: %s', this.meterId, this.name, response.data);
208
- const energyImport = response.data;
209
- this.log(response.data)
207
+ this.log('33333344', response, response.data);
208
+ const energyImport = 0;
210
209
  const energyExport = 0;
211
210
  if (this.tauroneLicznikEnergyService) {
212
211
  this.tauroneLicznikEnergyService
213
212
  .updateCharacteristic(Characteristic.tauroneLicznikEnergyImport, energyImport)
214
- .updateCharacteristic(Characteristic.tauroneLicznikEnergyImport, energyExport);
213
+ .updateCharacteristic(Characteristic.tauroneLicznikEnergyExport, energyExport);
215
214
  }
216
215
  this.energyImport = energyImport;
217
216
  this.energyExport = energyExport;
218
217
 
219
218
  this.checkDeviceState = true;
220
219
  } catch (error) {
221
- this.log.error('Device: %s %s, update Device state error: %s, state: Offline', this.meterId, this.name, error);
220
+ this.log.error('Device: %s %s, update Device state error: %s', this.meterId, this.name, error);
222
221
  this.checkDeviceState = false;
223
222
  this.checkDeviceInfo = true;
224
223
  }
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-beta8",
4
+ "version": "0.0.2-beta80",
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,36 @@
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
+ this.service = data.service;
14
+ }
15
+
16
+ async request(returnUrl) {
17
+ try {
18
+ const data = {
19
+ username: this.username,
20
+ password: this.password,
21
+ service: this.service
22
+ };
23
+
24
+ const options = {
25
+ data: data
26
+ };
27
+ const response = await axios.post(LOGIN_URL, options);
28
+ returnUrl = response.data;
29
+
30
+ return returnUrl;
31
+ } catch (err) {
32
+ return err
33
+ }
34
+ };
35
+ }
36
+ module.exports = axiosTauronAuth;