homebridge-tauron-elicznik 0.0.2-beta43 → 0.0.2-beta47

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 +33 -0
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -2,12 +2,18 @@
2
2
 
3
3
  const path = require('path');
4
4
  const axios = require('axios');
5
+ const https = require('https');
6
+ const qs = require('qs');
5
7
  const fs = require('fs');
6
8
  const fsPromises = require('fs').promises;
7
9
 
8
10
  const PLUGIN_NAME = 'homebridge-tauron-elicznik';
9
11
  const PLATFORM_NAME = 'tauroneLicznik';
10
12
 
13
+ const SERVICE_URL = 'https://elicznik.tauron-dystrybucja.pl';
14
+ const LOGIN_URL = 'https://logowanie.tauron-dystrybucja.pl/login?service=https://elicznik.tauron-dystrybucja.pl';
15
+ const CHARTS_URL = 'https://elicznik.tauron-dystrybucja.pl/index/charts';
16
+
11
17
  let Accessory, Characteristic, Service, Categories, UUID;
12
18
 
13
19
  module.exports = (api) => {
@@ -125,6 +131,26 @@ class eLicznikDevice {
125
131
  this.energyImport = 0;
126
132
  this.energyExport = 0;
127
133
 
134
+ const data = qs.stringify({
135
+ username: this.user,
136
+ password: this.passwd,
137
+ service: SERVICE_URL
138
+ });
139
+
140
+ const headers = {
141
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
142
+ };
143
+
144
+ this.axiosInstance = axios.create({
145
+ method: 'POST',
146
+ baseURL: LOGIN_URL,
147
+ data: data,
148
+ headers: headers,
149
+ httpsAgent: new https.Agent({
150
+ rejectUnauthorized: false
151
+ }),
152
+ });
153
+
128
154
  const prefDir = path.join(api.user.storagePath(), 'eLicznik');
129
155
 
130
156
  //check if the directory exists, if not then create it
@@ -169,8 +195,15 @@ class eLicznikDevice {
169
195
 
170
196
  async updateDeviceState() {
171
197
  this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
198
+ const url = CHARTS_URL + '?dane[chartYear]=2021&dane[paramType]=year&dane[checkOZE]=on&dane[smartNr]=' + this.meterId;
172
199
  try {
200
+ const options = {
201
+ method: 'POST',
202
+ url: url
203
+ };
204
+ const response = await this.axiosInstance(options);
173
205
 
206
+ this.log(response)
174
207
  const energyImport = 0;
175
208
  const energyExport = 0;
176
209
  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-beta43",
4
+ "version": "0.0.2-beta47",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to read data from Tauron eLicznik.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -31,7 +31,8 @@
31
31
  "homebridge": ">=1.3.0"
32
32
  },
33
33
  "dependencies": {
34
- "axios": "^0.21.4"
34
+ "axios": "^0.21.4",
35
+ "qs": "^6.10.1"
35
36
  },
36
37
  "keywords": [
37
38
  "homebridge",