homebridge-melcloud-control 4.2.3-beta.35 → 4.2.3-beta.37

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.35",
4
+ "version": "4.2.3-beta.37",
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"
@@ -205,17 +205,10 @@ class MelCloudAta extends EventEmitter {
205
205
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PostProtectionOverheat.replace('deviceid', deviceData.DeviceID);
206
206
  break;
207
207
  case 'holidaymode':
208
- const formatDateNoSeconds = (date) => {
209
- const d = new Date(date);
210
- const pad = (n) => n.toString().padStart(2, '0');
211
- return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
212
- };
213
-
214
- // przykład użycia
215
208
  payload = {
216
209
  enabled: deviceData.HolidayMode.Enabled,
217
- startDate: formatDateNoSeconds(deviceData.HolidayMode.StartDate),
218
- endDate: formatDateNoSeconds(deviceData.HolidayMode.EndDate),
210
+ startDate: deviceData.HolidayMode.StartDate,
211
+ endDate: deviceData.HolidayMode.EndDate,
219
212
  units: { "ATA": [deviceData.DeviceID] }
220
213
  };
221
214
  method = 'POST';
@@ -226,7 +219,6 @@ class MelCloudAta extends EventEmitter {
226
219
  payload = { enabled: deviceData.ScheduleEnabled };
227
220
  method = 'PUT';
228
221
  path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
229
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
230
222
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
231
223
  break;
232
224
  default:
@@ -240,7 +232,7 @@ class MelCloudAta extends EventEmitter {
240
232
  };
241
233
  method = 'PUT';
242
234
  path = ApiUrlsHome.PutAta.replace('deviceid', deviceData.DeviceID);
243
- deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDashboard
235
+ deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
244
236
  break
245
237
  }
246
238
 
@@ -271,7 +263,7 @@ class MelCloudAta extends EventEmitter {
271
263
 
272
264
  setTimeout(() => {
273
265
  this.lock = false
274
- }, 3000);
266
+ }, 2500);
275
267
  }
276
268
  };
277
269
  export default MelCloudAta;
@@ -185,14 +185,12 @@ class MelCloudAtw extends EventEmitter {
185
185
  };
186
186
  method = 'POST';
187
187
  path = ApiUrlsHome.PostHolidayMode;
188
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
189
188
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
190
189
  break;
191
190
  case 'schedule':
192
191
  payload = { enabled: deviceData.ScheduleEnabled };
193
192
  method = 'PUT';
194
193
  path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
195
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
196
194
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
197
195
  break;
198
196
  default:
@@ -213,7 +211,7 @@ class MelCloudAtw extends EventEmitter {
213
211
  };
214
212
  method = 'PUT';
215
213
  path = ApiUrlsHome.PutAtw.replace('deviceid', deviceData.DeviceID);
216
- deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDashboard
214
+ deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
217
215
  break
218
216
  }
219
217
 
@@ -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;
@@ -195,18 +195,16 @@ class MelCloudErv extends EventEmitter {
195
195
  enabled: deviceData.HolidayMode.Enabled,
196
196
  startDate: deviceData.HolidayMode.StartDate,
197
197
  endDate: deviceData.HolidayMode.EndDate,
198
- units: { "ATW": [deviceData.DeviceID] }
198
+ units: { "ERV": [deviceData.DeviceID] }
199
199
  };
200
200
  method = 'POST';
201
201
  path = ApiUrlsHome.PostHolidayMode;
202
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
203
202
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
204
203
  break;
205
204
  case 'schedule':
206
205
  payload = { enabled: deviceData.ScheduleEnabled };
207
206
  method = 'PUT';
208
207
  path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
209
- deviceData.Headers.Origin = ApiUrlsHome.Origin;
210
208
  deviceData.Headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
211
209
  break;
212
210
  default:
@@ -219,7 +217,7 @@ class MelCloudErv extends EventEmitter {
219
217
  };
220
218
  method = 'PUT';
221
219
  path = ApiUrlsHome.PutErv.replace('deviceid', deviceData.DeviceID);
222
- deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDashboard
220
+ deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
223
221
  break
224
222
  }
225
223
 
@@ -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;
@@ -62,9 +62,54 @@ class MelCloud extends EventEmitter {
62
62
  }
63
63
 
64
64
  // MELCloud Home
