homebridge-melcloud-control 4.0.0-beta.154 → 4.0.0-beta.156

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.0.0-beta.154",
4
+ "version": "4.0.0-beta.156",
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
@@ -35,14 +35,18 @@ export const DeviceType = [
35
35
  export const TemperatureDisplayUnits = ["°C", "°F"];
36
36
 
37
37
  export const AirConditioner = {
38
- System: ["AIR CONDITIONER OFF", "AIR CONDITIONER ON", "AIR CONDITIONER OFFLINE"],
39
- OperationMode: ["0", "HEAT", "DRY", "COOL", "4", "5", "6", "FAN", "AUTO", "ISEE HEAT", "ISEE DRY", "ISEE COOL"],
40
- VaneVertical: ["AUTO", "UP", "UP CENTER", "CENTER", "DOWN CENTER", "DOWN", "6", "SWING"],
41
- VaneHorizontal: ["AUTO", "LEFT", "LEFT CENTER", "CENTER", "RIGHT CENTER", "RIGHT", "6", "7", "SPLIT", "9", "10", "11", "SWING"],
42
- AirDirection: ["AUTO", "SWING"],
43
- FanSpeedMapHomekit: ["AUTO", "VERY QUIT", "QUIET", "WEAK", "MIDDLE", "STRONG", "VERY STRONG", "OFF"],
44
- CurrentOperationModeHeatherCooler: ["INACTIVE", "IDLE", "HEATING", "COOLING"],
45
- CurrentOperationModeThermostat: ["INACTIVE", "HEATING", "COOLING"],
38
+ SystemMapEnumToString: { 0: "Air Conditioner Off", 1: "ir Conditioner On", 2: "ir Conditioner Offline" },
39
+ AirDirectionMapEnumToString: { 0: "Auto", 1: "Swing" },
40
+ CurrentOperationModeHeatherCoolerMapEnumToString: { 0: "Inactive", 1: "Idle", 2: "Heating", 3: "Cooling" },
41
+ CurrentOperationModeThermostatMapEnumToString: { 0: "Inactive", 1: "Heating", 2: "Cooling" },
42
+ OperationModeMapStringToEnum: { "0": 0, "Heat": 1, "Dry": 2, "Cool": 3, "4": 4, "5": 5, "6": 6, "Fan": 7, "Auto": 8, "Isee Heat": 9, "Isee Dry": 10, "Isee Cool": 11 },
43
+ OperationModeMapEnumToString: { 0: "0", 1: "Heat", 2: "Dry", 3: "Cool", 4: "4", 5: "5", 6: "6", 7: "Fan", 8: "Auto", 9: "Isee Heat", 10: "Isee Dry", 11: "Isee Cool" },
44
+ FanSpeedMapStringToEnum: { "Auto": 0, "One": 1, "Two": 2, "Three": 3, "Four": 4, "Five": 5, "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, },
45
+ FanSpeedMapEnumToString: { 0: "Auto", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five" },
46
+ VaneVerticalDirectionMapStringToEnum: { "Auto": 0, "One": 1, "Two": 2, "Three": 3, "Four": 4, "Five": 5, "Six": 6, "Swing": 7 },
47
+ VaneVerticalDirectionMapEnumToString: { 0: "Auto", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Swing" },
48
+ VaneHorizontalDirectionMapStringToEnum: { "Auto": 0, "Left": 1, "LeftCenter": 2, "Center": 3, "RightCenter": 4, "Right": 5, "Six": 6, "Seven": 7, "Split": 8, "Nine": 9, "Ten": 10, "Eleven": 11, "Swing": 12 },
49
+ VaneHorizontalDirectionMapEnumToString: { 0: "Auto", 1: "Left", 2: "LeftCenter", 3: "Center", 4: "RightCenter", 5: "Right", 6: "Six", 7: "Seven", 8: "Split", 9: "Nine", 10: "Ten", 11: "Eleven", 12: "Swing" },
46
50
  EffectiveFlags: {
47
51
  Power: 1,
48
52
  OperationMode: 2,
@@ -63,14 +67,6 @@ export const AirConditioner = {
63
67
  HolidayMode: 131072,
64
68
  All: 281483566710825
65
69
  },
66
- OperationModeMapStringToEnum: { "0": 0, "Heat": 1, "Dry": 2, "Cool": 3, "4": 4, "5": 5, "6": 6, "Fan": 7, "Auto": 8, "Isee Heat": 9, "Isee Dry": 10, "Isee Cool": 11 },
67
- OperationModeMapEnumToString: { 0: "0", 1: "Heat", 2: "Dry", 3: "Cool", 4: "4", 5: "5", 6: "6", 7: "Fan", 8: "Auto", 9: "Isee Heat", 10: "Isee Dry", 11: "Isee Cool" },
68
- FanSpeedMapStringToEnum: { "Auto": 0, "One": 1, "Two": 2, "Three": 3, "Four": 4, "Five": 5, "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, },
69
- FanSpeedMapEnumToString: { 0: "Auto", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five" },
70
- VaneVerticalDirectionMapStringToEnum: { "Auto": 0, "One": 1, "Two": 2, "Three": 3, "Four": 4, "Five": 5, "Six": 6, "Swing": 7 },
71
- VaneVerticalDirectionMapEnumToString: { 0: "Auto", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Swing" },
72
- VaneHorizontalDirectionMapStringToEnum: { "Auto": 0, "Left": 1, "LeftCenter": 2, "Center": 3, "RightCenter": 4, "Right": 5, "Six": 6, "Seven": 7, "Split": 8, "Nine": 9, "Ten": 10, "Eleven": 11, "Swing": 12 },
73
- VaneHorizontalDirectionMapEnumToString: { 0: "Auto", 1: "Left", 2: "LeftCenter", 3: "Center", 4: "RightCenter", 5: "Right", 6: "Six", 7: "Seven", 8: "Split", 9: "Nine", 10: "Ten", 11: "Eleven", 12: "Swing" },
74
70
  };
75
71
 
76
72
  export const HeatPump = {
package/src/deviceata.js CHANGED
@@ -331,11 +331,9 @@ class DeviceAta extends EventEmitter {
331
331
  return;
332
332
  };
333
333
 
334
- this.emit('warn', deviceData.Device.OperationMode);
335
334
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.OperationMode;
336
335
  await this.melCloudAta.send(this.accountType, deviceData, this.displayMode);
337
- const operationModeText = AirConditioner.OperationMode[deviceData.Device.OperationMode];
338
- if (this.logInfo) this.emit('info', `Set operation mode: ${operationModeText}`);
336
+ if (this.logInfo) this.emit('info', `Set operation mode: ${AirConditioner.OperationModeMapEnumToString[deviceData.Device.OperationMode]}`);
339
337
  } catch (error) {
340
338
  if (this.logWarn) this.emit('warn', `Set operation mode error: ${error}`);
341
339
  };
@@ -358,29 +356,24 @@ class DeviceAta extends EventEmitter {
358
356
  })
359
357
  .onSet(async (value) => {
360
358
  try {
361
- let fanSpeedModeText = '';
362
359
  const fanKey = this.accountType === 'melcloud' ? 'FanSpeed' : 'SetFanSpeed';
363
360
  switch (numberOfFanSpeeds) {
364
361
  case 2: //Fan speed mode 2
365
- fanSpeedModeText = supportsAutomaticFanSpeed ? [7, 1, 2, 0][value] : [7, 1, 2][value];
366
362
  deviceData.Device[fanKey] = supportsAutomaticFanSpeed ? [0, 1, 2, 0][value] : [1, 1, 2][value];
367
363
  break;
368
364
  case 3: //Fan speed mode 3
369
- fanSpeedModeText = supportsAutomaticFanSpeed ? [7, 1, 2, 3, 0][value] : [7, 1, 2, 3][value];
370
365
  deviceData.Device[fanKey] = supportsAutomaticFanSpeed ? [0, 1, 2, 3, 0][value] : [1, 1, 2, 3][value];
371
366
  break;
372
367
  case 4: //Fan speed mode 4
373
- fanSpeedModeText = supportsAutomaticFanSpeed ? [7, 1, 2, 3, 4, 0][value] : [7, 1, 2, 3, 4][value];
374
368
  deviceData.Device[fanKey] = supportsAutomaticFanSpeed ? [0, 1, 2, 3, 4, 0][value] : [1, 1, 2, 3, 4][value];
375
369
  break;
376
370
  case 5: //Fan speed mode 5
377
- fanSpeedModeText = supportsAutomaticFanSpeed ? [7, 1, 2, 3, 4, 5, 0][value] : [7, 1, 2, 3, 4, 5][value];
378
371
  deviceData.Device[fanKey] = supportsAutomaticFanSpeed ? [0, 1, 2, 3, 4, 5, 0][value] : [1, 1, 2, 3, 4, 5][value];
379
372
  break;
380
373
  };
381
374
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetFanSpeed;
382
375
  await this.melCloudAta.send(this.accountType, deviceData, this.displayMode);
383
- if (this.logInfo) this.emit('info', `Set fan speed mode: ${AirConditioner.FanSpeedMapHomekit[fanSpeedModeText]}`);
376
+ if (this.logInfo) this.emit('info', `Set fan speed mode: ${AirConditioner.FanSpeedMapEnumToString[deviceData.Device[fanKey]]}`);
384
377
  } catch (error) {
385
378
  if (this.logWarn) this.emit('warn', `Set fan speed mode error: ${error}`);
386
379
  };
@@ -399,7 +392,7 @@ class DeviceAta extends EventEmitter {
399
392
  deviceData.Device.VaneVerticalDirection = value ? 7 : 0;
400
393
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.VaneVerticalVaneHorizontal;
401
394
  await this.melCloudAta.send(this.accountType, deviceData, this.displayMode);
402
- if (this.logInfo) this.emit('info', `Set air direction mode: ${AirConditioner.AirDirection[value]}`);
395
+ if (this.logInfo) this.emit('info', `Set air direction mode: ${AirConditioner.AirDirectionMapEnumToString[value]}`);
403
396
  } catch (error) {
404
397
  if (this.logWarn) this.emit('warn', `Set vane swing mode error: ${error}`);
405
398
  };
@@ -528,7 +521,7 @@ class DeviceAta extends EventEmitter {
528
521
  };
529
522
 
530
523
  await this.melCloudAta.send(this.accountType, deviceData, this.displayMode);
531
- const operationModeText = AirConditioner.OperationMode[deviceData.Device.OperationMode];
524
+ const operationModeText = AirConditioner.OperationModeMapEnumToString[deviceData.Device.OperationMode];
532
525
  if (this.logInfo) this.emit('info', `Set operation mode: ${operationModeText}`);
533
526
  } catch (error) {
534
527
  if (this.logWarn) this.emit('warn', `Set operation mode error: ${error}`);
@@ -1327,16 +1320,16 @@ class DeviceAta extends EventEmitter {
1327
1320
  //log current state
1328
1321
  if (this.logInfo) {
1329
1322
  this.emit('info', `Power: ${power ? 'ON' : 'OFF'}`);
1330
- this.emit('info', `Target operation mode: ${AirConditioner.OperationMode[operationMode]}`);
1331
- this.emit('info', `Current operation mode: ${this.displayMode === 1 ? AirConditioner.CurrentOperationModeHeatherCooler[obj.currentOperationMode] : AirConditioner.CurrentOperationModeThermostat[obj.currentOperationMode]}`);
1323
+ this.emit('info', `Target operation mode: ${AirConditioner.OperationModeMapEnumToString[operationMode]}`);
1324
+ this.emit('info', `Current operation mode: ${this.displayMode === 1 ? AirConditioner.CurrentOperationModeHeatherCoolerMapEnumToString[obj.currentOperationMode] : AirConditioner.CurrentOperationModeThermostatMapEnumToString[obj.currentOperationMode]}`);
1332
1325
  this.emit('info', `Target temperature: ${setTemperature}${obj.temperatureUnit}`);
1333
1326
  this.emit('info', `Current temperature: ${roomTemperature}${obj.temperatureUnit}`);
1334
1327
  if (supportsOutdoorTemperature && outdoorTemperature !== null) this.emit('info', `Outdoor temperature: ${outdoorTemperature}${obj.temperatureUnit}`);
1335
- if (supportsFanSpeed) this.emit('info', `Target fan speed: ${AirConditioner.FanSpeedMapHomekit[setFanSpeed]}`);
1336
- if (supportsFanSpeed) this.emit('info', `Current fan speed: ${AirConditioner.FanSpeedMapHomekit[actualFanSpeed]}`);
1337
- if (vaneHorizontalDirection !== null) this.emit('info', `Vane horizontal: ${AirConditioner.VaneHorizontal[vaneHorizontalDirection]}`);
1338
- if (vaneVerticalDirection !== null) this.emit('info', `Vane vertical: ${AirConditioner.VaneVertical[vaneVerticalDirection]}`);
1339
- if (supportsSwingFunction) this.emit('info', `Air direction: ${AirConditioner.AirDirection[obj.currentSwingMode]}`);
1328
+ if (supportsFanSpeed) this.emit('info', `Target fan speed: ${AirConditioner.FanSpeedMapEnumToString[setFanSpeed]}`);
1329
+ if (supportsFanSpeed) this.emit('info', `Current fan speed: ${AirConditioner.FanSpeedMapEnumToString[actualFanSpeed]}`);
1330
+ if (vaneHorizontalDirection !== null) this.emit('info', `Vane horizontal: ${AirConditioner.VaneHorizontalDirectionMapEnumToString[vaneHorizontalDirection]}`);
1331
+ if (vaneVerticalDirection !== null) this.emit('info', `Vane vertical: ${AirConditioner.VaneVerticalDirectionMapEnumToString[vaneVerticalDirection]}`);
1332
+ if (supportsSwingFunction) this.emit('info', `Air direction: ${AirConditioner.AirDirectionMapEnumToString[obj.currentSwingMode]}`);
1340
1333
  this.emit('info', `Temperature display unit: ${obj.temperatureUnit}`);
1341
1334
  this.emit('info', `Lock physical controls: ${obj.lockPhysicalControl ? 'LOCKED' : 'UNLOCKED'}`);
1342
1335
  };
@@ -192,50 +192,53 @@ class MelCloudAta extends EventEmitter {
192
192
  };
193
193
 
194
194
  async send(accountType, deviceData, displayMode) {
195
- switch (accountType) {
196
- case "melcloud":
197
- try {
195
+ try {
196
+ switch (accountType) {
197
+ // ----------------------------------------------------------
198
+ // MELCloud standard account
199
+ // ----------------------------------------------------------
200
+ case "melcloud": {
198
201
  const axiosInstancePost = axios.create({
199
- method: 'POST',
200
202
  baseURL: ApiUrls.BaseURL,
201
203
  timeout: 25000,
202
204
  headers: {
203
205
  'X-MitsContextKey': deviceData.ContextKey,
204
- 'content-type': 'application/json'
206
+ 'Content-Type': 'application/json'
205
207
  },
206
208
  withCredentials: true
207
209
  });
208
210
 
209
- //set target temp based on display mode and operation mode
211
+ // Set target temperature based on display and operation mode
210
212
  switch (displayMode) {
211
- case 1: //Heather/Cooler
213
+ case 1: // Heater/Cooler
212
214
  switch (deviceData.Device.OperationMode) {
213
- case 1: //HEAT
214
- case 9: //ISEE HEAT
215
+ case 1: // HEAT
216
+ case 9: // ISEE HEAT
215
217
  deviceData.Device.SetTemperature = deviceData.Device.DefaultHeatingSetTemperature;
216
218
  break;
217
- case 2: //DRY
218
- case 3: //COOL
219
- case 10: //ISEE DRY
220
- case 11: //ISEE COOL
219
+ case 2: // DRY
220
+ case 3: // COOL
221
+ case 10: // ISEE DRY
222
+ case 11: // ISEE COOL
221
223
  deviceData.Device.SetTemperature = deviceData.Device.DefaultCoolingSetTemperature;
222
224
  break;
223
- case 7: //FAN
224
- deviceData.Device.SetTemperature = deviceData.Device.SetTemperature;
225
+ case 7: // FAN
225
226
  break;
226
- case 8: //AUTO
227
- deviceData.Device.SetTemperature = (deviceData.Device.DefaultCoolingSetTemperature + deviceData.Device.DefaultHeatingSetTemperature) / 2;
227
+ case 8: // AUTO
228
+ deviceData.Device.SetTemperature =
229
+ (deviceData.Device.DefaultCoolingSetTemperature + deviceData.Device.DefaultHeatingSetTemperature) / 2;
228
230
  break;
229
231
  default:
230
- deviceData.Device.SetTemperature = deviceData.Device.SetTemperature;
231
232
  break;
232
- };
233
- case 2: //Thermostat
234
- deviceData.Device.SetTemperature = deviceData.Device.SetTemperature;
233
+ }
234
+ break;
235
+
236
+ case 2: // Thermostat
235
237
  break;
238
+
236
239
  default:
237
240
  return;
238
- };
241
+ }
239
242
 
240
243
  const payload = {
241
244
  data: {
@@ -256,20 +259,20 @@ class MelCloudAta extends EventEmitter {
256
259
  HideDryModeControl: deviceData.HideDryModeControl,
257
260
  HasPendingCommand: true
258
261
  }
259
- }
262
+ };
260
263
 
261
- await axiosInstancePost(ApiUrls.SetAta, payload);
264
+ await axiosInstancePost.post(ApiUrls.SetAta, payload);
262
265
  this.emit('deviceState', deviceData);
263
266
  return true;
264
- } catch (error) {
265
- throw new Error(`Send data error: ${error}`);
266
- };
267
- case "melcloudhome":
268
- try {
267
+ }
268
+
269
+ // ----------------------------------------------------------
270
+ // MELCloud Home account
271
+ // ----------------------------------------------------------
272
+ case "melcloudhome": {
269
273
  const axiosInstancePut = axios.create({
270
- method: 'PUT',
271
- timeout: 25000,
272
274
  baseURL: ApiUrlsHome.BaseURL,
275
+ timeout: 25000,
273
276
  headers: {
274
277
  'Accept': '*/*',
275
278
  'Accept-Language': 'en-US,en;q=0.9',
@@ -285,30 +288,28 @@ class MelCloudAta extends EventEmitter {
285
288
  }
286
289
  });
287
290
 
288
- //set target temp based on display mode and operation mode
291
+ // Set target temp
289
292
  switch (displayMode) {
290
- case 1: //Heather/Cooler
291
- switch (deviceData.Device.OperationMode) {
292
- case 8: //AUTO
293
- deviceData.Device.SetTemperature = (deviceData.Device.DefaultCoolingSetTemperature + deviceData.Device.DefaultHeatingSetTemperature) / 2;
294
- break;
295
- default:
296
- deviceData.Device.SetTemperature = deviceData.Device.SetTemperature;
297
- break;
298
- };
299
- case 2: //Thermostat
300
- deviceData.Device.SetTemperature = deviceData.Device.SetTemperature;
293
+ case 1: // Heater/Cooler
294
+ if (deviceData.Device.OperationMode === 8) {
295
+ deviceData.Device.SetTemperature =
296
+ (deviceData.Device.DefaultCoolingSetTemperature + deviceData.Device.DefaultHeatingSetTemperature) / 2;
297
+ }
298
+ break;
299
+ case 2: // Thermostat
301
300
  break;
302
301
  default:
303
302
  return;
304
- };
303
+ }
304
+
305
+ // Convert values to strings
306
+ deviceData.Device.Power = String(deviceData.Device.Power ?? '');
307
+ deviceData.Device.SetTemperature = String(deviceData.Device.SetTemperature ?? '');
308
+ deviceData.Device.SetFanSpeed = String(deviceData.Device.SetFanSpeed ?? '');
309
+ deviceData.Device.OperationMode = AirConditioner.OperationModeMapEnumToString?.[deviceData.Device.OperationMode] ?? '';
310
+ deviceData.Device.VaneHorizontalDirection = AirConditioner.VaneHorizontalDirectionMapEnumToString?.[deviceData.Device.VaneHorizontalDirection] ?? '';
311
+ deviceData.Device.VaneVerticalDirection = AirConditioner.VaneVerticalDirectionMapEnumToString?.[deviceData.Device.VaneVerticalDirection] ?? '';
305
312
 
306
- deviceData.Device.Power = deviceData.Device.Power.toString();
307
- deviceData.Device.SetTemperature = deviceData.Device.SetTemperature.toString();
308
- deviceData.Device.SetFanSpeed = deviceData.Device.SetFanSpeed.toString();
309
- deviceData.Device.OperationMode = AirConditioner.OperationModeMapEnumToString[deviceData.Device.OperationMode];
310
- deviceData.Device.VaneHorizontalDirection = AirConditioner.VaneHorizontalDirectionMapEnumToString[deviceData.Device.VaneHorizontalDirection];
311
- deviceData.Device.VaneVerticalDirection = AirConditioner.VaneVerticalDirectionMapEnumToString[deviceData.Device.VaneVerticalDirection];
312
313
  this.emit('warn', JSON.stringify(deviceData.Device, null, 2));
313
314
 
314
315
  const payload = {
@@ -320,19 +321,29 @@ class MelCloudAta extends EventEmitter {
320
321
  VaneHorizontalDirection: deviceData.Device.VaneHorizontalDirection,
321
322
  VaneVerticalDirection: deviceData.Device.VaneVerticalDirection
322
323
  }
323
- }
324
+ };
324
325
 
325
326
  this.emit('warn', JSON.stringify(payload, null, 2));
326
327
 
327
328
  const path = ApiUrlsHome.SetAta.replace('deviceid', deviceData.DeviceID);
328
- await axiosInstancePut(path, payload);
329
+ await axiosInstancePut.put(path, payload);
330
+
329
331
  return true;
330
- } catch (error) {
331
- throw new Error(`Send data error: ${error}`);
332
- };
333
- default:
334
- return;
332
+ }
333
+
334
+ default:
335
+ return;
336
+ }
337
+ } catch (error) {
338
+ if (error.response) {
339
+ throw new Error(`Send data error: HTTP ${error.response.status} - ${JSON.stringify(error.response.data)}`);
340
+ } else if (error.request) {
341
+ throw new Error(`Send data error: No response received - ${error.message}`);
342
+ } else {
343
+ throw new Error(`Send data error: ${error.message}`);
344
+ }
335
345
  }
336
346
  }
347
+
337
348
  };
338
349
  export default MelCloudAta;