homebridge-tauron-elicznik 0.0.2-beta18 → 0.0.2-beta21

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,9 +2,9 @@
2
2
 
3
3
  const path = require('path');
4
4
  const axios = require('axios');
5
+ const tauroneLicznikAuth = require('./src/tauroneLicznikAuth.js');
5
6
  const fs = require('fs');
6
7
  const fsPromises = require('fs').promises;
7
- const https = require('https');
8
8
 
9
9
  const PLUGIN_NAME = 'homebridge-tauron-elicznik';
10
10
  const PLATFORM_NAME = 'tauroneLicznik';
@@ -180,25 +180,25 @@ class eLicznikDevice {
180
180
  try {
181
181
  const CHART_DATA_URL = CHARTS_URL + '?dane[chartYear]=2020&dane[paramType]=year&dane[smartNr]=' + this.meterId + '&dane[checkOZE]=on';
182
182
 
183
- const data = {
184
- 'username': this.user,
185
- 'password': this.password,
186
- "service": SERVICE_URL
187
- };
188
-
189
- const response1 = await axios.request({
190
- method: 'POST',
191
- url: LOGIN_URL,
192
- data: data,
193
- headers: HEADERS,
194
- httpsAgent: new https.Agent({
195
- rejectUnauthorized: false
196
- }),
183
+ const elicznikAuth = new tauroneLicznikAuth({
184
+ username: this.user,
185
+ password: this.password,
186
+ service: SERVICE_URL
197
187
  });
188
+
189
+ const options = {
190
+ headers: {
191
+ Accept: HEADERS
192
+ },
193
+ method: 'POST',
194
+ url: CHART_DATA_URL
195
+ }
196
+
197
+ const response1 = await elicznikAuth.request(options);
198
198
  this.log(response1.data)
199
199
 
200
200
  this.log.debug('Device: %s %s, debug response: %s', this.meterId, this.name, response.data);
201
- const energyImport = response.data;
201
+ const energyImport = 0;
202
202
  this.log(response.data)
203
203
  const energyExport = 0;
204
204
  if (this.tauroneLicznikEnergyService) {
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-beta18",
4
+ "version": "0.0.2-beta21",
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,23 @@
1
+ "use strict";
2
+ const https = require('https');
3
+ const axios = require('axios');
4
+ let count = 0;
5
+
6
+ class tauroneLicznikAuth {
7
+ constructor({
8
+ username,
9
+ password,
10
+ service
11
+ }) {
12
+ this.user = username;
13
+ this.passwd = password;
14
+ this.service = service;
15
+ }
16
+
17
+ async request(options) {
18
+ try {
19
+ return await axios.request(options);
20
+ } catch (err) {}
21
+ };
22
+ }
23
+ module.exports = tauroneLicznikAuth;