homebridge-tauron-elicznik 0.0.3-beta.0 → 0.0.3-beta.10

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.
Files changed (2) hide show
  1. package/index.js +72 -59
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -4,16 +4,14 @@ const path = require('path');
4
4
  const fs = require('fs');
5
5
  const fsPromises = fs.promises;
6
6
  const axios = require('axios');
7
+ const https = require('https');
7
8
 
8
9
  const PLUGIN_NAME = 'homebridge-tauron-elicznik';
9
10
  const PLATFORM_NAME = 'tauroneLicznik';
10
11
 
11
- const SERVICE_URL = 'https://elicznik.tauron-dystrybucja.pl';
12
- const LOGIN_URL = 'https://logowanie.tauron-dystrybucja.pl/login';
13
- const CHARTS_URL = 'https://elicznik.tauron-dystrybucja.pl/index/charts';
14
- const HEADERS = {
15
- 'content-type': 'application/x-www-form-urlencoded'
16
- };
12
+ const url = 'https://logowanie.tauron-dystrybucja.pl/login';
13
+ const chartUrl = 'https://elicznik.tauron-dystrybucja.pl/index/charts';
14
+ const headers = { 'cache-control': 'no-cache' };
17
15
 
18
16
  let Accessory, Characteristic, Service, Categories, UUID;
19
17
 
