homebridge-tauron-elicznik 0.0.3-beta.13 → 0.0.3-beta.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +39 -39
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -138,6 +138,7 @@ class eLicznikDevice {
138
138
  }
139
139
 
140
140
  this.axiosInstance = axios.create({
141
+ method: 'POST',
141
142
  httpsAgent: new https.Agent({
142
143
  ciphers: 'DEFAULT@SECLEVEL=1'
143
144
  })
@@ -172,48 +173,47 @@ class eLicznikDevice {
172
173
  async updateDeviceState() {
173
174
  this.log.debug('Device: %s %s, requesting Device state.', this.meterId, this.name);
174
175
 
175
- // Add login details & meter ID here:
176
- const payload = {
177
- 'username': this.user,
178
- 'password': this.passwd,
179
- 'service': 'https://elicznik.tauron-dystrybucja.pl'
180
- }
176
+ try {
177
+ // Add login details & meter ID here:
178
+ const payload = {
179
+ 'username': this.user,
180
+ 'password': this.passwd,
181
+ 'service': 'https://elicznik.tauron-dystrybucja.pl'
182
+ }
181
183
 
182
- this.axiosInstance.post(url, payload, { headers: headers })
183
- .then((response) => {
184
- const chart_year = {
185
- "dane[chartYear]": 2020,
186
- "dane[paramType]": "year",
187
- "dane[smartNr]": this.meterId,
188
- "dane[checkOZE]": "on"
189
- };
190
- return this.axiosInstance.post(charturl, chart_year, { headers: headers });
191
- })
192
- .then((response) => {
193
- this.log('Device: %s, update Device state: %s', this.name, response.data);
194
-
195
- const energyImport = 0;
196
- const energyExport = 0;
197
- if (this.tauroneLicznikEnergyService) {
198
- this.tauroneLicznikEnergyService
199
- .updateCharacteristic(Characteristic.tauroneLicznikEnergyImport, energyImport)
200
- .updateCharacteristic(Characteristic.tauroneLicznikEnergyExport, energyExport);
201
- }
202
- this.energyImport = energyImport;
203
- this.energyExport = energyExport;
184
+ const chart_year = {
185
+ "dane[chartYear]": 2020,
186
+ "dane[paramType]": "year",
187
+ "dane[smartNr]": this.meterId,
188
+ "dane[checkOZE]": "on"
189
+ };
190
+
191
+ const response = await this.axiosInstance(url, payload, { headers: headers });
192
+ this.log('Device: %s, update Device state: %s', this.name, response.data);
193
+ const response1 = await this.axiosInstance(charturl, chart_year, { headers: headers });
194
+ this.log('Device: %s, update Device state: %s', this.name, response1.data);
195
+
196
+ const energyImport = 0;
197
+ const energyExport = 0;
198
+ if (this.tauroneLicznikEnergyService) {
199
+ this.tauroneLicznikEnergyService
200
+ .updateCharacteristic(Characteristic.tauroneLicznikEnergyImport, energyImport)
201
+ .updateCharacteristic(Characteristic.tauroneLicznikEnergyExport, energyExport);
202
+ }
203
+ this.energyImport = energyImport;
204
+ this.energyExport = energyExport;
204
205
 
205
- this.checkDeviceState = true;
206
+ this.checkDeviceState = true;
206
207
 
207
- //start prepare accessory
208
- if (this.startPrepareAccessory) {
209
- //this.prepareAccessory();
210
- }
211
- })
212
- .catch((error) => {
213
- this.log.error('Device: %s, update Device state error: %s', this.name, error);
214
- this.checkDeviceState = false;
215
- this.checkDeviceInfo = true;
216
- });
208
+ //start prepare accessory
209
+ if (this.startPrepareAccessory) {
210
+ //this.prepareAccessory();
211
+ }
212
+ } catch (error) {
213
+ this.log.error('Device: %s %s, update Device state error: %s', this.meterId, this.name, error);
214
+ this.checkDeviceState = false;
215
+ this.checkDeviceInfo = true;
216
+ };
217
217
  }
218
218
 
219
219
  //Prepare accessory
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.13",
4
+ "version": "0.0.3-beta.15",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to read data from Tauron eLicznik.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",