homebridge-melcloud-control 4.2.5-beta.2 → 4.2.5-beta.20
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/README.md +3 -3
- package/config.schema.json +36 -18
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/constants.js +1 -0
- package/src/deviceata.js +256 -231
- package/src/deviceatw.js +185 -164
- package/src/deviceerv.js +128 -104
- package/src/melcloud.js +9 -16
- package/src/melcloudata.js +18 -27
- package/src/melcloudatw.js +10 -20
- package/src/melclouderv.js +10 -20
- package/src/melcloudhome.js +17 -39
package/src/deviceerv.js
CHANGED
|
@@ -82,8 +82,8 @@ class DeviceErv extends EventEmitter {
|
|
|
82
82
|
//buttons configured
|
|
83
83
|
for (const button of this.buttons) {
|
|
84
84
|
button.name = button.name || 'Button'
|
|
85
|
-
button.serviceType = [
|
|
86
|
-
button.characteristicType = [
|
|
85
|
+
button.serviceType = serviceType[button.displayType];
|
|
86
|
+
button.characteristicType = characteristicType[button.displayType];
|
|
87
87
|
button.state = false;
|
|
88
88
|
button.previousValue = null;
|
|
89
89
|
}
|
|
@@ -741,7 +741,7 @@ class DeviceErv extends EventEmitter {
|
|
|
741
741
|
.onSet(async (state) => {
|
|
742
742
|
try {
|
|
743
743
|
deviceData.HolidayMode.Enabled = state;
|
|
744
|
-
if (this.logInfo) this.emit('info', `Holiday mode: ${state ? '
|
|
744
|
+
if (this.logInfo) this.emit('info', `Holiday mode: ${state ? 'Enabled' : 'Disabled'}`);
|
|
745
745
|
await this.melCloudErv.send(this.accountType, this.displayType, deviceData, 'holidaymode');
|
|
746
746
|
} catch (error) {
|
|
747
747
|
if (this.logWarn) this.emit('warn', `Set holiday mode error: ${error}`);
|
|
@@ -823,7 +823,7 @@ class DeviceErv extends EventEmitter {
|
|
|
823
823
|
break;
|
|
824
824
|
};
|
|
825
825
|
|
|
826
|
-
if (this.logInfo) this.emit('info', `Preset ${name}: ${state ? 'Set
|
|
826
|
+
if (this.logInfo) this.emit('info', `Preset ${name}: ${state ? 'Set' : 'Unset'}`);
|
|
827
827
|
await this.melCloudErv.send(this.accountType, this.displayType, deviceData, AirConditioner.EffectiveFlags.Presets);
|
|
828
828
|
} catch (error) {
|
|
829
829
|
if (this.logWarn) this.emit('warn', `Set preset error: ${error}`);
|
|
@@ -880,7 +880,7 @@ class DeviceErv extends EventEmitter {
|
|
|
880
880
|
.onSet(async (state) => {
|
|
881
881
|
try {
|
|
882
882
|
deviceData.ScheduleEnabled = state;
|
|
883
|
-
if (this.logInfo) this.emit('info', `Schedules: ${state ? '
|
|
883
|
+
if (this.logInfo) this.emit('info', `Schedules: ${state ? 'Enabled' : 'Disabled'}`);
|
|
884
884
|
await this.melCloudErv.send(this.accountType, this.displayType, deviceData, 'schedule');
|
|
885
885
|
} catch (error) {
|
|
886
886
|
if (this.logWarn) this.emit('warn', `Set schedule serror: ${error}`);
|
|
@@ -949,7 +949,7 @@ class DeviceErv extends EventEmitter {
|
|
|
949
949
|
.onSet(async (state) => {
|
|
950
950
|
try {
|
|
951
951
|
sceneData.Enabled = state;
|
|
952
|
-
if (this.logInfo) this.emit('info', `Scene ${name}: ${state ? '
|
|
952
|
+
if (this.logInfo) this.emit('info', `Scene ${name}: ${state ? 'Set' : 'Unset'}`);
|
|
953
953
|
await this.melCloudErv.send(this.accountType, this.displayType, deviceData, 'scene', sceneData);
|
|
954
954
|
} catch (error) {
|
|
955
955
|
if (this.logWarn) this.emit('warn', `Set scene error: ${error}`);
|
|
@@ -975,116 +975,135 @@ class DeviceErv extends EventEmitter {
|
|
|
975
975
|
|
|
976
976
|
//buttons services
|
|
977
977
|
if (this.buttons.length > 0) {
|
|
978
|
-
if (this.logDebug) this.emit('debug', `Prepare buttons services`);
|
|
979
|
-
this.
|
|
978
|
+
if (this.logDebug) this.emit('debug', `Prepare buttons / sensors services`);
|
|
979
|
+
this.buttonControlServices = [];
|
|
980
|
+
this.buttonControlSensorServices = [];
|
|
980
981
|
this.buttons.forEach((button, i) => {
|
|
981
982
|
//get button mode
|
|
982
983
|
const mode = button.mode;
|
|
983
984
|
|
|
984
985
|
//get button name
|
|
985
|
-
const
|
|
986
|
+
const name = button.name;
|
|
986
987
|
|
|
987
988
|
//get button name prefix
|
|
988
989
|
const namePrefix = button.namePrefix;
|
|
989
990
|
|
|
990
|
-
const serviceName1 = namePrefix ? `${accessoryName} ${
|
|
991
|
+
const serviceName1 = namePrefix ? `${accessoryName} ${name}` : name;
|
|
991
992
|
const serviceType = button.serviceType;
|
|
992
993
|
const characteristicType = button.characteristicType;
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
994
|
+
|
|
995
|
+
//control
|
|
996
|
+
if (button.displayType > 3) {
|
|
997
|
+
if (this.logDebug) this.emit('debug', `Prepare button control ${name} service`);
|
|
998
|
+
const buttonControlService = new serviceType(serviceName1, `buttonControlService${deviceId} ${i}`);
|
|
999
|
+
buttonControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
1000
|
+
buttonControlService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
|
|
1001
|
+
buttonControlService.getCharacteristic(Characteristic.On)
|
|
1002
|
+
.onGet(async () => {
|
|
1003
|
+
const state = button.state;
|
|
1004
|
+
return state;
|
|
1005
|
+
})
|
|
1006
|
+
.onSet(async (state) => {
|
|
1007
|
+
try {
|
|
1008
|
+
let flag = null;
|
|
1009
|
+
switch (mode) {
|
|
1010
|
+
case 0: //POWER ON,OFF
|
|
1011
|
+
deviceData.Device.Power = state;
|
|
1012
|
+
flag = Ventilation.EffectiveFlags.Power;
|
|
1013
|
+
break;
|
|
1014
|
+
case 1: //OPERATING MODE RECOVERY
|
|
1015
|
+
button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
|
|
1016
|
+
deviceData.Device.Power = true;
|
|
1017
|
+
deviceData.Device.VentilationMode = state ? 0 : button.previousValue;
|
|
1018
|
+
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
|
|
1019
|
+
break;
|
|
1020
|
+
case 2: //OPERATING MODE BYPASS
|
|
1021
|
+
button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
|
|
1022
|
+
deviceData.Device.Power = true;
|
|
1023
|
+
deviceData.Device.VentilationMode = state ? 1 : button.previousValue;
|
|
1024
|
+
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
|
|
1025
|
+
break
|
|
1026
|
+
case 3: //OPERATING MODE AUTO
|
|
1027
|
+
button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
|
|
1028
|
+
deviceData.Device.Power = true;
|
|
1029
|
+
deviceData.Device.VentilationMode = state ? 2 : button.previousValue;
|
|
1030
|
+
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
|
|
1031
|
+
break;
|
|
1032
|
+
case 4: //NIGHT PURGE MODE
|
|
1033
|
+
deviceData.Device.Power = true;
|
|
1034
|
+
deviceData.Device.NightPurgeMode = state;
|
|
1035
|
+
flag = Ventilation.EffectiveFlags.Power
|
|
1036
|
+
break;
|
|
1037
|
+
case 10: //FAN SPEED MODE AUTO
|
|
1038
|
+
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1039
|
+
deviceData.Device.Power = true;
|
|
1040
|
+
deviceData.Device.SetFanSpeed = state ? 0 : button.previousValue;
|
|
1041
|
+
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1042
|
+
break;
|
|
1043
|
+
case 11: //FAN SPEED MODE 1
|
|
1044
|
+
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1045
|
+
deviceData.Device.Power = true;
|
|
1046
|
+
deviceData.Device.SetFanSpeed = state ? 1 : button.previousValue;
|
|
1047
|
+
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1048
|
+
break;
|
|
1049
|
+
case 12: //FAN SPEED MODE 2
|
|
1050
|
+
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1051
|
+
deviceData.Device.Power = true;
|
|
1052
|
+
deviceData.Device.SetFanSpeed = state ? 2 : button.previousValue;
|
|
1053
|
+
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1054
|
+
break;
|
|
1055
|
+
case 13: //FAN SPEED MODE 3
|
|
1056
|
+
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1057
|
+
deviceData.Device.Power = true;
|
|
1058
|
+
deviceData.Device.SetFanSpeed = state ? 3 : button.previousValue;
|
|
1059
|
+
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1060
|
+
break;
|
|
1061
|
+
case 14: //FAN MODE 4
|
|
1062
|
+
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1063
|
+
deviceData.Device.Power = true;
|
|
1064
|
+
deviceData.Device.SetFanSpeed = state ? 4 : button.previousValue;
|
|
1065
|
+
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1066
|
+
break;
|
|
1067
|
+
case 15: //PHYSICAL LOCK CONTROLS
|
|
1068
|
+
deviceData.Device = deviceData.Device;
|
|
1069
|
+
flag = Ventilation.EffectiveFlags.Prohibit;
|
|
1070
|
+
break;
|
|
1071
|
+
case 16: //ROOM TEMP HIDE
|
|
1072
|
+
deviceData.HideRoomTemperature = state;
|
|
1073
|
+
break;
|
|
1074
|
+
case 17: //SUPPLY TEMP HIDE
|
|
1075
|
+
deviceData.HideSupplyTemperature = state;
|
|
1076
|
+
break;
|
|
1077
|
+
case 18: //OUTDOOR EMP HIDE
|
|
1078
|
+
deviceData.hideOutdoorTemperature = state;
|
|
1079
|
+
break;
|
|
1080
|
+
default:
|
|
1081
|
+
if (this.logWarn) this.emit('warn', `Unknown button mode: ${mode}`);
|
|
1082
|
+
break;
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
if (this.logInfo) this.emit('info', `Button ${name}: ${state ? `Enabled` : `Disabled`}`);
|
|
1086
|
+
await this.melCloudErv.send(this.accountType, this.displayType, deviceData, flag);
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
if (this.logWarn) this.emit('warn', `Set button error: ${error}`);
|
|
1089
|
+
};
|
|
1090
|
+
});
|
|
1091
|
+
this.buttonControlServices.push(buttonControlService);
|
|
1092
|
+
accessory.addService(buttonControlService);
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
//sensor
|
|
1096
|
+
if (this.logDebug) this.emit('debug', `Prepare button control sensor ${name} service`);
|
|
1097
|
+
const buttonControlSensorService = new serviceType(serviceName1, `buttonControlSensorService${deviceId} ${i}`);
|
|
1098
|
+
buttonControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
1099
|
+
buttonControlSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
|
|
1100
|
+
buttonControlSensorService.getCharacteristic(characteristicType)
|
|
997
1101
|
.onGet(async () => {
|
|
998
1102
|
const state = button.state;
|
|
999
1103
|
return state;
|
|
1000
1104
|
})
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
let flag = null;
|
|
1004
|
-
switch (mode) {
|
|
1005
|
-
case 0: //POWER ON,OFF
|
|
1006
|
-
deviceData.Device.Power = state;
|
|
1007
|
-
flag = Ventilation.EffectiveFlags.Power;
|
|
1008
|
-
break;
|
|
1009
|
-
case 1: //OPERATING MODE RECOVERY
|
|
1010
|
-
button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
|
|
1011
|
-
deviceData.Device.Power = true;
|
|
1012
|
-
deviceData.Device.VentilationMode = state ? 0 : button.previousValue;
|
|
1013
|
-
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
|
|
1014
|
-
break;
|
|
1015
|
-
case 2: //OPERATING MODE BYPASS
|
|
1016
|
-
button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
|
|
1017
|
-
deviceData.Device.Power = true;
|
|
1018
|
-
deviceData.Device.VentilationMode = state ? 1 : button.previousValue;
|
|
1019
|
-
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
|
|
1020
|
-
break
|
|
1021
|
-
case 3: //OPERATING MODE AUTO
|
|
1022
|
-
button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
|
|
1023
|
-
deviceData.Device.Power = true;
|
|
1024
|
-
deviceData.Device.VentilationMode = state ? 2 : button.previousValue;
|
|
1025
|
-
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
|
|
1026
|
-
break;
|
|
1027
|
-
case 4: //NIGHT PURGE MODE
|
|
1028
|
-
deviceData.Device.Power = true;
|
|
1029
|
-
deviceData.Device.NightPurgeMode = state;
|
|
1030
|
-
flag = Ventilation.EffectiveFlags.Power
|
|
1031
|
-
break;
|
|
1032
|
-
case 10: //FAN SPEED MODE AUTO
|
|
1033
|
-
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1034
|
-
deviceData.Device.Power = true;
|
|
1035
|
-
deviceData.Device.SetFanSpeed = state ? 0 : button.previousValue;
|
|
1036
|
-
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1037
|
-
break;
|
|
1038
|
-
case 11: //FAN SPEED MODE 1
|
|
1039
|
-
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1040
|
-
deviceData.Device.Power = true;
|
|
1041
|
-
deviceData.Device.SetFanSpeed = state ? 1 : button.previousValue;
|
|
1042
|
-
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1043
|
-
break;
|
|
1044
|
-
case 12: //FAN SPEED MODE 2
|
|
1045
|
-
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1046
|
-
deviceData.Device.Power = true;
|
|
1047
|
-
deviceData.Device.SetFanSpeed = state ? 2 : button.previousValue;
|
|
1048
|
-
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1049
|
-
break;
|
|
1050
|
-
case 13: //FAN SPEED MODE 3
|
|
1051
|
-
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1052
|
-
deviceData.Device.Power = true;
|
|
1053
|
-
deviceData.Device.SetFanSpeed = state ? 3 : button.previousValue;
|
|
1054
|
-
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1055
|
-
break;
|
|
1056
|
-
case 14: //FAN MODE 4
|
|
1057
|
-
button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
|
|
1058
|
-
deviceData.Device.Power = true;
|
|
1059
|
-
deviceData.Device.SetFanSpeed = state ? 4 : button.previousValue;
|
|
1060
|
-
flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
|
|
1061
|
-
break;
|
|
1062
|
-
case 15: //PHYSICAL LOCK CONTROLS
|
|
1063
|
-
deviceData.Device = deviceData.Device;
|
|
1064
|
-
flag = Ventilation.EffectiveFlags.Prohibit;
|
|
1065
|
-
break;
|
|
1066
|
-
case 16: //ROOM TEMP HIDE
|
|
1067
|
-
deviceData.HideRoomTemperature = state;
|
|
1068
|
-
break;
|
|
1069
|
-
case 17: //SUPPLY TEMP HIDE
|
|
1070
|
-
deviceData.HideSupplyTemperature = state;
|
|
1071
|
-
break;
|
|
1072
|
-
case 18: //OUTDOOR EMP HIDE
|
|
1073
|
-
deviceData.hideOutdoorTemperature = state;
|
|
1074
|
-
break;
|
|
1075
|
-
default:
|
|
1076
|
-
if (this.logWarn) this.emit('warn', `Unknown button mode: ${mode}`);
|
|
1077
|
-
break;
|
|
1078
|
-
};
|
|
1079
|
-
|
|
1080
|
-
if (this.logInfo) this.emit('info', `${state ? `Set: ${buttonName}` : `Unset: ${buttonName}, Set: ${button.previousValue}`}`);
|
|
1081
|
-
await this.melCloudErv.send(this.accountType, this.displayType, deviceData, flag);
|
|
1082
|
-
} catch (error) {
|
|
1083
|
-
if (this.logWarn) this.emit('warn', `Set button error: ${error}`);
|
|
1084
|
-
};
|
|
1085
|
-
});
|
|
1086
|
-
this.buttonsServices.push(buttonService);
|
|
1087
|
-
accessory.addService(buttonService);
|
|
1105
|
+
this.buttonControlSensorServices.push(buttonControlSensorService);
|
|
1106
|
+
accessory.addService(buttonControlSensorService);
|
|
1088
1107
|
});
|
|
1089
1108
|
};
|
|
1090
1109
|
|
|
@@ -1500,9 +1519,14 @@ class DeviceErv extends EventEmitter {
|
|
|
1500
1519
|
break;
|
|
1501
1520
|
};
|
|
1502
1521
|
|
|
1503
|
-
//
|
|
1504
|
-
|
|
1505
|
-
|
|
1522
|
+
//control
|
|
1523
|
+
if (button.displayType > 3) {
|
|
1524
|
+
this.buttonControlServices?.[i]?.updateCharacteristic(Characteristic.On, button.state);
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
//sensor
|
|
1528
|
+
const characteristicType = scene.characteristicType;
|
|
1529
|
+
this.buttonControlSensorServices?.[i]?.updateCharacteristic(characteristicType, button.state);
|
|
1506
1530
|
});
|
|
1507
1531
|
};
|
|
1508
1532
|
|
package/src/melcloud.js
CHANGED
|
@@ -52,17 +52,11 @@ class MelCloud extends EventEmitter {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
// MELCloud
|
|
56
55
|
async checkDevicesList() {
|
|
57
56
|
try {
|
|
58
57
|
const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
|
|
59
58
|
if (this.logDebug) this.emit('debug', `Scanning for devices...`);
|
|
60
|
-
const listDevicesData = await
|
|
61
|
-
method: 'GET',
|
|
62
|
-
baseURL: ApiUrls.BaseURL,
|
|
63
|
-
timeout: 15000,
|
|
64
|
-
headers: this.headers
|
|
65
|
-
});
|
|
59
|
+
const listDevicesData = await this.axiosInstance(ApiUrls.ListDevices, { method: 'GET', });
|
|
66
60
|
|
|
67
61
|
if (!listDevicesData || !listDevicesData.data) {
|
|
68
62
|
devicesList.Info = 'Invalid or empty response from MELCloud API'
|
|
@@ -168,15 +162,20 @@ class MelCloud extends EventEmitter {
|
|
|
168
162
|
return accountInfo;
|
|
169
163
|
}
|
|
170
164
|
|
|
171
|
-
|
|
165
|
+
const headers = {
|
|
172
166
|
'X-MitsContextKey': contextKey,
|
|
173
167
|
'Content-Type': 'application/json'
|
|
174
168
|
};
|
|
169
|
+
this.headers = headers;
|
|
170
|
+
this.axiosInstance = axios.create({
|
|
171
|
+
baseURL: ApiUrls.BaseURL,
|
|
172
|
+
timeout: 30000,
|
|
173
|
+
headers: headers
|
|
174
|
+
});
|
|
175
175
|
|
|
176
176
|
accountInfo.State = true;
|
|
177
177
|
accountInfo.Info = 'Connect to MELCloud Success';
|
|
178
178
|
accountInfo.LoginData = loginData;
|
|
179
|
-
accountInfo.Headers = this.headers;
|
|
180
179
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
181
180
|
|
|
182
181
|
return accountInfo
|
|
@@ -188,13 +187,7 @@ class MelCloud extends EventEmitter {
|
|
|
188
187
|
async send(accountInfo) {
|
|
189
188
|
try {
|
|
190
189
|
const payload = { data: accountInfo.LoginData };
|
|
191
|
-
await
|
|
192
|
-
method: 'POST',
|
|
193
|
-
baseURL: ApiUrls.BaseURL,
|
|
194
|
-
timeout: 15000,
|
|
195
|
-
headers: accountInfo.Headers,
|
|
196
|
-
data: payload
|
|
197
|
-
});
|
|
190
|
+
await this.axiosInstance(ApiUrls.UpdateApplicationOptions, { method: 'POST', data: payload });
|
|
198
191
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
199
192
|
return true;
|
|
200
193
|
} catch (error) {
|
package/src/melcloudata.js
CHANGED
|
@@ -23,7 +23,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
23
23
|
|
|
24
24
|
//set default values
|
|
25
25
|
this.deviceData = {};
|
|
26
|
-
this.
|
|
26
|
+
this.baseURL = this.accountType === 'melcloud' ? ApiUrls.BaseURL : ApiUrlsHome.BaseURL;
|
|
27
27
|
|
|
28
28
|
//lock flag
|
|
29
29
|
this.locks = true;
|
|
@@ -53,12 +53,15 @@ class MelCloudAta extends EventEmitter {
|
|
|
53
53
|
try {
|
|
54
54
|
//read device info from file
|
|
55
55
|
const devicesData = await this.functions.readData(this.devicesFile, true);
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
this.axiosInstance = axios.create({
|
|
57
|
+
baseURL: this.baseURL,
|
|
58
|
+
timeout: 30000,
|
|
59
|
+
headers: devicesData.Headers
|
|
60
|
+
});
|
|
59
61
|
|
|
62
|
+
const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
60
63
|
if (this.accountType === 'melcloudhome') {
|
|
61
|
-
deviceData.Scenes =
|
|
64
|
+
deviceData.Scenes = devicesData.Scenes ?? [];
|
|
62
65
|
deviceData.Device.OperationMode = AirConditioner.OperationModeMapStringToEnum[deviceData.Device.OperationMode] ?? deviceData.Device.OperationMode;
|
|
63
66
|
deviceData.Device.ActualFanSpeed = AirConditioner.FanSpeedMapStringToEnum[deviceData.Device.ActualFanSpeed] ?? deviceData.Device.ActualFanSpeed;
|
|
64
67
|
deviceData.Device.SetFanSpeed = AirConditioner.FanSpeedMapStringToEnum[deviceData.Device.SetFanSpeed] ?? deviceData.Device.SetFanSpeed;
|
|
@@ -163,13 +166,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
163
166
|
};
|
|
164
167
|
|
|
165
168
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
|
|
166
|
-
await
|
|
167
|
-
method: 'POST',
|
|
168
|
-
baseURL: ApiUrls.BaseURL,
|
|
169
|
-
timeout: 10000,
|
|
170
|
-
headers: this.headers,
|
|
171
|
-
data: payload
|
|
172
|
-
});
|
|
169
|
+
await this.axiosInstance(path, { method: 'POST', data: payload });
|
|
173
170
|
this.updateData(deviceData);
|
|
174
171
|
return true;
|
|
175
172
|
case "melcloudhome":
|
|
@@ -195,7 +192,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
195
192
|
};
|
|
196
193
|
method = 'POST';
|
|
197
194
|
path = ApiUrlsHome.PostProtectionFrost;
|
|
198
|
-
this.headers.Referer = ApiUrlsHome.Referers.PostProtectionFrost.replace('deviceid', deviceData.DeviceID);
|
|
195
|
+
//this.headers.Referer = ApiUrlsHome.Referers.PostProtectionFrost.replace('deviceid', deviceData.DeviceID);
|
|
199
196
|
break;
|
|
200
197
|
case 'overheatprotection':
|
|
201
198
|
payload = {
|
|
@@ -206,7 +203,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
206
203
|
};
|
|
207
204
|
method = 'POST';
|
|
208
205
|
path = ApiUrlsHome.PostProtectionOverheat;
|
|
209
|
-
this.headers.Referer = ApiUrlsHome.Referers.PostProtectionOverheat.replace('deviceid', deviceData.DeviceID);
|
|
206
|
+
//this.headers.Referer = ApiUrlsHome.Referers.PostProtectionOverheat.replace('deviceid', deviceData.DeviceID);
|
|
210
207
|
break;
|
|
211
208
|
case 'holidaymode':
|
|
212
209
|
payload = {
|
|
@@ -217,19 +214,19 @@ class MelCloudAta extends EventEmitter {
|
|
|
217
214
|
};
|
|
218
215
|
method = 'POST';
|
|
219
216
|
path = ApiUrlsHome.PostHolidayMode;
|
|
220
|
-
this.headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
|
|
217
|
+
//this.headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
|
|
221
218
|
break;
|
|
222
219
|
case 'schedule':
|
|
223
220
|
payload = { enabled: deviceData.ScheduleEnabled };
|
|
224
221
|
method = 'PUT';
|
|
225
222
|
path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
226
|
-
this.headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
223
|
+
//this.headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
227
224
|
break;
|
|
228
225
|
case 'scene':
|
|
229
226
|
method = 'PUT';
|
|
230
227
|
const state = flagData.Enabled ? 'Enable' : 'Disable';
|
|
231
228
|
path = ApiUrlsHome.PutScene[state].replace('sceneid', flagData.Id);
|
|
232
|
-
this.headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
|
|
229
|
+
//this.headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
|
|
233
230
|
break;
|
|
234
231
|
default:
|
|
235
232
|
payload = {
|
|
@@ -244,20 +241,14 @@ class MelCloudAta extends EventEmitter {
|
|
|
244
241
|
};
|
|
245
242
|
method = 'PUT';
|
|
246
243
|
path = ApiUrlsHome.PutAta.replace('deviceid', deviceData.DeviceID);
|
|
247
|
-
this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
|
|
244
|
+
//this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
|
|
248
245
|
break
|
|
249
246
|
}
|
|
250
247
|
|
|
251
|
-
this.headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
252
|
-
this.headers.Origin = ApiUrlsHome.Origin;
|
|
248
|
+
//this.headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
249
|
+
//this.headers.Origin = ApiUrlsHome.Origin;
|
|
253
250
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
|
|
254
|
-
await
|
|
255
|
-
method: method,
|
|
256
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
257
|
-
timeout: 10000,
|
|
258
|
-
headers: this.headers,
|
|
259
|
-
data: payload
|
|
260
|
-
});
|
|
251
|
+
await this.axiosInstance(path, { method: method, data: payload });
|
|
261
252
|
this.updateData(deviceData);
|
|
262
253
|
return true;
|
|
263
254
|
default:
|
package/src/melcloudatw.js
CHANGED
|
@@ -23,7 +23,6 @@ class MelCloudAtw 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 = true;
|
|
@@ -53,12 +52,15 @@ class MelCloudAtw extends EventEmitter {
|
|
|
53
52
|
try {
|
|
54
53
|
//read device info from file
|
|
55
54
|
const devicesData = await this.functions.readData(this.devicesFile, true);
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
this.axiosInstance = axios.create({
|
|
56
|
+
baseURL: this.baseURL,
|
|
57
|
+
timeout: 30000,
|
|
58
|
+
headers: devicesData.Headers
|
|
59
|
+
});
|
|
59
60
|
|
|
61
|
+
const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
60
62
|
if (this.accountType === 'melcloudhome') {
|
|
61
|
-
deviceData.Scenes =
|
|
63
|
+
deviceData.Scenes = devicesData.Scenes ?? [];
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
const safeConfig = {
|
|
@@ -169,13 +171,7 @@ class MelCloudAtw extends EventEmitter {
|
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
|
|
172
|
-
await
|
|
173
|
-
method: 'POST',
|
|
174
|
-
baseURL: ApiUrls.BaseURL,
|
|
175
|
-
timeout: 10000,
|
|
176
|
-
headers: this.headers,
|
|
177
|
-
data: payload
|
|
178
|
-
});
|
|
174
|
+
await this.axiosInstance(path, { method: 'POST', data: payload });
|
|
179
175
|
this.updateData(deviceData);
|
|
180
176
|
return true;
|
|
181
177
|
case "melcloudhome":
|
|
@@ -221,20 +217,14 @@ class MelCloudAtw extends EventEmitter {
|
|
|
221
217
|
};
|
|
222
218
|
method = 'PUT';
|
|
223
219
|
path = ApiUrlsHome.PutAtw.replace('deviceid', deviceData.DeviceID);
|
|
224
|
-
this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
|
|
220
|
+
this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
|
|
225
221
|
break
|
|
226
222
|
}
|
|
227
223
|
|
|
228
224
|
this.headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
229
225
|
this.headers.Origin = ApiUrlsHome.Origin;
|
|
230
226
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
|
|
231
|
-
await
|
|
232
|
-
method: method,
|
|
233
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
234
|
-
timeout: 10000,
|
|
235
|
-
headers: this.headers,
|
|
236
|
-
data: payload
|
|
237
|
-
});
|
|
227
|
+
await this.axiosInstance(path, { method: method, data: payload });
|
|
238
228
|
this.updateData(deviceData);
|
|
239
229
|
return true;
|
|
240
230
|
default:
|
package/src/melclouderv.js
CHANGED
|
@@ -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 = true;
|
|
@@ -53,12 +52,15 @@ class MelCloudErv extends EventEmitter {
|
|
|
53
52
|
try {
|
|
54
53
|
//read device info from file
|
|
55
54
|
const devicesData = await this.functions.readData(this.devicesFile, true);
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
this.axiosInstance = axios.create({
|
|
56
|
+
baseURL: this.baseURL,
|
|
57
|
+
timeout: 30000,
|
|
58
|
+
headers: devicesData.Headers
|
|
59
|
+
});
|
|
59
60
|
|
|
61
|
+
const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
60
62
|
if (this.accountType === 'melcloudhome') {
|
|
61
|
-
deviceData.Scenes =
|
|
63
|
+
deviceData.Scenes = devicesData.Scenes ?? [];
|
|
62
64
|
|
|
63
65
|
//read default temps
|
|
64
66
|
const temps = await this.functions.readData(this.defaultTempsFile, true);
|
|
@@ -172,13 +174,7 @@ class MelCloudErv extends EventEmitter {
|
|
|
172
174
|
}
|
|
173
175
|
|
|
174
176
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
|
|
175
|
-
await
|
|
176
|
-
method: 'POST',
|
|
177
|
-
baseURL: ApiUrls.BaseURL,
|
|
178
|
-
timeout: 10000,
|
|
179
|
-
headers: this.headers,
|
|
180
|
-
data: payload
|
|
181
|
-
});
|
|
177
|
+
await this.axiosInstance(path, { method: 'POST', data: payload });
|
|
182
178
|
this.updateData(deviceData);
|
|
183
179
|
return true;
|
|
184
180
|
case "melcloudhome":
|
|
@@ -228,20 +224,14 @@ class MelCloudErv extends EventEmitter {
|
|
|
228
224
|
};
|
|
229
225
|
method = 'PUT';
|
|
230
226
|
path = ApiUrlsHome.PutErv.replace('deviceid', deviceData.DeviceID);
|
|
231
|
-
this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
|
|
227
|
+
this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
|
|
232
228
|
break
|
|
233
229
|
}
|
|
234
230
|
|
|
235
231
|
this.headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
236
232
|
this.headers.Origin = ApiUrlsHome.Origin;
|
|
237
233
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
|
|
238
|
-
await
|
|
239
|
-
method: method,
|
|
240
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
241
|
-
timeout: 10000,
|
|
242
|
-
headers: this.headers,
|
|
243
|
-
data: payload
|
|
244
|
-
});
|
|
234
|
+
await this.axiosInstance(path, { method: method, data: payload });
|
|
245
235
|
this.updateData(deviceData);
|
|
246
236
|
return true;
|
|
247
237
|
default:
|