homebridge-tauron-elicznik 0.0.2-beta32 → 0.0.2-beta36

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 (3) hide show
  1. package/index.js +11 -32
  2. package/package.json +4 -3
  3. package/src/elicznik.py +57 -0
package/index.js CHANGED
@@ -1,21 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  const path = require('path');
4
- const axios = require('axios');
5
4
  const fs = require('fs');
6
5
  const fsPromises = require('fs').promises;
7
- const https = require('https');
6
+ const pyshell = require('python-shell');
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
- "cache-control": "no-cache"
17
- }
18
-
19
11
  let Accessory, Characteristic, Service, Categories, UUID;
20
12
 
21
13
  module.exports = (api) => {
@@ -178,31 +170,18 @@ class eLicznikDevice {
178
170
  async updateDeviceState() {
179
171
  this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
180
172
  try {
181
- const CHART_DATA_URL = CHARTS_URL + '?dane[chartYear]=2020&dane[paramType]=year&dane[smartNr]=' + this.meterId + '&dane[checkOZE]=on';
182
-
183
- const options = {
184
- method: 'POST',
185
- baseURL: LOGIN_URL,
186
- data: {
187
- username: this.user,
188
- password: this.password,
189
- service: SERVICE_URL
190
- },
191
- httpsAgent: new https.Agent({
192
- rejectUnauthorized: false
193
- })
173
+ var options = {
174
+ mode: 'text',
175
+ pythonOptions: ['-u'],
176
+ scriptPath: './src/',
177
+ args: [this.user, this.passwd, this.meterId]
194
178
  };
195
- const response = await axios(options);
196
- this.log(response)
197
179
 
198
- const options1 = {
199
- method: 'POST',
200
- url: CHART_DATA_URL,
201
- headers: HEADERS
202
- }
203
-
204
- const response1 = await axios(options1);
205
- this.log(response1)
180
+ pyshell.PythonShell.run('elicznik.py', options, function (err, results) {
181
+ if (err) throw err;
182
+ // results is an array consisting of messages collected during execution
183
+ console.log('results: %j', results.toString());
184
+ });
206
185
 
207
186
  this.log.debug('Device: %s %s, debug response: %s', this.meterId, this.name, response1);
208
187
  const energyImport = 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.2-beta32",
4
+ "version": "0.0.2-beta36",
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",
@@ -31,7 +32,7 @@
31
32
  "homebridge": ">=1.3.0"
32
33
  },
33
34
  "dependencies": {
34
- "axios": "^0.21.4"
35
+ "python-shell": "^3.0.0"
35
36
  },
36
37
  "keywords": [
37
38
  "homebridge",
@@ -44,4 +45,4 @@
44
45
  "scripts": {
45
46
  "test": "echo \"Error: no test specified\" && exit 1"
46
47
  }
47
- }
48
+ }
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env python
2
+
3
+ import sys
4
+ import requests
5
+ from requests import adapters
6
+ import ssl
7
+ from urllib3 import poolmanager
8
+ import datetime
9
+
10
+ # Add login details & meter ID here:
11
+ username = sys.argv[0]
12
+ password = sys.argv[1]
13
+ meter_id = sys.argv[2]
14
+
15
+ payload = {
16
+ 'username': username,
17
+ 'password': password,
18
+ 'service': 'https://elicznik.tauron-dystrybucja.pl'
19
+ }
20
+
21
+ url = 'https://logowanie.tauron-dystrybucja.pl/login'
22
+ charturl = 'https://elicznik.tauron-dystrybucja.pl/index/charts'
23
+ headers = {'cache-control': 'no-cache'}
24
+
25
+
26
+ class TLSAdapter(adapters.HTTPAdapter):
27
+
28
+ def init_poolmanager(self, connections, maxsize, block=False):
29
+ """Create and initialize the urllib3 PoolManager."""
30
+ ctx = ssl.create_default_context()
31
+ ctx.set_ciphers('DEFAULT@SECLEVEL=1')
32
+ self.poolmanager = poolmanager.PoolManager(
33
+ num_pools=connections,
34
+ maxsize=maxsize,
35
+ block=block,
36
+ ssl_version=ssl.PROTOCOL_TLS,
37
+ ssl_context=ctx)
38
+
39
+
40
+ session = requests.session()
41
+ session.mount('https://', TLSAdapter())
42
+
43
+ p = session.request("POST", url, data=payload, headers=headers)
44
+ p = session.request("POST", url, data=payload, headers=headers)
45
+
46
+ chart_year = {
47
+ # change timedelta to get data from another days (1 for yesterday)
48
+ "dane[chartYear]": 2020,
49
+ "dane[paramType]": "year",
50
+ "dane[smartNr]": meter_id,
51
+ # comment if don't want generated energy data in JSON output:
52
+ "dane[checkOZE]": "on"
53
+ }
54
+
55
+ r = session.request("POST", charturl, data=chart_year, headers=headers)
56
+
57
+ print(r.text)