@@ -57,7 +55,7 @@ module.exports = (api) => {
57
55
  Characteristic.tauroneLicznikEnergyExport = tauroneLicznikEnergyExport;
58
56
 
59
57
  class tauroneLicznikEnergyService extends Service {
60
- constructor(displayName, subtype, ) {
58
+ constructor(displayName, subtype,) {
61
59
  super(displayName, '00000001-000A-1000-8000-0026BB765291', subtype);
62
60
  // Mandatory Characteristics
63
61
  this.addCharacteristic(Characteristic.tauroneLicznikEnergyImport);
@@ -140,71 +138,86 @@ class eLicznikDevice {
140
138
  }
141
139
 
142
140
  //Check device state
143
- setInterval(function () {
141
+ setInterval(() => {
144
142
  if (this.checkDeviceInfo) {
145
143
  this.getDeviceInfo();
146
144
  }
147
145
  if (this.checkDeviceState) {
148
146
  this.updateDeviceState();
149
147
  }
150
- }.bind(this), this.refreshInterval * 1000);
151
-
152
- //start prepare accessory
153
- if (this.startPrepareAccessory) {
154
- this.prepareAccessory();
155
- }
148
+ }, 30000);
156
149
  }
157
150
 
158
- async getDeviceInfo() {
151
+ getDeviceInfo() {
159
152
  this.log.debug('Device: %s %s, requesting Device Info.', this.meterId, this.name);
160
- try {
161
- this.log('-------- %s --------', this.name);
162
- this.log('Manufacturer: %s', this.manufacturer);
163
- this.log('Model: %s', this.modelName);
164
- this.log('Meter Id: %s', this.meterId);
165
- this.log('Serialnr: %s', this.serialNumber);
166
- this.log('Firmware: %s', this.firmwareRevision);
167
- this.log('----------------------------------');
168
-
169
- this.checkDeviceInfo = false;
170
- this.updateDeviceState();
171
- } catch (error) {
172
- this.log.error('Device: %s %s, Device Info eror: %s, state: Offline, trying to reconnect', this.meterId, this.name, error);
173
- this.checkDeviceInfo = true;
174
- }
153
+
154
+ this.log('-------- %s --------', this.name);
155
+ this.log('Manufacturer: %s', this.manufacturer);
156
+ this.log('Model: %s', this.modelName);
157
+ this.log('Meter Id: %s', this.meterId);
158
+ this.log('Serialnr: %s', this.serialNumber);
159
+ this.log('Firmware: %s', this.firmwareRevision);
160
+ this.log('----------------------------------');
161
+
162
+ this.checkDeviceInfo = false;
163
+ this.updateDeviceState();
175
164
  }
176
165
 
177
166
  async updateDeviceState() {
178
167
  this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
179
- try {
180
- const url = CHARTS_URL + '?dane[chartYear]=2021&dane[paramType]=year&dane[checkOZE]=on&dane[smartNr]=' + this.meterId;
181
- const payload = {
182
- username: this.user,
183
- password: this.passwd,
184
- service: SERVICE_URL
185
- };
186
- const options = {
187
- method: 'POST',
188
- data: payload,
189
- headers: HEADERS
190
- };
191
-
192
- const energyImport = 0;
193
- const energyExport = 0;
194
- if (this.tauroneLicznikEnergyService) {
195
- this.tauroneLicznikEnergyService
196
- .updateCharacteristic(Characteristic.tauroneLicznikEnergyImport, energyImport)
197
- .updateCharacteristic(Characteristic.tauroneLicznikEnergyExport, energyExport);
198
- }
199
- this.energyImport = energyImport;
200
- this.energyExport = energyExport;
201
-
202
- this.checkDeviceState = true;
203
- } catch (error) {
204
- this.log.error('Device: %s %s, update Device state error: %s', this.meterId, this.name, error);
205
- this.checkDeviceState = false;
206
- this.checkDeviceInfo = true;
168
+
169
+ // Add login details & meter ID here:
170
+ const payload = {
171
+ 'username': username,
172
+ 'password': password,
173
+ 'service': 'https://elicznik.tauron-dystrybucja.pl'
207
174
  }
175
+
176
+ const url = 'https://logowanie.tauron-dystrybucja.pl/login';
177
+ const charturl = 'https://elicznik.tauron-dystrybucja.pl/index/charts';
178
+ const headers = { 'cache-control': 'no-cache' };
179
+
180
+ const axiosInstance = axios.create({
181
+ httpsAgent: new https.Agent({
182
+ ciphers: 'DEFAULT@SECLEVEL=1'
183
+ })
184
+ });
185
+
186
+ axiosInstance.post(url, payload, { headers: headers })
187
+ .then((response) => {
188
+ const chart_year = {
189
+ "dane[chartYear]": 2020,
190
+ "dane[paramType]": "year",
191
+ "dane[smartNr]": meter_id,
192
+ "dane[checkOZE]": "on"
193
+ };
194
+ return axiosInstance.post(charturl, chart_year, { headers: headers });
195
+ })
196
+ .then((response) => {
197
+ this.log('Device: %s, update Device state: %s', this.name, response.data);
198
+
199
+ const energyImport = 0;
200
+ const energyExport = 0;
201
+ if (this.tauroneLicznikEnergyService) {
202
+ this.tauroneLicznikEnergyService
203
+ .updateCharacteristic(Characteristic.tauroneLicznikEnergyImport, energyImport)
204
+ .updateCharacteristic(Characteristic.tauroneLicznikEnergyExport, energyExport);
205
+ }
206
+ this.energyImport = energyImport;
207
+ this.energyExport = energyExport;
208
+
209
+ this.checkDeviceState = true;
210
+
211
+ //start prepare accessory
212
+ if (this.startPrepareAccessory) {
213
+ //this.prepareAccessory();
214
+ }
215
+ })
216
+ .catch((error) => {
217
+ this.log.error('Device: %s, update Device state error: %s', this.name, error);
218
+ this.checkDeviceState = false;
219
+ this.checkDeviceInfo = true;
220
+ });
208
221
  }
209
222
 
210
223
  //Prepare accessory
@@ -236,7 +249,7 @@ class eLicznikDevice {
236
249
  //Prepare service
237
250
  this.log.debug('prepareTauroneLicznikService');
238
251
  //power and energy
239
- this.tauroneLicznikEnergyService = new Service.tauroneLicznikEnergyService('Meter ' + this.meterId, 'tauroneLicznikEnergyService');
252
+ this.tauroneLicznikEnergyService = new Service.tauroneLicznikEnergyService(`Meter ${this.meterId}`, 'tauroneLicznikEnergyService');
240
253
  this.tauroneLicznikEnergyService.getCharacteristic(Characteristic.tauroneLicznikEnergyImport)
241
254
  .onGet(async () => {
242
255
  const value = this.energyImport;
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.0",
4
+ "version": "0.0.3-beta.10",
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
+ "axios": ">=1.2.1"
35
35
  },
36
36
  "keywords": [
37
37
  "homebridge",