homebridge-melcloud-control 4.2.3-beta.34 → 4.2.3-beta.36

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.2.3-beta.34",
4
+ "version": "4.2.3-beta.36",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/constants.js CHANGED
@@ -36,7 +36,7 @@ export const ApiUrlsHome = {
36
36
  PostHolidayMode: "https://melcloudhome.com/ata/deviceid/holidaymode",
37
37
  PostProtectionFrost: "https://melcloudhome.com/ata/deviceid/frostprotection",
38
38
  PostProtectionOverheat: "https://melcloudhome.com/ata/deviceid/overheatprotection",
39
- PutDashboard: "https://melcloudhome.com/dashboard",
39
+ PutDeviceSettings: "https://melcloudhome.com/dashboard",
40
40
  PutScheduleEnabled: "https://melcloudhome.com/ata/deviceid/schedule",
41
41
  },
42
42
  Origin: "https://melcloudhome.com"
@@ -131,8 +131,6 @@ class MelCloudAta extends EventEmitter {
131
131
  let method = null
132
132
  let payload = {};
133
133
  let path = '';
134
- let origin = '';
135
- let referer = '';
136
134
  switch (accountType) {
137
135
  case "melcloud":
138
136
 
@@ -213,7 +211,7 @@ class MelCloudAta extends EventEmitter {
213
211
  endDate: deviceData.HolidayMode.EndDate,
214
212
  units: { "ATA": [deviceData.DeviceID] }
215
213
  };
216
- method = 'PUT';
214
+ method = 'POST';
217
215
  path = ApiUrlsHome.PostHolidayMode;
218
216
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
219
217
  break;
@@ -221,7 +219,6 @@ class MelCloudAta extends EventEmitter {
221
219
  payload = { enabled: deviceData.ScheduleEnabled };
222
220
  method = 'PUT';
223
221
  path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
224
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
225
222
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
226
223
  break;
227
224
  default:
@@ -235,7 +232,7 @@ class MelCloudAta extends EventEmitter {
235
232
  };
236
233
  method = 'PUT';
237
234
  path = ApiUrlsHome.PutAta.replace('deviceid', deviceData.DeviceID);
238
- deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDashboard
235
+ deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
239
236
  break
240
237
  }
241
238
 
@@ -266,7 +263,7 @@ class MelCloudAta extends EventEmitter {
266
263
 
267
264
  setTimeout(() => {
268
265
  this.lock = false
269
- }, 3000);
266
+ }, 2500);
270
267
  }
271
268
  };
272
269
  export default MelCloudAta;
@@ -138,8 +138,6 @@ class MelCloudAtw extends EventEmitter {
138
138
  let method = null
139
139
  let payload = {};
140
140
  let path = '';
141
- let origin = '';
142
- let referer = '';
143
141
  switch (accountType) {
144
142
  case "melcloud":
145
143
  deviceData.Device.EffectiveFlags = effectiveFlags;
@@ -187,14 +185,12 @@ class MelCloudAtw extends EventEmitter {
187
185
  };
188
186
  method = 'POST';
189
187
  path = ApiUrlsHome.PostHolidayMode;
190
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
191
188
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
192
189
  break;
193
190
  case 'schedule':
194
191
  payload = { enabled: deviceData.ScheduleEnabled };
195
192
  method = 'PUT';
196
193
  path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
197
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
198
194
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
199
195
  break;
200
196
  default:
@@ -215,10 +211,12 @@ class MelCloudAtw extends EventEmitter {
215
211
  };
216
212
  method = 'PUT';
217
213
  path = ApiUrlsHome.PutAtw.replace('deviceid', deviceData.DeviceID);
218
- deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDashboard
214
+ deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
219
215
  break
220
216
  }
221
217
 
218
+ deviceData.Headers['Content-Type'] = 'application/json; charset=utf-8';
219
+ deviceData.Headers.Origin = ApiUrlsHome.Origin;
222
220
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(deviceData.Headers, null, 2)}`);
223
221
  await axios(path, {
224
222
  method: method,
@@ -244,7 +242,7 @@ class MelCloudAtw extends EventEmitter {
244
242
 
245
243
  setTimeout(() => {
246
244
  this.lock = false
247
- }, 3000);
245
+ }, 2500);
248
246
  }
249
247
  };
250
248
  export default MelCloudAtw;
@@ -125,8 +125,6 @@ class MelCloudErv extends EventEmitter {
125
125
  let method = null
126
126
  let payload = {};
127
127
  let path = '';
128
- let origin = '';
129
- let referer = '';
130
128
  switch (accountType) {
131
129
  case "melcloud":
132
130
  //set target temp based on display mode and ventilation mode
@@ -197,18 +195,16 @@ class MelCloudErv extends EventEmitter {
197
195
  enabled: deviceData.HolidayMode.Enabled,
198
196
  startDate: deviceData.HolidayMode.StartDate,
199
197
  endDate: deviceData.HolidayMode.EndDate,
200
- units: { "ATW": [deviceData.DeviceID] }
198
+ units: { "ERV": [deviceData.DeviceID] }
201
199
  };
202
200
  method = 'POST';
203
201
  path = ApiUrlsHome.PostHolidayMode;
204
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
205
202
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
206
203
  break;
207
204
  case 'schedule':
208
205
  payload = { enabled: deviceData.ScheduleEnabled };
209
206
  method = 'PUT';
210
207
  path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
211
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
212
208
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
213
209
  break;
214
210
  default:
@@ -221,10 +217,12 @@ class MelCloudErv extends EventEmitter {
221
217
  };
222
218
  method = 'PUT';
223
219
  path = ApiUrlsHome.PutErv.replace('deviceid', deviceData.DeviceID);
224
- deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDashboard
220
+ deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
225
221
  break
226
222
  }
227
223
 
224
+ deviceData.Headers['Content-Type'] = 'application/json; charset=utf-8';
225
+ deviceData.Headers.Origin = ApiUrlsHome.Origin;
228
226
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(deviceData.Headers, null, 2)}`);
229
227
  await axios(path, {
230
228
  method: method,
@@ -250,7 +248,7 @@ class MelCloudErv extends EventEmitter {
250
248
 
251
249
  setTimeout(() => {
252
250
  this.lock = false
253
- }, 3000);
251
+ }, 2500);
254
252
  }