65
+ async checkScenesList() {
66
+ try {
67
+ if (this.logDebug) this.emit('debug', `Scanning for scenes`);
68
+ const listScenesData = await axios(ApiUrlsHome.GetUserScenes, {
69
+ method: 'GET',
70
+ baseURL: ApiUrlsHome.BaseURL,
71
+ timeout: 25000,
72
+ headers: this.headers
73
+ });
74
+
75
+ const scenesList = listScenesData.data;
76
+ if (this.logDebug) this.emit('debug', `Scenes: ${JSON.stringify(scenesList, null, 2)}`);
77
+
78
+ const scenes = scenesList.flatMap(scene => {
79
+ const capitalizeKeysDeep = obj => {
80
+ if (Array.isArray(obj)) {
81
+ return obj.map(item => capitalizeKeysDeep(item));
82
+ }
83
+
84
+ if (obj && typeof obj === 'object') {
85
+ return Object.fromEntries(
86
+ Object.entries(obj).map(([key, value]) => [
87
+ key.charAt(0).toUpperCase() + key.slice(1),
88
+ capitalizeKeysDeep(value)
89
+ ])
90
+ );
91
+ }
92
+
93
+ return obj;
94
+ };
95
+
96
+ const allSettings = [
97
+ ...(scene.ataSceneSettings || []),
98
+ ...(scene.ervSceneSettings || []),
99
+ ...(scene.atwSceneSettings || [])
100
+ ];
101
+
102
+ return allSettings.map(setting => capitalizeKeysDeep(setting));
103
+ });
104
+ return scenes;
105
+ } catch (error) {
106
+ throw new Error(`Check scenes list error: ${error.message}`);
107
+ }
108
+ }
109
+
65
110
  async checkDevicesList() {
66
111
  try {
67
- const devicesList = { State: false, Info: null, Devices: [] }
112
+ const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
68
113
  if (this.logDebug) this.emit('debug', `Scanning for devices`);
69
114
  const listDevicesData = await axios(ApiUrlsHome.GetUserContext, {
70
115
  method: 'GET',
@@ -72,7 +117,11 @@ class MelCloud extends EventEmitter {
72
117
  timeout: 25000,
73
118
  headers: this.headers
74
119
  });
75
- const buildingsList = listDevicesData.data.buildings;
120
+
121
+ const userContext = listDevicesData.data;
122
+ const buildings = userContext.buildings ?? [];
123
+ const guestBuildings = userContext.guestBuildings ?? [];
124
+ const buildingsList = [...buildings, ...guestBuildings];
76
125
  if (this.logDebug) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
77
126
 
78
127
  if (!buildingsList) {
@@ -80,7 +129,7 @@ class MelCloud extends EventEmitter {
80
129
  return devicesList;
81
130
  }
82
131
 
83
- await this.functions.saveData(this.buildingsFile, buildingsList);
132
+ await this.functions.saveData(this.buildingsFile, userContext);
84
133
  if (this.logDebug) this.emit('debug', `Buildings list saved`);
85
134
 
86
135
  const devices = buildingsList.flatMap(building => {
@@ -137,7 +186,7 @@ class MelCloud extends EventEmitter {
137
186
  if (device.FrostProtection) device.FrostProtection = { ...capitalizeKeys(device.FrostProtection || {}) };
138
187
  if (device.OverheatProtection) device.OverheatProtection = { ...capitalizeKeys(device.OverheatProtection || {}) };
139
188
  if (device.HolidayMode) device.HolidayMode = { ...capitalizeKeys(device.HolidayMode || {}) };
140
- if (Array.isArray(device.Schedule)) device.Schedule = device.Schedule.map(capitalizeKeysDeep);
189
+ if (Array.isArray(device.Schedule)) device.Schedule = device.Schedule.map(capitalizeKeysDeep || []);
141
190
 
142
191
  // Usuń stare pola Settings i Capabilities
143
192
  const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
@@ -166,9 +215,12 @@ class MelCloud extends EventEmitter {
166
215
  return devicesList;
167
216
  }
168
217
 
218
+ const scenes = this.checkScenesList();
219
+
169
220
  devicesList.State = true;
170
221
  devicesList.Info = `Found ${devicesCount} devices`;
171
222
  devicesList.Devices = devices;
223
+ devicesList.Scenes = scenes;
172
224
 
173
225
  await this.functions.saveData(this.devicesFile, devicesList);
174
226
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);