homebridge-melcloud-control 3.1.4-beta.1 → 3.1.4-beta.11

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.
@@ -173,7 +173,7 @@
173
173
 
174
174
  //get devices from melcloud by type
175
175
  for (const deviceInMelcloud of devicesInMelCloud) {
176
- const deviceType = device.Type;
176
+ const deviceType = devicesInMelCloud.Type;
177
177
  const pusDeviceTypeAta = deviceType === 0 ? devicesByTypeInMelCloud.ata.push(deviceInMelcloud) : false;
178
178
  const pusDeviceTypeAtw = deviceType === 1 ? devicesByTypeInMelCloud.atw.push(deviceInMelcloud) : false;
179
179
  const pusDeviceTypeErv = deviceType === 3 ? devicesByTypeInMelCloud.erv.push(deviceInMelcloud) : false;
package/index.js CHANGED
@@ -55,9 +55,9 @@ class MelCloudPlatform {
55
55
 
56
56
  //define directory and file paths
57
57
  const prefDir = path.join(api.user.storagePath(), 'melcloud');
58
- const accountInfoFile = `${prefDir}/${accountName}_Account`;
58
+ const accountFile = `${prefDir}/${accountName}_Account`;
59
59
  const buildingsFile = `${prefDir}/${accountName}_Buildings`;
60
- const deviceFile = `${prefDir}/${accountName}_Device_`;
60
+ const devicesFile = `${prefDir}/${accountName}_Devices`;
61
61
 
62
62
  //create directory if it doesn't exist
63
63
  try {
@@ -74,7 +74,7 @@ class MelCloudPlatform {
74
74
 
75
75
  try {
76
76
  //melcloud account
77
- const melCloud = new MelCloud(user, passwd, language, accountInfoFile, buildingsFile, deviceFile, enableDebugMode, false);
77
+ const melCloud = new MelCloud(user, passwd, language, accountFile, buildingsFile, devicesFile, enableDebugMode, false);
78
78
  melCloud.on('success', (message) => {
79
79
  log.success(`Account ${accountName}, ${message}`);
80
80
  })
@@ -106,16 +106,15 @@ class MelCloudPlatform {
106
106
  //Air Conditioner 0
107
107
  for (const device of account.ataDevices) {
108
108
  //chack device from config exist on melcloud
109
- const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === device.id);
109
+ const deviceId = device.id;
110
+ const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === deviceId);
110
111
  if (!deviceExistInMelCloud || device.displayMode === 0) {
111
112
  continue;
112
113
  };
113
114
 
114
- const deviceId = device.id.toString();
115
115
  const deviceName = device.name;
116
116
  const deviceTypeText = device.typeString;
117
- const deviceInfoFile = `${prefDir}/${accountName}_Device_${deviceId}`;
118
- const airConditioner = new DeviceAta(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, deviceRefreshInterval)
117
+ const airConditioner = new DeviceAta(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, deviceRefreshInterval)
119
118
  airConditioner.on('publishAccessory', (accessory) => {
120
119
 
121
120
  //publish device
@@ -145,16 +144,15 @@ class MelCloudPlatform {
145
144
  //Heat Pump 1
146
145
  for (const device of account.atwDevices) {
147
146
  //chack device from config exist on melcloud
147
+ const deviceId = device.id;
148
148
  const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === device.id);
149
149
  if (!deviceExistInMelCloud || device.displayMode === 0) {
150
150
  continue;
151
151
  };
152
152
 
153
- const deviceId = device.id.toString();
154
153
  const deviceName = device.name;
155
154
  const deviceTypeText = device.typeString;
156
- const deviceInfoFile = `${prefDir}/${accountName}_Device_${deviceId}`;
157
- const heatPump = new DeviceAtw(api, account, melCloud, device, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, deviceRefreshInterval)
155
+ const heatPump = new DeviceAtw(api, account, melCloud, device, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, deviceRefreshInterval)
158
156
  heatPump.on('publishAccessory', (accessory) => {
159
157
 
160
158
  //publish device
@@ -184,16 +182,15 @@ class MelCloudPlatform {
184
182
  //Energy Recovery Ventilation 3
185
183
  for (const device of account.ervDevices) {
186
184
  //chack device from config exist on melcloud
185
+ const deviceId = device.id;
187
186
  const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === device.id);
188
187
  if (!deviceExistInMelCloud || device.displayMode === 0) {
189
188
  continue;
190
189
  };
191
190
 
192
- const deviceId = device.id.toString();
193
191
  const deviceName = device.name;
194
192
  const deviceTypeText = device.typeString;
195
- const deviceInfoFile = `${prefDir}/${accountName}_Device_${deviceId}`;
196
- const energyRecoveryVentilation = new DeviceErv(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, deviceRefreshInterval)
193
+ const energyRecoveryVentilation = new DeviceErv(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, deviceRefreshInterval)
197
194
  energyRecoveryVentilation.on('publishAccessory', (accessory) => {
198
195
 
199
196
  //publish device
@@ -220,7 +217,7 @@ class MelCloudPlatform {
220
217
  });
221
218
  };
222
219
  } catch (error) {
223
- log.error(`Account: ${accountName}, MELCloud error: ${error.message ?? error}`);
220
+ log.error(`Account: ${accountName}, Did finish launching error: ${error.message ?? error}`);
224
221
  }
225
222
  };
226
223
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "3.1.4-beta.1",
4
+ "version": "3.1.4-beta.11",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "engines": {
31
31
  "homebridge": "^1.6.0 || ^2.0.0-beta.0",
32
- "node": "^18.20.4 || ^20.15.1, || ^22.7.0"
32
+ "node": "^18.20.4 || ^20.15.1 || ^22.7.0"
33
33
  },
34
34
  "dependencies": {
35
35
  "@homebridge/plugin-ui-utils": "^1.0.3",
package/src/deviceata.js CHANGED
@@ -7,7 +7,7 @@ const CONSTANTS = require('./constants.json');
7
7
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
8
8
 
9
9
  class DeviceAta extends EventEmitter {
10
- constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, refreshInterval) {
10
+ constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, refreshInterval) {
11
11
  super();
12
12
 
13
13
  Accessory = api.platformAccessory;
@@ -94,8 +94,9 @@ class DeviceAta extends EventEmitter {
94
94
  //melcloud device
95
95
  this.melCloudAta = new MelCloudAta({
96
96
  contextKey: contextKey,
97
- accountInfoFile: accountInfoFile,
98
- deviceInfoFile: deviceInfoFile,
97
+ accountFile: accountFile,
98
+ devicesFile: devicesFile,
99
+ deviceId: deviceId,
99
100
  debugLog: account.enableDebugMode,
100
101
  refreshInterval: refreshInterval
101
102
  });
@@ -192,7 +193,6 @@ class DeviceAta extends EventEmitter {
192
193
  .on('deviceState', async (deviceData, deviceState, useFahrenheit) => {
193
194
  //device info
194
195
  const displayMode = this.displayMode;
195
- const inStandbyMode = deviceData.Device.InStandbyMode;
196
196
  const hasAutomaticFanSpeed = deviceData.Device.HasAutomaticFanSpeed ?? false;
197
197
  const airDirectionFunction = deviceData.Device.AirDirectionFunction ?? false;
198
198
  const hasOutdoorTemperature = deviceData.Device.HasOutdoorTemperature ?? false;
@@ -213,6 +213,9 @@ class DeviceAta extends EventEmitter {
213
213
  const presetsOnServer = deviceData.Presets ?? [];
214
214
 
215
215
  //device state
216
+ const power = deviceState.Power;
217
+ const offline = deviceState.Offline;
218
+ const inStandbyMode = deviceState.InStandbyMode;
216
219
  const roomTemperature = deviceState.RoomTemperature;
217
220
  const setTemperature = deviceState.SetTemperature;
218
221
  const setFanSpeed = deviceState.SetFanSpeed;
@@ -224,8 +227,6 @@ class DeviceAta extends EventEmitter {
224
227
  const prohibitSetTemperature = deviceState.ProhibitSetTemperature;
225
228
  const prohibitOperationMode = deviceState.ProhibitOperationMode;
226
229
  const prohibitPower = deviceState.ProhibitPower;
227
- const power = deviceState.Power;
228
- const offline = deviceState.Offline;
229
230
 
230
231
  //accessory
231
232
  this.accessory.presetsOnServer = presetsOnServer;
@@ -745,7 +746,7 @@ class DeviceAta extends EventEmitter {
745
746
  })
746
747
  .onSet(async (state) => {
747
748
  try {
748
- deviceState.Power = state;
749
+ deviceState.Power = [false, true][state];
749
750
  deviceState.EffectiveFlags = CONSTANTS.AirConditioner.EffectiveFlags.Power;
750
751
  await this.melCloudAta.send(deviceState);
751
752
  const info = this.disableLogInfo ? false : this.emit('message', `Set power: ${state ? 'ON' : 'OFF'}`);
package/src/deviceatw.js CHANGED
@@ -7,7 +7,7 @@ const CONSTANTS = require('./constants.json');
7
7
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
8
8
 
9
9
  class DeviceAtw extends EventEmitter {
10
- constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, refreshInterval) {
10
+ constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, refreshInterval) {
11
11
  super();
12
12
 
13
13
  Accessory = api.platformAccessory;
@@ -90,8 +90,9 @@ class DeviceAtw extends EventEmitter {
90
90
  //melcloud device
91
91
  this.melCloudAtw = new MelCloudAtw({
92
92
  contextKey: contextKey,
93
- accountInfoFile: accountInfoFile,
94
- deviceInfoFile: deviceInfoFile,
93
+ accountFile: accountFile,
94
+ devicesFile: devicesFile,
95
+ deviceId: deviceId,
95
96
  debugLog: account.enableDebugMode,
96
97
  refreshInterval: refreshInterval
97
98
  });
@@ -874,7 +875,7 @@ class DeviceAtw extends EventEmitter {
874
875
  try {
875
876
  switch (i) {
876
877
  case 0: //Heat Pump
877
- deviceState.Power = state;
878
+ deviceState.Power = [false, true][state];
878
879
  deviceState.EffectiveFlags = CONSTANTS.HeatPump.EffectiveFlags.Power;
879
880
  await this.melCloudAtw.send(deviceState);
880
881
  const info = this.disableLogInfo ? false : this.emit('message', `${zoneName}, Set power: ${state ? 'ON' : 'OFF'}`);
package/src/deviceerv.js CHANGED
@@ -7,7 +7,7 @@ const CONSTANTS = require('./constants.json');
7
7
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
8
8
 
9
9
  class DeviceErv extends EventEmitter {
10
- constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, refreshInterval) {
10
+ constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, refreshInterval) {
11
11
  super();
12
12
 
13
13
  Accessory = api.platformAccessory;
@@ -93,8 +93,9 @@ class DeviceErv extends EventEmitter {
93
93
  //melcloud device
94
94
  this.melCloudErv = new MelCloudErv({
95
95
  contextKey: contextKey,
96
- accountInfoFile: accountInfoFile,
97
- deviceInfoFile: deviceInfoFile,
96
+ accountFile: accountFile,
97
+ devicesFile: devicesFile,
98
+ deviceId: deviceId,
98
99
  debugLog: account.enableDebugMode,
99
100
  refreshInterval: refreshInterval
100
101
  });
@@ -684,7 +685,7 @@ class DeviceErv extends EventEmitter {
684
685
  })
685
686
  .onSet(async (state) => {
686
687
  try {
687
- deviceState.Power = state;
688
+ deviceState.Power = [false, true][state];
688
689
  deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
689
690
  await this.melCloudErv.send(deviceState);
690
691
  const info = this.disableLogInfo ? false : this.emit('message', `Set power: ${state ? 'ON' : 'OFF'}`);
package/src/melcloud.js CHANGED
@@ -8,14 +8,15 @@ const ImpulseGenerator = require('./impulsegenerator.js');
8
8
  const CONSTANTS = require('./constants.json');
9
9
 
10
10
  class MelCloud extends EventEmitter {
11
- constructor(user, passwd, language, accountInfoFile, buildingsFile, deviceFile, enableDebugMode, requestConfig) {
11
+ constructor(user, passwd, language, accountFile, buildingsFile, devicesFile, enableDebugMode, requestConfig) {
12
12
  super();
13
- this.accountInfoFile = accountInfoFile;
13
+ this.accountFile = accountFile;
14
14
  this.buildingsFile = buildingsFile;
15
- this.deviceFile = deviceFile;
15
+ this.devicesFile = devicesFile;
16
16
  this.enableDebugMode = enableDebugMode;
17
17
  this.requestConfig = requestConfig;
18
18
  this.contextKey = '';
19
+ this.useFahrenheit = 0;
19
20
  this.devicesId = [];
20
21
 
21
22
  this.options = {
@@ -62,6 +63,7 @@ class MelCloud extends EventEmitter {
62
63
  const account = accountData.data;
63
64
  const accountInfo = account.LoginData;
64
65
  const contextKey = accountInfo.ContextKey;
66
+ this.useFahrenheit = accountInfo.UseFahrenheit
65
67
  this.contextKey = contextKey;
66
68
 
67
69
  //remove sensitive data
@@ -82,7 +84,7 @@ class MelCloud extends EventEmitter {
82
84
  };
83
85
 
84
86
  //save melcloud info to the file
85
- await this.saveData(this.accountInfoFile, accountInfo);
87
+ await this.saveData(this.accountFile, accountInfo);
86
88
 
87
89
  //emit connect success
88
90
  this.emit('success', `Connect to MELCloud Success.`)
@@ -152,18 +154,10 @@ class MelCloud extends EventEmitter {
152
154
  this.emit('warn', `No devices found.`);
153
155
  return;
154
156
  }
155
- const debug3 = this.enableDebugMode ? this.emit('debug', `Found: ${devicesCount} devices.`) : false;
156
-
157
- //get device info fom devices
158
- for (const deviceInfo of devices) {
159
- const deviceId = deviceInfo.DeviceID
160
- const deviceName = deviceInfo.DeviceName;
161
157
 
162
- //save every device info to the file
163
- const deviceFile = `${this.deviceFile}${deviceId}`;
164
- await this.saveData(deviceFile, deviceInfo);
165
- const debug = this.enableDebugMode ? this.emit('debug', `Device: ${deviceName} info saved.`) : false;
166
- };
158
+ //save buildings to the file
159
+ await this.saveData(this.devicesFile, devices);
160
+ const debug3 = this.enableDebugMode ? this.emit('debug', `${devicesCount} devices saved.`) : false;
167
161
 
168
162
  return devices;
169
163
  } catch (error) {
@@ -11,8 +11,9 @@ class MelCloudAta extends EventEmitter {
11
11
  constructor(config) {
12
12
  super();
13
13
  const contextKey = config.contextKey;
14
- const accountInfoFile = config.accountInfoFile;
15
- const deviceInfoFile = config.deviceInfoFile;
14
+ const accountFile = config.accountFile;
15
+ const devicesFile = config.devicesFile;
16
+ const deviceId = config.deviceId;
16
17
  const debugLog = config.debugLog;
17
18
  const refreshInterval = config.refreshInterval;
18
19
 
@@ -39,7 +40,7 @@ class MelCloudAta extends EventEmitter {
39
40
  impulseGenerator.on('checkDevice', async () => {
40
41
  try {
41
42
  //read account info from file
42
- const accountInfo = await this.readData(accountInfoFile);
43
+ const accountInfo = await this.readData(accountFile);
43
44
 
44
45
  //remove sensitive data
45
46
  const debugData = {
@@ -56,8 +57,9 @@ class MelCloudAta extends EventEmitter {
56
57
  this.useFahrenheit = useFahrenheit;
57
58
 
58
59
  //read device info from file
59
- const deviceData = await this.readData(deviceInfoFile);
60
- const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(deviceData, null, 2)}`) : false;
60
+ const devicesData = await this.readData(devicesFile);
61
+ const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(devicesData, null, 2)}`) : false;
62
+ const deviceData = devicesData.find((device) => device.DeviceID === deviceId);
61
63
 
62
64
  if (!deviceData) {
63
65
  this.emit('warn', `Device data not found.`);
@@ -65,7 +67,6 @@ class MelCloudAta extends EventEmitter {
65
67
  }
66
68
 
67
69
  //device info
68
- const deviceId = deviceData.DeviceID.toString();
69
70
  const deviceName = deviceData.DeviceName;
70
71
  const buildingId = deviceData.BuildingID;
71
72
  const buildingName = deviceData.BuildingName;
@@ -413,7 +414,7 @@ class MelCloudAta extends EventEmitter {
413
414
 
414
415
  await this.axiosInstancePost(CONSTANTS.ApiUrls.SetAta, options);
415
416
  this.emit('deviceState', this.deviceData, deviceState, this.useFahrenheit);
416
- return true;;
417
+ return true;
417
418
  } catch (error) {
418
419
  throw new Error(error.message ?? error);
419
420
  };
@@ -11,8 +11,9 @@ class MelCloudAtw extends EventEmitter {
11
11
  constructor(config) {
12
12
  super();
13
13
  const contextKey = config.contextKey;
14
- const accountInfoFile = config.accountInfoFile;
15
- const deviceInfoFile = config.deviceInfoFile;
14
+ const accountFile = config.accountFile;
15
+ const devicesFile = config.devicesFile;
16
+ const deviceId = config.deviceId;
16
17
  const debugLog = config.debugLog;
17
18
  const refreshInterval = config.refreshInterval;
18
19
 
@@ -39,7 +40,7 @@ class MelCloudAtw extends EventEmitter {
39
40
  impulseGenerator.on('checkDevice', async () => {
40
41
  try {
41
42
  //read account info from file
42
- const accountInfo = await this.readData(accountInfoFile);
43
+ const accountInfo = await this.readData(accountFile);
43
44
 
44
45
  //remove sensitive data
45
46
  const debugData = {
@@ -56,8 +57,9 @@ class MelCloudAtw extends EventEmitter {
56
57
  this.useFahrenheit = useFahrenheit;
57
58
 
58
59
  //read device info from file
59
- const deviceData = await this.readData(deviceInfoFile);
60
- const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(deviceData, null, 2)}`) : false;
60
+ const devicesData = await this.readData(devicesFile);
61
+ const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(devicesData, null, 2)}`) : false;
62
+ const deviceData = devicesData.find((device) => device.DeviceID === deviceId);
61
63
 
62
64
  if (!deviceData) {
63
65
  this.emit('warn', `Device data not found.`);
@@ -65,7 +67,6 @@ class MelCloudAtw extends EventEmitter {
65
67
  }
66
68
 
67
69
  //device info
68
- const deviceId = deviceData.DeviceID.toString();
69
70
  const deviceName = deviceData.DeviceName;
70
71
  const buildingId = deviceData.BuildingID;
71
72
  const buildingName = deviceData.BuildingName;
@@ -11,8 +11,9 @@ class MelCloudErv extends EventEmitter {
11
11
  constructor(config) {
12
12
  super();
13
13
  const contextKey = config.contextKey;
14
- const accountInfoFile = config.accountInfoFile;
15
- const deviceInfoFile = config.deviceInfoFile;
14
+ const accountFile = config.accountFile;
15
+ const devicesFile = config.devicesFile;
16
+ const deviceId = config.deviceId;
16
17
  const debugLog = config.debugLog;
17
18
  const refreshInterval = config.refreshInterval;
18
19
 
@@ -39,7 +40,7 @@ class MelCloudErv extends EventEmitter {
39
40
  impulseGenerator.on('checkDevice', async () => {
40
41
  try {
41
42
  //read account info from file
42
- const accountInfo = await this.readData(accountInfoFile);
43
+ const accountInfo = await this.readData(accountFile);
43
44
 
44
45
  //remove sensitive data
45
46
  const debugData = {
@@ -56,8 +57,9 @@ class MelCloudErv extends EventEmitter {
56
57
  this.useFahrenheit = useFahrenheit;
57
58
 
58
59
  //read device info from file
59
- const deviceData = await this.readData(deviceInfoFile);
60
- const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(deviceData, null, 2)}`) : false;
60
+ const devicesData = await this.readData(devicesFile);
61
+ const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(devicesData, null, 2)}`) : false;
62
+ const deviceData = devicesData.find((device) => device.DeviceID === deviceId);
61
63
 
62
64
  if (!deviceData) {
63
65
  this.emit('warn', `Device data not found.`);
@@ -65,7 +67,6 @@ class MelCloudErv extends EventEmitter {
65
67
  }
66
68
 
67
69
  //deviceData
68
- const deviceId = deviceData.DeviceID.toString();
69
70
  const deviceName = deviceData.DeviceName;
70
71
  const buildingId = deviceData.BuildingID;
71
72
  const buildingName = deviceData.BuildingName;