homebridge-verano 1.0.7 → 1.0.9

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/package.json +1 -1
  2. package/src/index.js +48 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-verano",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Plugins for Verano Heating System",
5
5
  "displayName": "Verano Heating System",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -13,7 +13,6 @@ class VeranoAccessoryPlugin {
13
13
  this.isAuthorized = false;
14
14
  this.log.debug('Verano Accessory Plugin Loaded');
15
15
 
16
- this.Service = this.api.hap.Service;
17
16
  this.Characteristic = this.api.hap.Characteristic;
18
17
 
19
18
  this.informationService = new this.api.hap.Service.AccessoryInformation()
@@ -23,23 +22,22 @@ class VeranoAccessoryPlugin {
23
22
  this.name = config.name;
24
23
 
25
24
  this.thermostatService = new this.api.hap.Service.Thermostat(this.name);
26
- // this.thermostatService = new this.Service(this.Service.Thermostat);
27
25
 
28
- this.service.getCharacteristic(this.Characteristic.CurrentHeatingCoolingState)
26
+ this.thermostatService.getCharacteristic(this.Characteristic.CurrentHeatingCoolingState)
29
27
  .onGet(this.handleCurrentHeatingCoolingStateGet.bind(this));
30
28
 
31
- this.service.getCharacteristic(this.Characteristic.TargetHeatingCoolingState)
29
+ this.thermostatService.getCharacteristic(this.Characteristic.TargetHeatingCoolingState)
32
30
  .onGet(this.handleTargetHeatingCoolingStateGet.bind(this))
33
31
  .onSet(this.handleTargetHeatingCoolingStateSet.bind(this));
34
32
 
35
- this.service.getCharacteristic(this.Characteristic.CurrentTemperature)
33
+ this.thermostatService.getCharacteristic(this.Characteristic.CurrentTemperature)
36
34
  .onGet(this.handleCurrentTemperatureGet.bind(this));
37
35
 
38
- this.service.getCharacteristic(this.Characteristic.TargetTemperature)
36
+ this.thermostatService.getCharacteristic(this.Characteristic.TargetTemperature)
39
37
  .onGet(this.handleTargetTemperatureGet.bind(this))
40
38
  .onSet(this.handleTargetTemperatureSet.bind(this));
41
39
 
42
- this.service.getCharacteristic(this.Characteristic.TemperatureDisplayUnits)
40
+ this.thermostatService.getCharacteristic(this.Characteristic.TemperatureDisplayUnits)
43
41
  .onGet(this.handleTemperatureDisplayUnitsGet.bind(this))
44
42
  .onSet(this.handleTemperatureDisplayUnitsSet.bind(this));
45
43
 
@@ -56,7 +54,19 @@ class VeranoAccessoryPlugin {
56
54
  handleCurrentHeatingCoolingStateGet() {
57
55
  this.log.debug('Triggered GET CurrentHeatingCoolingState');
58
56
  return this.getTiles()
59
- .then(this.extractMode);
57
+ .then(this.extractMode)
58
+ .then(statusId => {
59
+
60
+ if (statusId === 1) {
61
+ return this.Characteristic.CurrentHeatingCoolingState.COOL;
62
+ }
63
+
64
+ if (statusId === 0) {
65
+ return this.Characteristic.CurrentHeatingCoolingState.HEAT;
66
+ }
67
+
68
+ return this.Characteristic.CurrentHeatingCoolingState.OFF;
69
+ });
60
70
  }
61
71
 
62
72
 
@@ -66,7 +76,19 @@ class VeranoAccessoryPlugin {
66
76
  handleTargetHeatingCoolingStateGet() {
67
77
  this.log.debug('Triggered GET TargetHeatingCoolingState');
68
78
  return this.getTiles()
69
- .then(this.extractMode);
79
+ .then(this.extractMode)
80
+ .then(statusId => {
81
+
82
+ if (statusId === 1) {
83
+ return this.Characteristic.TargetHeatingCoolingState.COOL;
84
+ }
85
+
86
+ if (statusId === 0) {
87
+ return this.Characteristic.TargetHeatingCoolingState.HEAT;
88
+ }
89
+
90
+ return this.Characteristic.TargetHeatingCoolingState.OFF;
91
+ });
70
92
  }
71
93
 
72
94
  /**
@@ -99,7 +121,8 @@ class VeranoAccessoryPlugin {
99
121
  axios.post('https://emodul.pl/send_control_data', requestBody, {
100
122
  headers: {
101
123
  'Cookie': this.sessionCookie
102
- }
124
+ },
125
+ withCredentials: true
103
126
  }).then(response => response.data);
104
127
  }
105
128
 
@@ -137,7 +160,8 @@ class VeranoAccessoryPlugin {
137
160
  axios.post('https://emodul.pl/send_control_data', requestBody, {
138
161
  headers: {
139
162
  'Cookie': this.sessionCookie
140
- }
163
+ },
164
+ withCredentials: true
141
165
  }).then(response => response.data);
142
166
  }
143
167
 
@@ -158,17 +182,23 @@ class VeranoAccessoryPlugin {
158
182
 
159
183
  getTiles() {
160
184
 
185
+ this.log.debug('Getting tiles');
161
186
  if(!this.isAuthorized) {
162
- this.log.debug('Not authorized, cannot get tiles, trying to authorize');
187
+ this.log.error('Not authorized, cannot get tiles, trying to authorize');
163
188
  this.authorize();
164
189
  return;
165
190
  }
166
191
 
167
- return axios.get('https://emodul.pl/update_data', {
192
+ return axios.get('https://emodul.pl/frontend/module_data', {
168
193
  headers: {
169
194
  'Cookie': this.sessionCookie
170
- }
171
- }).then(response => response.data.tiles)
195
+ },
196
+ withCredentials: true
197
+ }).then(response => {
198
+ const tiles = response.data.tiles;
199
+ this.log.debug('Tiles', tiles);
200
+ return tiles;
201
+ })
172
202
  .catch(error => {
173
203
  this.log.error("Error during tiles fetch", error);
174
204
  this.isAuthorized = false;
@@ -186,18 +216,9 @@ class VeranoAccessoryPlugin {
186
216
  return foundTile.params.widget2.value / 10;
187
217
  }
188
218
 
189
- async extractMode(tiles) {
190
- const foundTile = tiles.filter(tile => tile.id === 61)[0]
191
- const statusId = foundTile.params.statusId;
192
- if (statusId === 1) {
193
- return this.Characteristic.TargetHeatingCoolingState.COOL;
194
- }
195
-
196
- if (statusId === 0) {
197
- return this.Characteristic.TargetHeatingCoolingState.HEAT;
198
- }
199
-
200
- return this.Characteristic.TargetHeatingCoolingState.OFF;
219
+ extractMode(tiles = []) {
220
+ const foundTile = tiles.filter(tile => tile?.id === 61)?.[0]
221
+ return foundTile?.params?.statusId || -1;
201
222
  }
202
223
 
203
224
  async authorize() {