homebridge-tauron-elicznik 0.0.2-beta40 → 0.0.2-beta44
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 +18 -11
- package/package.json +4 -4
- package/elicznik.py +0 -57
package/index.js
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
const path = require('path');
|
4
|
+
const axios = require('axios');
|
5
|
+
const qs = require('qs');
|
4
6
|
const fs = require('fs');
|
5
7
|
const fsPromises = require('fs').promises;
|
6
|
-
const pyshell = require('python-shell');
|
7
8
|
|
8
9
|
const PLUGIN_NAME = 'homebridge-tauron-elicznik';
|
9
10
|
const PLATFORM_NAME = 'tauroneLicznik';
|
10
11
|
|
12
|
+
const SERVICE_URL = 'https://elicznik.tauron-dystrybucja.pl';
|
13
|
+
const LOGIN_URL = 'https://logowanie.tauron-dystrybucja.pl/login?service=https://elicznik.tauron-dystrybucja.pl';
|
14
|
+
const CHARTS_URL = 'https://elicznik.tauron-dystrybucja.pl/index/charts';
|
15
|
+
|
11
16
|
let Accessory, Characteristic, Service, Categories, UUID;
|
12
17
|
|
13
18
|
module.exports = (api) => {
|
@@ -170,18 +175,20 @@ class eLicznikDevice {
|
|
170
175
|
async updateDeviceState() {
|
171
176
|
this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
|
172
177
|
try {
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
};
|
178
|
-
|
179
|
-
pyshell.PythonShell.run('elicznik.py', options, function (err, results) {
|
180
|
-
if (err) throw err;
|
181
|
-
// results is an array consisting of messages collected during execution
|
182
|
-
this.log('results: %j', results.toString());
|
178
|
+
const data = qs.stringify({
|
179
|
+
pointId: this.meterId,
|
180
|
+
username: this.user,
|
181
|
+
password: this.passwd
|
183
182
|
});
|
183
|
+
const headers = {
|
184
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
185
|
+
};
|
186
|
+
const response = await axios.post(LOGIN_URL,
|
187
|
+
data,
|
188
|
+
headers
|
189
|
+
);
|
184
190
|
|
191
|
+
this.log(response)
|
185
192
|
const energyImport = 0;
|
186
193
|
const energyExport = 0;
|
187
194
|
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-
|
4
|
+
"version": "0.0.2-beta44",
|
5
5
|
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to read data from Tauron eLicznik.",
|
6
6
|
"license": "MIT",
|
7
7
|
"author": "grzegorz914",
|
@@ -24,15 +24,15 @@
|
|
24
24
|
"package.json",
|
25
25
|
"CHANGELOG.md",
|
26
26
|
"README.md",
|
27
|
-
"LICENSE"
|
28
|
-
"elicznik.py"
|
27
|
+
"LICENSE"
|
29
28
|
],
|
30
29
|
"engines": {
|
31
30
|
"node": ">=12.0.0",
|
32
31
|
"homebridge": ">=1.3.0"
|
33
32
|
},
|
34
33
|
"dependencies": {
|
35
|
-
"
|
34
|
+
"axios": "^0.21.4",
|
35
|
+
"qs": "^6.10.1"
|
36
36
|
},
|
37
37
|
"keywords": [
|
38
38
|
"homebridge",
|
package/elicznik.py
DELETED
@@ -1,57 +0,0 @@
|
|
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)
|