homebridge-melcloud-control 4.0.0-beta.191 → 4.0.0-beta.193

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/index.js CHANGED
@@ -79,6 +79,7 @@ class MelCloudPlatform {
79
79
  const accountFile = `${prefDir}/${accountName}_Account`;
80
80
  const buildingsFile = `${prefDir}/${accountName}_Buildings`;
81
81
  const devicesFile = `${prefDir}/${accountName}_Devices`;
82
+ const defaultTempsFile = `${prefDir}/${accountName}_Temps`;
82
83
 
83
84
 
84
85
  //set account refresh interval
@@ -146,15 +147,15 @@ class MelCloudPlatform {
146
147
  let configuredDevice;
147
148
  switch (deviceType) {
148
149
  case 0: //ATA
149
- configuredDevice = new DeviceAta(api, account, device, devicesFile, useFahrenheit, restFul, mqtt);
150
+ configuredDevice = new DeviceAta(api, account, device, devicesFile, defaultTempsFile, useFahrenheit, restFul, mqtt);
150
151
  break;
151
152
  case 1: //ATW
152
- configuredDevice = new DeviceAtw(api, account, device, contextKey, devicesFile, useFahrenheit, restFul, mqtt);
153
+ configuredDevice = new DeviceAtw(api, account, device, contextKey, devicesFile, defaultTempsFile, useFahrenheit, restFul, mqtt);
153
154
  break;
154
155
  case 2:
155
156
  break;
156
157
  case 3: //ERV
157
- configuredDevice = new DeviceErv(api, account, device, contextKey, devicesFile, useFahrenheit, restFul, mqtt);
158
+ configuredDevice = new DeviceErv(api, account, device, contextKey, devicesFile, defaultTempsFile, useFahrenheit, restFul, mqtt);
158
159
  break;
159
160
  default:
160
161
  if (logLevel.warn) log.warn(`${accountName}, ${deviceTypeText}, ${deviceName}, unknown device: ${deviceType}.`);
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.191",
4
+ "version": "4.0.0-beta.193",
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
@@ -43,7 +43,7 @@ export const AirConditioner = {
43
43
  OperationModeMapEnumToString: { 0: "0", 1: "Heat", 2: "Dry", 3: "Cool", 4: "4", 5: "5", 6: "6", 7: "Fan", 8: "Automatic", 9: "Isee Heat", 10: "Isee Dry", 11: "Isee Cool" },
44
44
  FanSpeedMapStringToEnum: { "Auto": 0, "One": 1, "Two": 2, "Three": 3, "Four": 4, "Five": 5 },
45
45
  FanSpeedMapEnumToString: { 0: "Auto", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five" },
46
- FanSpeedCurrentMapEnumToString: { 0: "Zero", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five" },
46
+ FanSpeedCurrentMapEnumToString: { 0: "Quiet", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five" },
47
47
  VaneVerticalDirectionMapStringToEnum: { "Auto": 0, "One": 1, "Two": 2, "Three": 3, "Four": 4, "Five": 5, "Six": 6, "Swing": 7 },
48
48
  VaneVerticalDirectionMapEnumToString: { 0: "Auto", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Swing" },
49
49
  VaneHorizontalDirectionMapStringToEnum: { "Auto": 0, "Left": 1, "LeftCentre": 2, "Centre": 3, "RightCentre": 4, "Right": 5, "Six": 6, "Seven": 7, "Split": 8, "Nine": 9, "Ten": 10, "Eleven": 11, "Swing": 12 },
package/src/deviceata.js CHANGED
@@ -6,7 +6,7 @@ import { TemperatureDisplayUnits, AirConditioner, ApiUrlsHome } from './constant
6
6
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
7
7
 
8
8
  class DeviceAta extends EventEmitter {
9
- constructor(api, account, device, devicesFile, useFahrenheit, restFul, mqtt) {
9
+ constructor(api, account, device, devicesFile, defaultTempsFile, useFahrenheit, restFul, mqtt) {
10
10
  super();
11
11
 
12
12
  Accessory = api.platformAccessory;
@@ -36,6 +36,7 @@ class DeviceAta extends EventEmitter {
36
36
  this.deviceName = device.name;
37
37
  this.deviceTypeText = device.typeString;
38
38
  this.devicesFile = devicesFile;
39
+ this.defaultTempsFile = defaultTempsFile;
39
40
  this.displayDeviceInfo = true;
40
41
 
41
42
  //external integrations
@@ -922,7 +923,7 @@ class DeviceAta extends EventEmitter {
922
923
  async start() {
923
924
  try {
924
925
  //melcloud device
925
- this.melCloudAta = new MelCloudAta(this.account, this.device, this.devicesFile)
926
+ this.melCloudAta = new MelCloudAta(this.account, this.device, this.devicesFile, this.defaultTempsFile)
926
927
  .on('deviceInfo', (manufacturer, modelIndoor, modelOutdoor, serialNumber, firmwareAppVersion) => {
927
928
  if (this.logDeviceInfo && this.displayDeviceInfo) {
928
929
  this.emit('devInfo', `---- ${this.deviceTypeText}: ${this.deviceName} ----`);
package/src/deviceatw.js CHANGED
@@ -6,7 +6,7 @@ import { TemperatureDisplayUnits, HeatPump } from './constants.js';
6
6
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
7
7
 
8
8
  class DeviceAtw extends EventEmitter {
9
- constructor(api, account, device, contextKey, devicesFile, useFahrenheit, restFul, mqtt) {
9
+ constructor(api, account, device, contextKey, devicesFile, defaultTempsFile, useFahrenheit, restFul, mqtt) {
10
10
  super();
11
11
 
12
12
  Accessory = api.platformAccessory;
@@ -41,6 +41,7 @@ class DeviceAtw extends EventEmitter {
41
41
  this.deviceName = device.name;
42
42
  this.deviceTypeText = device.typeString;
43
43
  this.devicesFile = devicesFile;
44
+ this.defaultTempsFile = defaultTempsFile;
44
45
  this.displayDeviceInfo = true;
45
46
 
46
47
  //external integrations
@@ -1285,7 +1286,7 @@ class DeviceAtw extends EventEmitter {
1285
1286
  async start() {
1286
1287
  try {
1287
1288
  //melcloud device
1288
- this.melCloudAtw = new MelCloudAtw(this.device, this.contextKey, this.devicesFile)
1289
+ this.melCloudAtw = new MelCloudAtw(this.device, this.contextKey, this.devicesFile, this.defaultTempsFile)
1289
1290
  .on('deviceInfo', (manufacturer, modelIndoor, modelOutdoor, serialNumber, firmwareAppVersion, hasHotWaterTank, hasZone2) => {
1290
1291
  if (this.logDeviceInfo && this.displayDeviceInfo) {
1291
1292
  this.emit('devInfo', `---- ${this.deviceTypeText}: ${this.deviceName} ----`);
package/src/deviceerv.js CHANGED
@@ -6,7 +6,7 @@ import { TemperatureDisplayUnits, Ventilation } from './constants.js';
6
6
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
7
7
 
8
8
  class DeviceErv extends EventEmitter {
9
- constructor(api, account, device, contextKey, devicesFile, useFahrenheit, restFul, mqtt) {
9
+ constructor(api, account, device, contextKey, devicesFile, defaultTempsFile, useFahrenheit, restFul, mqtt) {
10
10
  super();
11
11
 
12
12
  Accessory = api.platformAccessory;
@@ -34,6 +34,7 @@ class DeviceErv extends EventEmitter {
34
34
  this.deviceName = device.name;
35
35
  this.deviceTypeText = device.typeString;
36
36
  this.devicesFile = devicesFile;
37
+ this.defaultTempsFile = defaultTempsFile;
37
38
  this.displayDeviceInfo = true;
38
39
 
39
40
  //external integrations
@@ -840,7 +841,7 @@ class DeviceErv extends EventEmitter {
840
841
  async start() {
841
842
  try {
842
843
  //melcloud device
843
- this.melCloudErv = new MelCloudErv(this.device, this.contextKey, this.devicesFile)
844
+ this.melCloudErv = new MelCloudErv(this.device, this.contextKey, this.devicesFile, this.defaultTempsFile)
844
845
  .on('deviceInfo', (manufacturer, modelIndoor, modelOutdoor, serialNumber, firmwareAppVersion) => {
845
846
  if (this.logDeviceInfo && this.displayDeviceInfo) {
846
847
  this.emit('devInfo', `---- ${this.deviceTypeText}: ${this.deviceName} ----`);
package/src/functions.js CHANGED
@@ -14,11 +14,15 @@ class Functions {
14
14
  }
15
15
  }
16
16
 
17
- async readData(path) {
17
+ async readData(path, parseJson = false) {
18
18
  try {
19
- const data = await fsPromises.readFile(path);
20
- return data;
19
+ const data = await fsPromises.readFile(path, 'utf8');
20
+ return parseJson ? JSON.parse(data) : data;
21
21
  } catch (error) {
22
+ if (error.code === 'ENOENT') {
23
+ // File does not exist
24
+ return null;
25
+ }
22
26
  throw new Error(`Read data error: ${error}`);
23
27
  }
24
28
  }
@@ -5,16 +5,15 @@ import Functions from './functions.js';
5
5
  import { ApiUrls, ApiUrlsHome, AirConditioner } from './constants.js';
6
6
 
7
7
  class MelCloudAta extends EventEmitter {
8
- constructor(account, device, devicesFile) {
8
+ constructor(account, device, devicesFile, defaultTempsFile) {
9
9
  super();
10
10
  this.accountType = account.displayType
11
11
  this.deviceId = device.id;
12
12
  this.logWarn = device.log?.warn;
13
13
  this.logDebug = device.log?.debug;
14
14
  this.devicesFile = devicesFile;
15
+ this.defaultTempsFile = defaultTempsFile;
15
16
  this.functions = new Functions();
16
- this.defaultHeatingSetTemperature = 20;
17
- this.defaultCoolingSetTemperature = 23;
18
17
 
19
18
  //set default values
20
19
  this.deviceState = {};
@@ -47,9 +46,11 @@ class MelCloudAta extends EventEmitter {
47
46
 
48
47
  async checkState() {
49
48
  try {
49
+ //read default temps
50
+ const temps = await this.functions.readData(this.defaultTempsFile, true);
51
+
50
52
  //read device info from file
51
- const data = await this.functions.readData(this.devicesFile);
52
- const devicesData = JSON.parse(data);
53
+ const devicesData = await this.functions.readData(this.devicesFile, true);
53
54
 
54
55
  if (!Array.isArray(devicesData)) {
55
56
  if (this.logWarn) this.emit('warn', `Device data not found`);
@@ -63,8 +64,8 @@ class MelCloudAta extends EventEmitter {
63
64
  deviceData.Device.SetFanSpeed = AirConditioner.FanSpeedMapStringToEnum[deviceData.Device.SetFanSpeed] ?? deviceData.Device.SetFanSpeed;
64
65
  deviceData.Device.VaneVerticalDirection = AirConditioner.VaneVerticalDirectionMapStringToEnum[deviceData.Device.VaneVerticalDirection] ?? deviceData.Device.VaneVerticalDirection;
65
66
  deviceData.Device.VaneHorizontalDirection = AirConditioner.VaneHorizontalDirectionMapStringToEnum[deviceData.Device.VaneHorizontalDirection] ?? deviceData.Device.VaneHorizontalDirection;
66
- deviceData.Device.DefaultHeatingSetTemperature = this.defaultHeatingSetTemperature;
67
- deviceData.Device.DefaultCoolingSetTemperature = this.defaultCoolingSetTemperature;
67
+ deviceData.Device.DefaultHeatingSetTemperature = temps?.defaultHeatingSetTemperature ?? 20;
68
+ deviceData.Device.DefaultCoolingSetTemperature = temps?.defaultCoolingSetTemperature ?? 24;
68
69
  deviceData.Device.FirmwareAppVersion = '4.0.0';
69
70
  }
70
71
  if (this.logDebug) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
@@ -238,7 +239,7 @@ class MelCloudAta extends EventEmitter {
238
239
  HasPendingCommand: true
239
240
  }
240
241
  };
241
- if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(settings.data, null, 2)}`);
242
+ if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload.data, null, 2)}`);
242
243
 
243
244
  await axiosInstancePost(ApiUrls.SetAta, payload);
244
245
  this.emit('deviceState', deviceData);
@@ -282,13 +283,21 @@ class MelCloudAta extends EventEmitter {
282
283
  break;
283
284
  case 8: //AUTO
284
285
  deviceData.Device.SetTemperature = (deviceData.Device.DefaultCoolingSetTemperature + deviceData.Device.DefaultHeatingSetTemperature) / 2;
285
- this.defaultCoolingSetTemperature = deviceData.Device.DefaultCoolingSetTemperature;
286
- this.defaultHeatingSetTemperature = deviceData.Device.DefaultHeatingSetTemperature;
287
286
  break;
288
287
  default:
289
288
  if (this.logWarn) this.emit('warn', `Unknown operation mode: ${deviceData.Device.OperationMode}`);
290
289
  return;
291
290
  };
291
+
292
+ if (this.deviceState.DefaultCoolingSetTemperature !== deviceData.Device.DefaultCoolingSetTemperature || this.deviceState.DefaultHeatingSetTemperature !== deviceData.Device.DefaultHeatingSetTemperature) {
293
+ const temps = {
294
+ defaultCoolingSetTemperature: deviceData.Device.DefaultCoolingSetTemperature,
295
+ defaultHeatingSetTemperature: deviceData.Device.DefaultHeatingSetTemperature
296
+ };
297
+ await this.functions.saveData(this.defaultTempsFile, temps);
298
+ }
299
+
300
+ break
292
301
  case 2: //Thermostat
293
302
  deviceData.Device.SetTemperature = deviceData.Device.SetTemperature;
294
303
  break;
@@ -6,12 +6,13 @@ import Functions from './functions.js';
6
6
  import { ApiUrls } from './constants.js';
7
7
 
8
8
  class MelCloudAtw extends EventEmitter {
9
- constructor(device, contextKey, devicesFile) {
9
+ constructor(device, contextKey, devicesFile, defaultTempsFile) {
10
10
  super();
11
11
  this.deviceId = device.id;
12
12
  this.logWarn = device.log?.warn;
13
13
  this.logDebug = device.log?.debug;
14
14
  this.devicesFile = devicesFile;
15
+ this.defaultTempsFile = defaultTempsFile;
15
16
  this.functions = new Functions();
16
17
 
17
18
  //set default values
@@ -61,8 +62,7 @@ class MelCloudAtw extends EventEmitter {
61
62
  async checkState() {
62
63
  try {
63
64
  //read device info from file
64
- const data = await this.functions.readData(this.devicesFile);
65
- const devicesData = JSON.parse(data);
65
+ const devicesData = await this.functions.readData(this.devicesFile, true);
66
66
 
67
67
  if (!Array.isArray(devicesData)) {
68
68
  if (this.logWarn) this.emit('warn', `Device data not found`);
@@ -6,12 +6,13 @@ import Functions from './functions.js';
6
6
  import { ApiUrls } from './constants.js';
7
7
 
8
8
  class MelCloudErv extends EventEmitter {
9
- constructor(device, contextKey, devicesFile) {
9
+ constructor(device, contextKey, devicesFile, defaultTempsFile) {
10
10
  super();
11
11
  this.deviceId = device.id;
12
12
  this.logWarn = device.log?.warn;
13
13
  this.logDebug = device.log?.debug;
14
14
  this.devicesFile = devicesFile;
15
+ this.defaultTempsFile = defaultTempsFile;
15
16
  this.functions = new Functions();
16
17
 
17
18
  //set default values
@@ -61,8 +62,7 @@ class MelCloudErv extends EventEmitter {
61
62
  async checkState() {
62
63
  try {
63
64
  //read device info from file
64
- const data = await this.functions.readData(this.devicesFile);
65
- const devicesData = JSON.parse(data);
65
+ const devicesData = await this.functions.readData(this.devicesFile, true);
66
66
 
67
67
  if (!Array.isArray(devicesData)) {
68
68
  if (this.logWarn) this.emit('warn', `Device data not found`);