homebridge-melcloud-control 4.1.2-beta.9 → 4.1.2

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.
@@ -23,7 +23,6 @@ class MelCloudErv extends EventEmitter {
23
23
 
24
24
  //set default values
25
25
  this.devicesData = {};
26
- this.headers = {};
27
26
 
28
27
  //lock flags
29
28
  this.locks = {
@@ -55,13 +54,11 @@ class MelCloudErv extends EventEmitter {
55
54
  try {
56
55
  //read device info from file
57
56
  const devicesData = await this.functions.readData(this.devicesFile, true);
58
-
59
57
  if (!Array.isArray(devicesData)) {
60
58
  if (this.logWarn) this.emit('warn', `Device data not found`);
61
59
  return null;
62
60
  }
63
61
  const deviceData = devicesData.find(device => device.DeviceID === this.deviceId);
64
- this.headers = deviceData.Headers;
65
62
 
66
63
  if (this.accountType === 'melcloudhome') {
67
64
  deviceData.SerialNumber = deviceData.DeviceID || '4.0.0';
@@ -72,7 +69,11 @@ class MelCloudErv extends EventEmitter {
72
69
  deviceData.Device.DefaultHeatingSetTemperature = temps?.defaultHeatingSetTemperature ?? 20;
73
70
  deviceData.Device.DefaultCoolingSetTemperature = temps?.defaultCoolingSetTemperature ?? 24;
74
71
  }
75
- if (this.logDebug) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
72
+ const safeConfig = {
73
+ ...deviceData,
74
+ headers: 'removed',
75
+ };
76
+ if (this.logDebug) this.emit('debug', `Device Data: ${JSON.stringify(safeConfig, null, 2)}`);
76
77
 
77
78
  //presets
78
79
  const serialNumber = deviceData.SerialNumber;
@@ -141,7 +142,7 @@ class MelCloudErv extends EventEmitter {
141
142
  method: 'POST',
142
143
  baseURL: ApiUrls.BaseURL,
143
144
  timeout: 10000,
144
- headers: this.headers,
145
+ headers: deviceData.Headers,
145
146
  withCredentials: true
146
147
  });
147
148
 
@@ -194,7 +195,7 @@ class MelCloudErv extends EventEmitter {
194
195
  method: 'PUT',
195
196
  baseURL: ApiUrlsHome.BaseURL,
196
197
  timeout: 10000,
197
- headers: this.headers,
198
+ headers: deviceData.Headers,
198
199
  withCredentials: true
199
200
  });
200
201
 
@@ -210,7 +211,7 @@ class MelCloudErv extends EventEmitter {
210
211
  }
211
212
  }
212
213
 
213
- const settings = {
214
+ const settings = effectiveFlags === 'scheduleset' ? { data: { enabled: deviceData.ScheduleEnabled } } : {
214
215
  data: {
215
216
  Power: deviceData.Device.Power,
216
217
  SetTemperature: deviceData.Device.SetTemperature,
@@ -221,7 +222,7 @@ class MelCloudErv extends EventEmitter {
221
222
  };
222
223
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(settings.data, null, 2)}`);
223
224
 
224
- const path = ApiUrlsHome.SetErv.replace('deviceid', deviceData.DeviceID);
225
+ const path = effectiveFlags === 'scheduleset' ? ApiUrlsHome.SetSchedule.replace('deviceid', deviceData.DeviceID) : ApiUrlsHome.SetErv.replace('deviceid', deviceData.DeviceID);
225
226
  await axiosInstancePut(path, settings);
226
227
  this.updateData(deviceData);
227
228
  return true;
@@ -229,6 +230,11 @@ class MelCloudErv extends EventEmitter {
229
230
  return;
230
231
  }
231
232
  } catch (error) {
233
+ // Return 500 for schedule hovewer working correct
234
+ if (error?.response?.status === 500) {
235
+ return true;
236
+ }
237
+
232
238
  throw new Error(`Send data error: ${error.message}`);
233
239
  }
234
240
  }