homebridge-tauron-elicznik 0.0.3-beta.6 → 0.0.3-beta.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +34 -24
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -3,18 +3,14 @@
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
5
  const fsPromises = fs.promises;
6
- const axios = require('axios');
7
- const https = require('https');
6
+ const request = require('request-promise');
8
7
 
9
8
  const PLUGIN_NAME = 'homebridge-tauron-elicznik';
10
9
  const PLATFORM_NAME = 'tauroneLicznik';
11
10
 
12
- const SERVICE_URL = 'https://elicznik.tauron-dystrybucja.pl';
13
- const LOGIN_URL = 'https://logowanie.tauron-dystrybucja.pl/login';
14
- const CHARTS_URL = 'https://elicznik.tauron-dystrybucja.pl/index/charts';
15
- const HEADERS = {
16
- 'content-type': 'application/x-www-form-urlencoded'
17
- };
11
+ const url = 'https://logowanie.tauron-dystrybucja.pl/login';
12
+ const chartUrl = 'https://elicznik.tauron-dystrybucja.pl/index/charts';
13
+ const headers = { 'cache-control': 'no-cache' };
18
14
 
19
15
  let Accessory, Characteristic, Service, Categories, UUID;
20
16
 
@@ -58,7 +54,7 @@ module.exports = (api) => {
58
54
  Characteristic.tauroneLicznikEnergyExport = tauroneLicznikEnergyExport;
59
55
 
60
56
  class tauroneLicznikEnergyService extends Service {
61
- constructor(displayName, subtype, ) {
57
+ constructor(displayName, subtype,) {
62
58
  super(displayName, '00000001-000A-1000-8000-0026BB765291', subtype);
63
59
  // Mandatory Characteristics
64
60
  this.addCharacteristic(Characteristic.tauroneLicznikEnergyImport);
@@ -141,14 +137,14 @@ class eLicznikDevice {
141
137
  }
142
138
 
143
139
  //Check device state
144
- setInterval(function () {
140
+ setInterval(() => {
145
141
  if (this.checkDeviceInfo) {
146
142
  this.getDeviceInfo();
147
143
  }
148
144
  if (this.checkDeviceState) {
149
145
  this.updateDeviceState();
150
146
  }
151
- }.bind(this), this.refreshInterval * 1000);
147
+ }, 30000);
152
148
  }
153
149
 
154
150
  getDeviceInfo() {
@@ -168,22 +164,36 @@ class eLicznikDevice {
168
164
 
169
165
  async updateDeviceState() {
170
166
  this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
167
+
171
168
  try {
172
- const url = `${CHARTS_URL}?dane[chartYear]=2022&dane[paramType]=year&dane[checkOZE]=on&dane[smartNr]=${this.meterId}`;
173
- const options = {
174
- method: 'POST',
175
- url: url
169
+ // Add login details & meter ID here:
170
+ const username = this.user;
171
+ const password = this.passwd;
172
+ const meterId = this.meterId;
173
+
174
+ const payload = {
175
+ username,
176
+ password,
177
+ service: 'https://elicznik.tauron-dystrybucja.pl'
176
178
  };
177
179
 
178
- const token = Buffer.from(`${this.user}:${this.passwd}`, 'utf8').toString('base64')
179
- const login = axios.post(LOGIN_URL, {
180
- headers: {
181
- 'Authorization': `Basic ${token}`
182
- }
183
- });
184
- this.log('hhhhhhhh', login)
185
- //const data = await axios(options);
186
- //this.log('gggggggg', data.data)
180
+ const chartYear = {
181
+ 'dane[chartYear]': 2021,
182
+ 'dane[paramType]': 'year',
183
+ 'dane[smartNr]': meterId,
184
+ 'dane[checkOZE]': 'on'
185
+ };
186
+
187
+ // Log in to the TAURON eLicznik website
188
+ await request.post({ url, form: payload, headers });
189
+ await request.post({ url, form: payload, headers });
190
+
191
+ // Retrieve data for the specified meter ID
192
+ const response = await request.post({ url: chartUrl, form: chartYear, headers });
193
+ const jsonData = JSON.parse(response);
194
+
195
+ // Print the JSON data
196
+ this.log('Device: %s, update Device state: %s', this.name, jsonData);
187
197
 
188
198
  const energyImport = 0;
189
199
  const energyExport = 0;
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.3-beta.6",
4
+ "version": "0.0.3-beta.8",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to read data from Tauron eLicznik.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -28,10 +28,10 @@
28
28
  ],
29
29
  "engines": {
30
30
  "node": ">=14.0.0",
31
- "homebridge": ">=1.3.0"
31
+ "homebridge": ">=1.4.0"
32
32
  },
33
33
  "dependencies": {
34
- "axios": ">=0.25.0"
34
+ "request-promise": ">=4.2.6"
35
35
  },
36
36
  "keywords": [
37
37
  "homebridge",