homebridge-tauron-elicznik 0.0.2-beta42 → 0.0.2-beta46

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 +29 -12
  2. package/package.json +3 -3
  3. package/src/elicznik.py +0 -57
package/index.js CHANGED
@@ -1,13 +1,19 @@
1
1
  'use strict';
2
2
 
3
3
  const path = require('path');
4
+ const axios = require('axios');
5
+ const https = require('https');
6
+ const qs = require('qs');
4
7
  const fs = require('fs');
5
8
  const fsPromises = require('fs').promises;
6
- const pyshell = require('python-shell');
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,25 @@ 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
+ data: data,
147
+ headers: headers,
148
+ httpsAgent: new https.Agent({
149
+ rejectUnauthorized: false
150
+ }),
151
+ });
152
+
128
153
  const prefDir = path.join(api.user.storagePath(), 'eLicznik');
129
154
 
130
155
  //check if the directory exists, if not then create it
@@ -170,18 +195,10 @@ class eLicznikDevice {
170
195
  async updateDeviceState() {
171
196
  this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
172
197
  try {
173
- var options = {
174
- mode: 'text',
175
- pythonOptions: ['-u'],
176
- args: [this.user, this.passwd, this.meterId]
177
- };
178
-
179
- pyshell.PythonShell.run(__dirname + '/src/elicznik.py', options, function (err, results) {
180
- if (err) throw err;
181
- // results is an array consisting of messages collected during execution
182
- console.log('results: %j', results.toString());
183
- });
198
+
199
+ const response = await this.axiosInstance(CHARTS_URL);
184
200
 
201
+ this.log(response)
185
202
  const energyImport = 0;
186
203
  const energyExport = 0;
187
204
  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-beta42",
4
+ "version": "0.0.2-beta46",
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,7 +19,6 @@
19
19
  },
20
20
  "main": "index.js",
21
21
  "files": [
22
- "src",
23
22
  "index.js",
24
23
  "config.schema.json",
25
24
  "package.json",
@@ -32,7 +31,8 @@
32
31
  "homebridge": ">=1.3.0"
33
32
  },
34
33
  "dependencies": {
35
- "python-shell": "^3.0.0"
34
+ "axios": "^0.21.4",
35
+ "qs": "^6.10.1"
36
36
  },
37
37
  "keywords": [
38
38
  "homebridge",
package/src/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)