255
253
  };
256
254
  export default MelCloudErv;
@@ -64,7 +64,7 @@ class MelCloud extends EventEmitter {
64
64
  // MELCloud Home
65
65
  async checkDevicesList() {
66
66
  try {
67
- const devicesList = { State: false, Info: null, Devices: [] }
67
+ const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
68
68
  if (this.logDebug) this.emit('debug', `Scanning for devices`);
69
69
  const listDevicesData = await axios(ApiUrlsHome.GetUserContext, {
70
70
  method: 'GET',
@@ -72,15 +72,21 @@ class MelCloud extends EventEmitter {
72
72
  timeout: 25000,
73
73
  headers: this.headers
74
74
  });
75
- const buildingsList = listDevicesData.data.buildings;
75
+
76
+ const userContext = listDevicesData.data;
77
+ const buildings = userContext.buildings ?? [];
78
+ const guestBuildings = userContext.guestBuildings ?? [];
79
+ const buildingsList = [...buildings, ...guestBuildings];
80
+ const scenesList = userContext.scenes;
76
81
  if (this.logDebug) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
82
+ if (this.logDebug) this.emit('debug', `Scenes: ${JSON.stringify(scenesList, null, 2)}`);
77
83
 
78
84
  if (!buildingsList) {
79
85
  devicesList.Info = 'No building found'
80
86
  return devicesList;
81
87
  }
82
88
 
83
- await this.functions.saveData(this.buildingsFile, buildingsList);
89
+ await this.functions.saveData(this.buildingsFile, userContext);
84
90
  if (this.logDebug) this.emit('debug', `Buildings list saved`);
85
91
 
86
92
  const devices = buildingsList.flatMap(building => {
@@ -137,7 +143,7 @@ class MelCloud extends EventEmitter {
137
143
  if (device.FrostProtection) device.FrostProtection = { ...capitalizeKeys(device.FrostProtection || {}) };
138
144
  if (device.OverheatProtection) device.OverheatProtection = { ...capitalizeKeys(device.OverheatProtection || {}) };
139
145
  if (device.HolidayMode) device.HolidayMode = { ...capitalizeKeys(device.HolidayMode || {}) };
140
- if (Array.isArray(device.Schedule)) device.Schedule = device.Schedule.map(capitalizeKeysDeep);
146
+ if (Array.isArray(device.Schedule)) device.Schedule = device.Schedule.map(capitalizeKeysDeep || []);
141
147
 
142
148
  // Usuń stare pola Settings i Capabilities
143
149
  const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
@@ -160,6 +166,35 @@ class MelCloud extends EventEmitter {
160
166
  ];
161
167
  });
162
168
 
169
+ const scenes = scenesList.flatMap(scene => {
170
+ const capitalizeKeysDeep = obj => {
171
+ if (Array.isArray(obj)) {
172
+ return obj.map(item => capitalizeKeysDeep(item));
173
+ }
174
+
175
+ if (obj && typeof obj === 'object') {
176
+ return Object.fromEntries(
177
+ Object.entries(obj).map(([key, value]) => [
178
+ key.charAt(0).toUpperCase() + key.slice(1),
179
+ capitalizeKeysDeep(value)
180
+ ])
181
+ );
182
+ }
183
+
184
+ return obj;
185
+ };
186
+
187
+ // merge ATA + ATW arrays
188
+ const allSettings = [
189
+ ...(scene.ataSceneSettings || []),
190
+ ...(scene.ervSceneSettings || []),
191
+ ...(scene.atwSceneSettings || [])
192
+ ];
193
+
194
+ return allSettings.map(setting => capitalizeKeysDeep(setting));
195
+ });
196
+
197
+
163
198
  const devicesCount = devices.length;
164
199
  if (devicesCount === 0) {
165
200
  devicesList.Info = 'No devices found'
@@ -169,6 +204,7 @@ class MelCloud extends EventEmitter {
169
204
  devicesList.State = true;
170
205
  devicesList.Info = `Found ${devicesCount} devices`;
171
206
  devicesList.Devices = devices;
207
+ devicesList.Scenes = scenes;
172
208
 
173
209
  await this.functions.saveData(this.devicesFile, devicesList);
174
210
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);