homebridge-melcloud-control 4.0.0-beta.205 → 4.0.0-beta.207

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 CHANGED
@@ -207,13 +207,13 @@ Homebridge plugin for Air Conditioner, Heat Pump and Energy Recovery Ventilation
207
207
  | `user` | Here set the account username. |
208
208
  | `passwd` | Here set the account password. |
209
209
  | `language` | Here select the account language. |
210
- | `accountType` | Here select the account type `None/Disabled`, `MELCloud`, `MELCloud Home`. |
210
+ | `type` | Here select the account type `None/Disabled`, `MELCloud`, `MELCloud Home`. |
211
211
  | `ataDevices[]` | Array of ATA devices created automatically after login to MELCloud from plugin config UI. |
212
212
  | `ataDevices[].id` | Read only data, do not change it. |
213
213
  | `ataDevices[].type` | Read only data, do not change it. |
214
214
  | `ataDevices[].typeString` | Read only data, do not change it. |
215
215
  | `ataDevices[].name` | Here You can schange the `Accessory Name` which is exposed to the `Homebridge/HomeKit`. |
216
- | `ataDevices[].displayMode` | Here select device control mode `None/Disabled`, `Heater/Cooler`, `Thermostat`. |
216
+ | `ataDevices[].displayType` | Here select device control mode `None/Disabled`, `Heater/Cooler`, `Thermostat`. |
217
217
  | `ataDevices[].heatDryFanMode` | Here select the operatiing mode for `Heat`, if this mode is not supported, it will be disabled. |
218
218
  | `ataDevices[].coolDryFanMode` | Here select the operatiing mode for `Cool`, if this mode is not supported, it will be disabled. |
219
219
  | `ataDevices[].autoDryFanMode` | Here select the operatiing mode for `Auto`, if this mode is not supported, it will be disabled.. |
@@ -234,7 +234,7 @@ Homebridge plugin for Air Conditioner, Heat Pump and Energy Recovery Ventilation
234
234
  | `atwDevices[].type` | Read only data, do not change it. |
235
235
  | `atwDevices[].typeString` | Read only data, do not change it. |
236
236
  | `atwDevices[].name` | Here You can schange the `Accessory Name` which is exposed to the `Homebridge/HomeKit`. |
237
- | `atwDevices[].displayMode` | Here select main control mode `None/Disabled`, `Heater/Cooler`, `Thermostat`. |
237
+ | `atwDevices[].displayType` | Here select main control mode `None/Disabled`, `Heater/Cooler`, `Thermostat`. |
238
238
  | `atwDevices[].hideZone` | Here select which zone need to be hidden `None/Disabled`, `Heat Pump`, `Heat Pump / Zone 1`, `Heat Pump / Zone 1 / Hot Water`, `Heat Pump / Zone 1 / Zone 2`, `Heat Pump / Hot Water`,`Heat Pump / Hot Water / Zone 2`, `Heat Pump / Zone 2`, `Zone 1`, `Zone 1 / Hot Water`, `Zone 1 / Hot Water / Zone 2`, `Zone 1 / Zone 2`, `Hot Water`, `Hot Water / Zone 2`, `Zone 2`, `All`. |
239
239
  | `atwDevices[].temperatureSensor` | This enable extra `Room` temperature sensors to use with automations in HomeKit app. |
240
240
  | `atwDevices[].temperatureSensorFlow` | This enable extra `Flow` temperature sensors to use with automations in HomeKit app. |
@@ -260,7 +260,7 @@ Homebridge plugin for Air Conditioner, Heat Pump and Energy Recovery Ventilation
260
260
  | `ervDevices[].type` | Read only data, do not change it. |
261
261
  | `ervDevices[].typeString` | Read only data, do not change it. |
262
262
  | `ervDevices[].name` | Here You can schange the `Accessory Name` which is exposed to the `Homebridge/HomeKit`. |
263
- | `ervDevices[].displayMode` | Here select main control mode `None/Disabled`, `Heater/Cooler`, `Thermostat`. |
263
+ | `ervDevices[].displayType` | Here select main control mode `None/Disabled`, `Heater/Cooler`, `Thermostat`. |
264
264
  | `ervDevices[].temperatureSensor` | This enable extra `Room` temperature sensors to use with automations in HomeKit app. |
265
265
  | `ervDevices[].temperatureSensorOutdoor` | This enable extra `Outdoor` temperature sensors to use with automations in HomeKit app. |
266
266
  | `ervDevices[].temperatureSensorSupply` | This enable extra `Supply` temperature sensors to use with automations in HomeKit app. |
@@ -251,7 +251,7 @@
251
251
  "default": "Air Conditioner",
252
252
  "readonly": true
253
253
  },
254
- "displayMode": {
254
+ "displayType": {
255
255
  "title": "Display Type",
256
256
  "type": "integer",
257
257
  "minimum": 0,
@@ -786,14 +786,14 @@
786
786
  }
787
787
  },
788
788
  "required": [
789
- "displayMode",
789
+ "displayType",
790
790
  "heatDryFanMode",
791
791
  "coolDryFanMode",
792
792
  "autoDryFanMode"
793
793
  ]
794
794
  },
795
795
  "condition": {
796
- "functionBody": "const accounts = model.accounts[arrayIndices]?.ataDevices || []; return accounts.length > 0 && accounts.every(device => device.id != null);"
796
+ "functionBody": "return model.accounts[arrayIndices[0]].ataDevices.length > 0 && model.accounts[arrayIndices[0]].every(device => device.id != null);"
797
797
  }
798
798
  },
799
799
  "atwDevices": {
@@ -825,7 +825,7 @@
825
825
  "type": "string",
826
826
  "default": "Heat Pump"
827
827
  },
828
- "displayMode": {
828
+ "displayType": {
829
829
  "title": "Display Type",
830
830
  "type": "integer",
831
831
  "minimum": 0,
@@ -1323,7 +1323,7 @@
1323
1323
  }
1324
1324
  },
1325
1325
  "required": [
1326
- "displayMode",
1326
+ "displayType",
1327
1327
  "hideZone"
1328
1328
  ]
1329
1329
  },
@@ -1360,7 +1360,7 @@
1360
1360
  "type": "string",
1361
1361
  "default": "Ventilation"
1362
1362
  },
1363
- "displayMode": {
1363
+ "displayType": {
1364
1364
  "title": "Display Type",
1365
1365
  "type": "integer",
1366
1366
  "minimum": 0,
@@ -1672,7 +1672,7 @@
1672
1672
  }
1673
1673
  },
1674
1674
  "required": [
1675
- "displayMode"
1675
+ "displayType"
1676
1676
  ]
1677
1677
  },
1678
1678
  "condition": {
@@ -1867,7 +1867,7 @@
1867
1867
  "key": "accounts[].ataDevices[].typeString",
1868
1868
  "readonly": true
1869
1869
  },
1870
- "accounts[].ataDevices[].displayMode",
1870
+ "accounts[].ataDevices[].displayType",
1871
1871
  {
1872
1872
  "key": "accounts[].ataDevices[]",
1873
1873
  "title": "Settings",
@@ -1882,7 +1882,7 @@
1882
1882
  "accounts[].ataDevices[].refreshInterval"
1883
1883
  ],
1884
1884
  "condition": {
1885
- "functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode > 0;"
1885
+ "functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayType > 0;"
1886
1886
  }
1887
1887
  },
1888
1888
  {
@@ -1896,7 +1896,7 @@
1896
1896
  "accounts[].ataDevices[].temperatureSensorOutdoor"
1897
1897
  ],
1898
1898
  "condition": {
1899
- "functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode > 0;"
1899
+ "functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayType > 0;"
1900
1900
  }
1901
1901
  },
1902
1902
  {
@@ -1922,7 +1922,7 @@
1922
1922
  }
1923
1923
  ],
1924
1924
  "condition": {
1925
- "functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode > 0;"
1925
+ "functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayType > 0;"
1926
1926
  }
1927
1927
  },
1928
1928
  {
@@ -1945,7 +1945,7 @@
1945
1945
  }
1946
1946
  ],
1947
1947
  "condition": {
1948
- "functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode > 0;"
1948
+ "functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayType > 0;"
1949
1949
  }
1950
1950
  }
1951
1951
  ],
@@ -1981,9 +1981,9 @@
1981
1981
  "key": "accounts[].atwDevices[].typeString",
1982
1982
  "readonly": true
1983
1983
  },
1984
- "accounts[].atwDevices[].displayMode",
1984
+ "accounts[].atwDevices[].displayType",
1985
1985
  {
1986
- "key": "accounts[].atwDevices",
1986
+ "key": "accounts[].atwDevices[]",
1987
1987
  "type": "section",
1988
1988
  "title": "Settings",
1989
1989
  "expandable": true,
@@ -1994,11 +1994,11 @@
1994
1994
  "accounts[].atwDevices[].refreshInterval"
1995
1995
  ],
1996
1996
  "condition": {
1997
- "functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode > 0;"
1997
+ "functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayType > 0;"
1998
1998
  }
1999
1999
  },
2000
2000
  {
2001
- "key": "accounts[].atwDevices",
2001
+ "key": "accounts[].atwDevices[]",
2002
2002
  "title": "Temperature Sensors",
2003
2003
  "type": "section",
2004
2004
  "expandable": true,
@@ -2015,7 +2015,7 @@
2015
2015
  "accounts[].atwDevices[].temperatureSensorReturnZone2"
2016
2016
  ],
2017
2017
  "condition": {
2018
- "functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode > 0;"
2018
+ "functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayType > 0;"
2019
2019
  }
2020
2020
  },
2021
2021
  {
@@ -2041,7 +2041,7 @@
2041
2041
  }
2042
2042
  ],
2043
2043
  "condition": {
2044
- "functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode > 0;"
2044
+ "functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayType > 0;"
2045
2045
  }
2046
2046
  },
2047
2047
  {
@@ -2064,7 +2064,7 @@
2064
2064
  }
2065
2065
  ],
2066
2066
  "condition": {
2067
- "functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode > 0;"
2067
+ "functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayType > 0;"
2068
2068
  }
2069
2069
  }
2070
2070
  ],
@@ -2100,9 +2100,9 @@
2100
2100
  "key": "accounts[].ervDevices[].typeString",
2101
2101
  "readonly": true
2102
2102
  },
2103
- "accounts[].ervDevices[].displayMode",
2103
+ "accounts[].ervDevices[].displayType",
2104
2104
  {
2105
- "key": "accounts[].ervDevices",
2105
+ "key": "accounts[].ervDevices[]",
2106
2106
  "title": "Settings",
2107
2107
  "type": "section",
2108
2108
  "expandable": true,
@@ -2112,11 +2112,11 @@
2112
2112
  "accounts[].ervDevices[].refreshInterval"
2113
2113
  ],
2114
2114
  "condition": {
2115
- "functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode > 0;"
2115
+ "functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayType > 0;"
2116
2116
  }
2117
2117
  },
2118
2118
  {
2119
- "key": "accounts[].ervDevices",
2119
+ "key": "accounts[].ervDevices[]",
2120
2120
  "title": "Temperature Sensors",
2121
2121
  "type": "section",
2122
2122
  "expandable": true,
@@ -2127,7 +2127,7 @@
2127
2127
  "accounts[].ervDevices[].temperatureSensorSupply"
2128
2128
  ],
2129
2129
  "condition": {
2130
- "functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode > 0;"
2130
+ "functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayType > 0;"
2131
2131
  }
2132
2132
  },
2133
2133
  {
@@ -2153,7 +2153,7 @@
2153
2153
  }
2154
2154
  ],
2155
2155
  "condition": {
2156
- "functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode > 0;"
2156
+ "functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayType > 0;"
2157
2157
  }
2158
2158
  },
2159
2159
  {
@@ -2176,7 +2176,7 @@
2176
2176
  }
2177
2177
  ],
2178
2178
  "condition": {
2179
- "functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode > 0;"
2179
+ "functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayType > 0;"
2180
2180
  }
2181
2181
  }
2182
2182
  ],
@@ -244,7 +244,7 @@
244
244
  type,
245
245
  typeString,
246
246
  name,
247
- displayMode: 1,
247
+ displayType: 1,
248
248
  presets: [],
249
249
  buttonsSensors: []
250
250
  });
package/index.js CHANGED
@@ -131,9 +131,9 @@ class MelCloudPlatform {
131
131
 
132
132
  for (const device of devices) {
133
133
  //chack device from config exist on melcloud
134
- const displayMode = device.displayMode > 0;
134
+ const displayType = device.displayType > 0;
135
135
  const deviceExistInMelCloud = devicesInMelcloud.some(dev => dev.DeviceID === device.id);
136
- if (!deviceExistInMelCloud || !displayMode) {
136
+ if (!deviceExistInMelCloud || !displayType) {
137
137
  continue;
138
138
  }
139
139
 
@@ -145,15 +145,19 @@ class MelCloudPlatform {
145
145
 
146
146
  if (accountType === 'melcloudhome') {
147
147
  try {
148
- [defaultTempsFile].forEach(file => {
149
- const temps = JSON.stringify({
150
- defaultCoolingSetTemperature: 24,
151
- defaultHeatingSetTemperature: 20
152
- });
153
- if (!existsSync(file)) writeFileSync(file, temps);
154
- });
148
+ const temps = {
149
+ defaultCoolingSetTemperature: 24,
150
+ defaultHeatingSetTemperature: 20
151
+ };
152
+
153
+ if (!existsSync(defaultTempsFile)) {
154
+ writeFileSync(defaultTempsFile, JSON.stringify(temps, null, 2));
155
+ if (logLevel.debug) log.debug(`Default temperature file created: ${defaultTempsFile}`);
156
+ }
155
157
  } catch (error) {
156
- if (logLevel.error) log.error(`Device: ${host} ${deviceName}, File init error: ${error}`);
158
+ if (logLevel.error) {
159
+ log.error(`Device: ${host} ${deviceName}, File init error: ${error.message}`);
160
+ }
157
161
  continue;
158
162
  }
159
163
  }
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.205",
4
+ "version": "4.0.0-beta.207",
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/deviceata.js CHANGED
@@ -17,9 +17,16 @@ class DeviceAta extends EventEmitter {
17
17
 
18
18
  //account config
19
19
  this.account = account;
20
- this.device = device;
21
20
  this.accountType = account.type;
22
- this.displayMode = device.displayMode;
21
+ this.accountName = account.name;
22
+ this.logDeviceInfo = account.log?.deviceInfo || false;
23
+ this.logInfo = account.log?.info || false;
24
+ this.logWarn = account.log?.warn || false;
25
+ this.logDebug = account.log?.debug || false;
26
+
27
+ //device config
28
+ this.device = device;
29
+ this.displayType = device.displayType;
23
30
  this.temperatureSensor = device.temperatureSensor || false;
24
31
  this.temperatureSensorOutdoor = device.temperatureSensorOutdoor || false;
25
32
  this.heatDryFanMode = device.heatDryFanMode || 1; //NONE, HEAT, DRY, FAN
@@ -27,11 +34,6 @@ class DeviceAta extends EventEmitter {
27
34
  this.autoDryFanMode = device.autoDryFanMode || 1; //NONE, AUTO, DRY, FAN
28
35
  this.presets = (device.presets || []).filter(preset => (preset.displayType ?? 0) > 0);
29
36
  this.buttons = (device.buttonsSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0);
30
- this.logDeviceInfo = account.log?.deviceInfo || false;
31
- this.logInfo = account.log?.info || false;
32
- this.logWarn = account.log?.warn || false;
33
- this.logDebug = account.log?.debug || false;
34
- this.accountName = account.name;
35
37
  this.deviceId = device.id;
36
38
  this.deviceName = device.name;
37
39
  this.deviceTypeText = device.typeString;
@@ -156,67 +158,67 @@ class DeviceAta extends EventEmitter {
156
158
  case 'Power':
157
159
  deviceData.Device[key] = value;
158
160
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Power;
159
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
161
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
160
162
  break;
161
163
  case 'OperationMode':
162
164
  deviceData.Device[key] = value;
163
165
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.OperationMode
164
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
166
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
165
167
  break;
166
168
  case 'SetTemperature':
167
169
  deviceData.Device[key] = value;
168
170
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetTemperature;
169
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
171
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
170
172
  break;
171
173
  case 'DefaultCoolingSetTemperature':
172
174
  deviceData.Device[key] = value;
173
175
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetTemperature;
174
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
176
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
175
177
  break;
176
178
  case 'DefaultHeatingSetTemperature':
177
179
  deviceData.Device[key] = value;
178
180
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetTemperature;
179
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
181
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
180
182
  break;
181
183
  case 'FanSpeed':
182
184
  deviceData.Device[key] = value;
183
185
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetFanSpeed;
184
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
186
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
185
187
  break;
186
188
  case 'VaneHorizontalDirection':
187
189
  deviceData.Device[key] = value;
188
190
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.VaneHorizontalDirection;
189
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
191
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
190
192
  break;
191
193
  case 'VaneVerticalDirection':
192
194
  deviceData.Device[key] = value;
193
195
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.VaneVerticalDirection;
194
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
196
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
195
197
  break;
196
198
  case 'HideVaneControls':
197
199
  deviceData[key] = value;
198
200
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Prohibit;
199
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
201
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
200
202
  break;
201
203
  case 'HideDryModeControl':
202
204
  deviceData[key] = value;
203
205
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Prohibit;
204
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
206
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
205
207
  break;
206
208
  case 'ProhibitSetTemperature':
207
209
  deviceData.Device[key] = value;
208
210
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Prohibit;
209
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
211
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
210
212
  break;
211
213
  case 'ProhibitOperationMode':
212
214
  deviceData.Device[key] = value;
213
215
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Prohibit;
214
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
216
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
215
217
  break;
216
218
  case 'ProhibitPower':
217
219
  deviceData.Device[key] = value;
218
220
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Prohibit;
219
- set = await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
221
+ set = await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
220
222
  break;
221
223
  default:
222
224
  this.emit('warn', `${integration}, received key: ${key}, value: ${value}`);
@@ -264,7 +266,7 @@ class DeviceAta extends EventEmitter {
264
266
  if (this.logDebug) this.emit('debug', `Prepare accessory`);
265
267
  const accessoryName = deviceName;
266
268
  const accessoryUUID = AccessoryUUID.generate(accountName + deviceId.toString());
267
- const accessoryCategory = [Categories.OTHER, Categories.AIR_HEATER, Categories.THERMOSTAT][this.displayMode];
269
+ const accessoryCategory = [Categories.OTHER, Categories.AIR_HEATER, Categories.THERMOSTAT][this.displayType];
268
270
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
269
271
 
270
272
  //information service
@@ -278,7 +280,7 @@ class DeviceAta extends EventEmitter {
278
280
 
279
281
  //melcloud services
280
282
  const serviceName = `${deviceTypeText} ${accessoryName}`;
281
- switch (this.displayMode) {
283
+ switch (this.displayType) {
282
284
  case 1: //Heater Cooler
283
285
  if (this.logDebug) this.emit('debug', `Prepare heater/cooler service`);
284
286
  this.melCloudService = new Service.HeaterCooler(serviceName, `HeaterCooler ${deviceId}`);
@@ -295,7 +297,7 @@ class DeviceAta extends EventEmitter {
295
297
  try {
296
298
  deviceData.Device.Power = state
297
299
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Power;
298
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
300
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
299
301
  if (this.logInfo) this.emit('info', `Set power: ${state ? 'ON' : 'OFF'}`);
300
302
  } catch (error) {
301
303
  if (this.logWarn) this.emit('warn', `Set power error: ${error}`);
@@ -334,7 +336,7 @@ class DeviceAta extends EventEmitter {
334
336
  };
335
337
 
336
338
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.OperationMode;
337
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
339
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
338
340
  if (this.logInfo) this.emit('info', `Set operation mode: ${AirConditioner.OperationModeMapEnumToString[value]}`);
339
341
  } catch (error) {
340
342
  if (this.logWarn) this.emit('warn', `Set operation mode error: ${error}`);
@@ -376,7 +378,7 @@ class DeviceAta extends EventEmitter {
376
378
 
377
379
  deviceData.Device[fanKey] = value
378
380
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetFanSpeed;
379
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
381
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
380
382
  if (this.logInfo) this.emit('info', `Set fan speed mode: ${AirConditioner.FanSpeedMapEnumToString[value]}`);
381
383
  } catch (error) {
382
384
  if (this.logWarn) this.emit('warn', `Set fan speed mode error: ${error}`);
@@ -395,7 +397,7 @@ class DeviceAta extends EventEmitter {
395
397
  deviceData.Device.VaneHorizontalDirection = value ? 12 : 0;
396
398
  deviceData.Device.VaneVerticalDirection = value ? 7 : 0;
397
399
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.VaneVerticalVaneHorizontal;
398
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
400
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
399
401
  if (this.logInfo) this.emit('info', `Set air direction mode: ${AirConditioner.AirDirectionMapEnumToString[value]}`);
400
402
  } catch (error) {
401
403
  if (this.logWarn) this.emit('warn', `Set vane swing mode error: ${error}`);
@@ -417,7 +419,7 @@ class DeviceAta extends EventEmitter {
417
419
  const tempKey = this.accessory.operationMode === 8 ? 'DefaultCoolingSetTemperature' : 'SetTemperature';
418
420
  deviceData.Device[tempKey] = value;
419
421
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetTemperature;
420
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
422
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
421
423
  if (this.logInfo) this.emit('info', `Set cooling threshold temperature: ${value}${this.accessory.temperatureUnit}`);
422
424
  } catch (error) {
423
425
  if (this.logWarn) this.emit('warn', `Set cooling threshold temperature error: ${error}`);
@@ -439,7 +441,7 @@ class DeviceAta extends EventEmitter {
439
441
  const tempKey = this.accessory.operationMode === 8 ? 'DefaultHeatingSetTemperature' : 'SetTemperature';
440
442
  deviceData.Device[tempKey] = value;
441
443
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetTemperature;
442
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
444
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
443
445
  if (this.logInfo) this.emit('info', `Set heating threshold temperature: ${value}${this.accessory.temperatureUnit}`);
444
446
  } catch (error) {
445
447
  if (this.logWarn) this.emit('warn', `Set heating threshold temperature error: ${error}`);
@@ -458,7 +460,7 @@ class DeviceAta extends EventEmitter {
458
460
  deviceData.Device.ProhibitOperationMode = value;
459
461
  deviceData.Device.ProhibitPower = value;
460
462
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Prohibit;
461
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
463
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
462
464
  if (this.logInfo) this.emit('info', `Set local physical controls: ${value ? 'LOCK' : 'UNLOCK'}`);
463
465
  } catch (error) {
464
466
  if (this.logWarn) this.emit('warn', `Set lock physical controls error: ${error}`);
@@ -526,7 +528,7 @@ class DeviceAta extends EventEmitter {
526
528
  };
527
529
 
528
530
  deviceData.Device.OperationMode = value;
529
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
531
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
530
532
  const operationModeText = AirConditioner.OperationModeMapEnumToString[value];
531
533
  if (this.logInfo) this.emit('info', `Set operation mode: ${operationModeText}`);
532
534
  } catch (error) {
@@ -552,7 +554,7 @@ class DeviceAta extends EventEmitter {
552
554
  try {
553
555
  deviceData.Device.SetTemperature = value;
554
556
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetTemperature;
555
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
557
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
556
558
  if (this.logInfo) this.emit('info', `Set temperature: ${value}${this.accessory.temperatureUnit}`);
557
559
  } catch (error) {
558
560
  if (this.logWarn) this.emit('warn', `Set temperature error: ${error}`);
@@ -663,7 +665,7 @@ class DeviceAta extends EventEmitter {
663
665
  break;
664
666
  };
665
667
 
666
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
668
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
667
669
  if (this.logInfo) this.emit('info', `${state ? 'Set:' : 'Unset:'} ${name}`);
668
670
  } catch (error) {
669
671
  if (this.logWarn) this.emit('warn', `Set preset error: ${error}`);
@@ -904,7 +906,7 @@ class DeviceAta extends EventEmitter {
904
906
  break;
905
907
  };
906
908
 
907
- await this.melCloudAta.send(this.accountType, this.displayMode, deviceData);
909
+ await this.melCloudAta.send(this.accountType, this.displayType, deviceData);
908
910
  if (this.logInfo) this.emit('info', `${state ? `Set: ${name}` : `Unset: ${name}, Set: ${button.previousValue}`}`);
909
911
  } catch (error) {
910
912
  if (this.logWarn) this.emit('warn', `Set button error: ${error}`);
@@ -1041,7 +1043,7 @@ class DeviceAta extends EventEmitter {
1041
1043
  };
1042
1044
 
1043
1045
  //operating mode 0, HEAT, DRY, COOL, 4, 5, 6, FAN, AUTO, ISEE HEAT, ISEE DRY, ISEE COOL
1044
- switch (this.displayMode) {
1046
+ switch (this.displayType) {
1045
1047
  case 1: //Heater Cooler
1046
1048
  switch (operationMode) {
1047
1049
  case 1: //HEAT
@@ -1322,7 +1324,7 @@ class DeviceAta extends EventEmitter {
1322
1324
  if (this.logInfo) {
1323
1325
  this.emit('info', `Power: ${power ? 'ON' : 'OFF'}`);
1324
1326
  this.emit('info', `Target operation mode: ${AirConditioner.OperationModeMapEnumToString[operationMode]}`);
1325
- this.emit('info', `Current operation mode: ${this.displayMode === 1 ? AirConditioner.CurrentOperationModeHeatherCoolerMapEnumToString[obj.currentOperationMode] : AirConditioner.CurrentOperationModeThermostatMapEnumToString[obj.currentOperationMode]}`);
1327
+ this.emit('info', `Current operation mode: ${this.displayType === 1 ? AirConditioner.CurrentOperationModeHeatherCoolerMapEnumToString[obj.currentOperationMode] : AirConditioner.CurrentOperationModeThermostatMapEnumToString[obj.currentOperationMode]}`);
1326
1328
  this.emit('info', `Target temperature: ${setTemperature}${obj.temperatureUnit}`);
1327
1329
  this.emit('info', `Current temperature: ${roomTemperature}${obj.temperatureUnit}`);
1328
1330
  if (supportsOutdoorTemperature && outdoorTemperature !== null) this.emit('info', `Outdoor temperature: ${outdoorTemperature}${obj.temperatureUnit}`);
package/src/deviceatw.js CHANGED
@@ -18,7 +18,7 @@ class DeviceAtw extends EventEmitter {
18
18
  //account config
19
19
  this.accountMelcloud = account.displayType === 'melcloud' ? true : false;
20
20
  this.device = device;
21
- this.displayMode = device.displayMode;
21
+ this.displayType = device.displayType;
22
22
  this.hideZone = device.hideZone;
23
23
  this.temperatureSensor = device.temperatureSensor || false;
24
24
  this.temperatureSensorFlow = device.temperatureSensorFlow || false;
@@ -289,7 +289,7 @@ class DeviceAtw extends EventEmitter {
289
289
  if (this.logDebug) this.emit('debug', `Prepare accessory`);
290
290
  const accessoryName = deviceName;
291
291
  const accessoryUUID = AccessoryUUID.generate(accountName + deviceId.toString());
292
- const accessoryCategory = [Categories.OTHER, Categories.AIR_HEATER, Categories.THERMOSTAT][this.displayMode];
292
+ const accessoryCategory = [Categories.OTHER, Categories.AIR_HEATER, Categories.THERMOSTAT][this.displayType];
293
293
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
294
294
 
295
295
  //information service
@@ -307,7 +307,7 @@ class DeviceAtw extends EventEmitter {
307
307
  this.accessory.zones.forEach((zone, i) => {
308
308
  const zoneName = zone.name
309
309
  const serviceName = `${deviceTypeText} ${accessoryName}: ${zoneName}`;
310
- switch (this.displayMode) {
310
+ switch (this.displayType) {
311
311
  case 1: //Heater Cooler
312
312
  if (this.logDebug) this.emit('debug', `Prepare heather/cooler ${zoneName} service`);
313
313
  const melCloudService = new Service.HeaterCooler(serviceName, `HeaterCooler ${deviceId} ${i}`);
@@ -1437,7 +1437,7 @@ class DeviceAtw extends EventEmitter {
1437
1437
  let temperatureSetPropsMaxValue = 100;
1438
1438
 
1439
1439
  for (let i = 0; i < zonesCount; i++) {
1440
- switch (this.displayMode) {
1440
+ switch (this.displayType) {
1441
1441
  case 1: //Heater Cooler
1442
1442
  switch (i) {
1443
1443
  case caseHeatPump: //Heat Pump Operation Mode - IDLE, HOT WATER, HEATING ZONES, COOLING, HOT WATER STORAGE, FREEZE STAT, LEGIONELLA, HEATING ECO, MODE 1, MODE 2, MODE 3, HEATING UP /// Unit Status - HEAT, COOL
package/src/deviceerv.js CHANGED
@@ -18,7 +18,7 @@ class DeviceErv extends EventEmitter {
18
18
  //account config
19
19
  this.accountMelcloud = account.displayType === 'melcloud' ? true : false;
20
20
  this.device = device;
21
- this.displayMode = device.displayMode;
21
+ this.displayType = device.displayType;
22
22
  this.temperatureSensor = device.temperatureSensor || false;
23
23
  this.temperatureSensorOutdoor = device.temperatureSensorOutdoor || false;
24
24
  this.temperatureSensorSupply = device.temperatureSensorSupply || false;
@@ -154,57 +154,57 @@ class DeviceErv extends EventEmitter {
154
154
  case 'Power':
155
155
  deviceData.Device[key] = value;
156
156
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.Power;
157
- set = await this.melCloudErv.send(deviceData, this.displayMode);
157
+ set = await this.melCloudErv.send(deviceData, this.displayType);
158
158
  break;
159
159
  case 'OperationMode':
160
160
  deviceData.Device[key] = value;
161
161
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.OperationMode;
162
- set = await this.melCloudErv.send(deviceData, this.displayMode);
162
+ set = await this.melCloudErv.send(deviceData, this.displayType);
163
163
  break;
164
164
  case 'VentilationMode':
165
165
  deviceData.Device[key] = value;
166
166
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.VentilationMode;
167
- set = await this.melCloudErv.send(deviceData, this.displayMode);
167
+ set = await this.melCloudErv.send(deviceData, this.displayType);
168
168
  break;
169
169
  case 'SetTemperature':
170
170
  deviceData.Device[key] = value;
171
171
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.SetTemperature;
172
- set = await this.melCloudErv.send(deviceData, this.displayMode);
172
+ set = await this.melCloudErv.send(deviceData, this.displayType);
173
173
  break;
174
174
  case 'DefaultCoolingSetTemperature':
175
175
  deviceData.Device[key] = value;
176
176
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.SetTemperature;
177
- set = await this.melCloudErv.send(deviceData, this.displayMode);
177
+ set = await this.melCloudErv.send(deviceData, this.displayType);
178
178
  break;
179
179
  case 'DefaultHeatingSetTemperature':
180
180
  deviceData.Device[key] = value;
181
181
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.SetTemperature;
182
- set = await this.melCloudErv.send(deviceData, this.displayMode);
182
+ set = await this.melCloudErv.send(deviceData, this.displayType);
183
183
  break;
184
184
  case 'NightPurgeMode':
185
185
  deviceData.Device[key] = value;
186
186
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.NightPurgeMode;
187
- set = await this.melCloudErv.send(deviceData, this.displayMode);
187
+ set = await this.melCloudErv.send(deviceData, this.displayType);
188
188
  break;
189
189
  case 'SetFanSpeed':
190
190
  deviceData.Device[key] = value;
191
191
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.SetFanSpeed;
192
- set = await this.melCloudErv.send(deviceData, this.displayMode);
192
+ set = await this.melCloudErv.send(deviceData, this.displayType);
193
193
  break;
194
194
  case 'HideRoomTemperature':
195
195
  deviceData[key] = value;
196
196
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.Prohibit;
197
- set = await this.melCloudErv.send(deviceData, this.displayMode);
197
+ set = await this.melCloudErv.send(deviceData, this.displayType);
198
198
  break;
199
199
  case 'HideSupplyTemperature':
200
200
  deviceData[key] = value;
201
201
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.Prohibit;
202
- set = await this.melCloudErv.send(deviceData, this.displayMode);
202
+ set = await this.melCloudErv.send(deviceData, this.displayType);
203
203
  break;
204
204
  case 'HideOutdoorTemperature':
205
205
  deviceData[key] = value;
206
206
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.Prohibit;
207
- set = await this.melCloudErv.send(deviceData, this.displayMode);
207
+ set = await this.melCloudErv.send(deviceData, this.displayType);
208
208
  break;
209
209
  default:
210
210
  this.emit('warn', `${integration}, received key: ${key}, value: ${value}`);
@@ -251,7 +251,7 @@ class DeviceErv extends EventEmitter {
251
251
  if (this.logDebug) this.emit('debug', `Prepare accessory`);
252
252
  const accessoryName = deviceName;
253
253
  const accessoryUUID = AccessoryUUID.generate(accountName + deviceId.toString());
254
- const accessoryCategory = [Categories.OTHER, Categories.AIR_PURIFIER, Categories.THERMOSTAT][this.displayMode];
254
+ const accessoryCategory = [Categories.OTHER, Categories.AIR_PURIFIER, Categories.THERMOSTAT][this.displayType];
255
255
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
256
256
 
257
257
  //information service
@@ -265,7 +265,7 @@ class DeviceErv extends EventEmitter {
265
265
 
266
266
  //services
267
267
  const serviceName = `${deviceTypeText} ${accessoryName}`;
268
- switch (this.displayMode) {
268
+ switch (this.displayType) {
269
269
  case 1: //Heater Cooler
270
270
  if (this.logDebug) this.emit('debug', `Prepare heather/cooler service`);
271
271
  this.melCloudService = new Service.HeaterCooler(serviceName, `HeaterCooler ${deviceId}`);
@@ -279,7 +279,7 @@ class DeviceErv extends EventEmitter {
279
279
  try {
280
280
  deviceData.Device.Power = [false, true][state];
281
281
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.Power;
282
- await this.melCloudErv.send(deviceData, this.displayMode);
282
+ await this.melCloudErv.send(deviceData, this.displayType);
283
283
  if (this.logInfo) this.emit('info', `Set power: ${state ? 'ON' : 'OFF'}`);
284
284
  } catch (error) {
285
285
  if (this.logWarn) this.emit('warn', `Set power error: ${error}`);
@@ -315,7 +315,7 @@ class DeviceErv extends EventEmitter {
315
315
  };
316
316
 
317
317
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.VentilationMode;
318
- await this.melCloudErv.send(deviceData, this.displayMode);
318
+ await this.melCloudErv.send(deviceData, this.displayType);
319
319
  const operationModeText = Ventilation.VentilationMode[deviceData.Device.VentilationMode];
320
320
  if (this.logInfo) this.emit('info', `Set operation mode: ${operationModeText}`);
321
321
  } catch (error) {
@@ -359,7 +359,7 @@ class DeviceErv extends EventEmitter {
359
359
  break;;
360
360
  };
361
361
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.SetFanSpeed;
362
- await this.melCloudErv.send(deviceData, this.displayMode);
362
+ await this.melCloudErv.send(deviceData, this.displayType);
363
363
  if (this.logInfo) this.emit('info', `Set fan speed mode: ${Ventilation.FanSpeed[fanSpeedModeText]}`);
364
364
  } catch (error) {
365
365
  if (this.logWarn) this.emit('warn', `Set fan speed mode error: ${error}`);
@@ -381,7 +381,7 @@ class DeviceErv extends EventEmitter {
381
381
  try {
382
382
  deviceData.Device.DefaultCoolingSetTemperature = value;
383
383
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.SetTemperature;
384
- await this.melCloudErv.send(deviceData, this.displayMode);
384
+ await this.melCloudErv.send(deviceData, this.displayType);
385
385
  if (this.logInfo) this.emit('info', `Set cooling threshold temperature: ${value}${this.accessory.temperatureUnit}`);
386
386
  } catch (error) {
387
387
  if (this.logWarn) this.emit('warn', `Set cooling threshold temperature error: ${error}`);
@@ -404,7 +404,7 @@ class DeviceErv extends EventEmitter {
404
404
  try {
405
405
  deviceData.Device.DefaultHeatingSetTemperature = value;
406
406
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.SetTemperature;
407
- await this.melCloudErv.send(deviceData, this.displayMode);
407
+ await this.melCloudErv.send(deviceData, this.displayType);
408
408
  if (this.logInfo) this.emit('info', `Set heating threshold temperature: ${value}${this.accessory.temperatureUnit}`);
409
409
  } catch (error) {
410
410
  if (this.logWarn) this.emit('warn', `Set heating threshold temperature error: ${error}`);
@@ -422,7 +422,7 @@ class DeviceErv extends EventEmitter {
422
422
  // value = value ? true : false;
423
423
  // deviceData.Device = deviceData.Device;
424
424
  // deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
425
- // await this.melCloudErv.send(deviceData, this.displayMode);
425
+ // await this.melCloudErv.send(deviceData, this.displayType);
426
426
  // if (this.logInfo) this.emit('info', `Set local physical controls: ${value ? 'LOCK' : 'UNLOCK'}`);
427
427
  // } catch (error) {
428
428
  // if (this.logWarn) this.emit('warn', `Set lock physical controls error: ${error}`);
@@ -488,7 +488,7 @@ class DeviceErv extends EventEmitter {
488
488
  break;
489
489
  };
490
490
 
491
- await this.melCloudErv.send(deviceData, this.displayMode);
491
+ await this.melCloudErv.send(deviceData, this.displayType);
492
492
  const operationModeText = Ventilation.VentilationMode[deviceData.Device.VentilationMode];
493
493
  if (this.logInfo) this.emit('info', `Set operation mode: ${operationModeText}`);
494
494
  } catch (error) {
@@ -514,7 +514,7 @@ class DeviceErv extends EventEmitter {
514
514
  try {
515
515
  deviceData.Device.SetTemperature = value;
516
516
  deviceData.Device.EffectiveFlags = Ventilation.EffectiveFlags.SetTemperature;
517
- await this.melCloudErv.send(deviceData, this.displayMode);
517
+ await this.melCloudErv.send(deviceData, this.displayType);
518
518
  if (this.logInfo) this.emit('info', `Set temperature: ${value}${this.accessory.temperatureUnit}`);
519
519
  } catch (error) {
520
520
  if (this.logWarn) this.emit('warn', `Set temperature error: ${error}`);
@@ -706,7 +706,7 @@ class DeviceErv extends EventEmitter {
706
706
  break;
707
707
  };
708
708
 
709
- await this.melCloudErv.send(deviceData, this.displayMode);
709
+ await this.melCloudErv.send(deviceData, this.displayType);
710
710
  if (this.logInfo) this.emit('info', `${state ? 'Set:' : 'Unset:'} ${name}`);
711
711
  } catch (error) {
712
712
  if (this.logWarn) this.emit('warn', `Set preset error: ${error}`);
@@ -820,7 +820,7 @@ class DeviceErv extends EventEmitter {
820
820
  break;
821
821
  };
822
822
 
823
- await this.melCloudErv.send(deviceData, this.displayMode);
823
+ await this.melCloudErv.send(deviceData, this.displayType);
824
824
  if (this.logInfo) this.emit('info', `${state ? `Set: ${buttonName}` : `Unset: ${buttonName}, Set: ${button.previousValue}`}`);
825
825
  } catch (error) {
826
826
  if (this.logWarn) this.emit('warn', `Set button error: ${error}`);
@@ -958,7 +958,7 @@ class DeviceErv extends EventEmitter {
958
958
  };
959
959
 
960
960
  //ventilation mode - 0, HEAT, 2, COOL, 4, 5, 6, FAN, AUTO
961
- switch (this.displayMode) {
961
+ switch (this.displayType) {
962
962
  case 1: //Heater Cooler
963
963
  switch (ventilationMode) {
964
964
  case 0: //LOSSNAY
package/src/functions.js CHANGED
@@ -1,3 +1,4 @@
1
+ import fs from 'fs';
1
2
  import { promises as fsPromises } from 'fs';
2
3
 
3
4
  class Functions {
@@ -26,5 +27,15 @@ class Functions {
26
27
  throw new Error(`Read data error: ${error}`);
27
28
  }
28
29
  }
30
+
31
+ async isRunningInDocker() {
32
+ try {
33
+ if (fs.existsSync('/.dockerenv')) return true;
34
+ const cgroup = fs.readFileSync('/proc/1/cgroup', 'utf8');
35
+ return cgroup.includes('docker') || cgroup.includes('kubepods');
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
29
40
  }
30
41
  export default Functions
package/src/melcloud.js CHANGED
@@ -1,4 +1,4 @@
1
- import fs from 'fs';
1
+
2
2
  import { execSync } from 'child_process';
3
3
  import puppeteer from 'puppeteer';
4
4
  import axios from 'axios';
@@ -56,113 +56,63 @@ class MelCloud extends EventEmitter {
56
56
  }
57
57
  }
58
58
 
59
+ // MELCloud
59
60
  async checkMelcloudDevicesList(contextKey) {
60
- if (this.logDebug) this.emit('debug', `Connecting to MELCloud Home`);
61
-
62
61
  try {
63
- const browser = await puppeteer.launch({
64
- headless: true,
65
- args: ['--no-sandbox', '--disable-setuid-sandbox']
62
+ const axiosInstanceGet = axios.create({
63
+ method: 'GET',
64
+ baseURL: ApiUrls.BaseURL,
65
+ timeout: 15000,
66
+ headers: { 'X-MitsContextKey': contextKey }
66
67
  });
67
- const page = await browser.newPage();
68
68
 
69
- await page.goto(ApiUrlsHome.BaseURL, { waitUntil: 'networkidle2' });
69
+ if (this.logDebug) this.emit('debug', `Scanning for devices`);
70
+ const listDevicesData = await axiosInstanceGet(ApiUrls.ListDevices);
71
+ const buildingsList = listDevicesData.data;
72
+ if (this.logDebug) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
70
73
 
71
- const buttons = await page.$$('button.btn--blue');
72
- let loginBtn = null;
73
- for (const btn of buttons) {
74
- const text = await page.evaluate(el => el.textContent, btn);
75
- if (text.trim() === 'Zaloguj' || text.trim() === 'Log In') {
76
- loginBtn = btn;
77
- break;
78
- }
74
+ if (!buildingsList) {
75
+ if (this.logWarn) this.emit('warn', `No building found`);
76
+ return null;
79
77
  }
80
78
 
81
- if (!loginBtn && this.logWarn) this.emit('warn', `Login button not found`);
82
-
83
- await Promise.all([
84
- loginBtn.click(),
85
- page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 10000 })
86
- ]);
87
-
88
- await page.waitForSelector('input[name="username"]', { timeout: 5000 });
89
- await page.type('input[name="username"]', this.user, { delay: 50 });
90
- await page.type('input[name="password"]', this.passwd, { delay: 50 });
79
+ await this.functions.saveData(this.buildingsFile, buildingsList);
80
+ if (this.logDebug) this.emit('debug', `Buildings list saved`);
91
81
 
92
- const button1 = await page.$('input[type="submit"]');
93
- await Promise.all([
94
- button1.click(),
95
- page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 10000 })
96
- ]);
82
+ const devices = [];
83
+ for (const building of buildingsList) {
84
+ const buildingStructure = building.Structure;
85
+ const allDevices = [
86
+ ...buildingStructure.Floors.flatMap(floor => [
87
+ ...floor.Areas.flatMap(area => area.Devices),
88
+ ...floor.Devices
89
+ ]),
90
+ ...buildingStructure.Areas.flatMap(area => area.Devices),
91
+ ...buildingStructure.Devices
92
+ ];
97
93
 
98
- let c1 = null, c2 = null;
99
- const start = Date.now();
94
+ // Zamiana DeviceID na string
95
+ allDevices.forEach(device => {
96
+ if (device.DeviceID !== undefined && device.DeviceID !== null) {
97
+ device.DeviceID = device.DeviceID.toString();
98
+ }
99
+ });
100
100
 
101
- while ((!c1 || !c2) && Date.now() - start < 20000) {
102
- const cookies = await page.cookies();
103
- c1 = cookies.find(c => c.name === '__Secure-monitorandcontrolC1')?.value || c1;
104
- c2 = cookies.find(c => c.name === '__Secure-monitorandcontrolC2')?.value || c2;
105
- if (!c1 || !c2) await new Promise(r => setTimeout(r, 500));
101
+ devices.push(...allDevices);
106
102
  }
107
103
 
108
- if (!c1 || !c2) {
109
- if (this.logWarn) this.emit('warn', `Cookies C1/C2 missing`);
104
+ const devicesCount = devices.length;
105
+ if (devicesCount === 0) {
106
+ if (this.logWarn) this.emit('warn', `No devices found`);
110
107
  return null;
111
108
  }
112
109
 
113
- const contextKey = [
114
- '__Secure-monitorandcontrol=chunks-2',
115
- `__Secure-monitorandcontrolC1=${c1}`,
116
- `__Secure-monitorandcontrolC2=${c2}`
117
- ].join('; ');
118
-
119
- const accountInfo = { ContextKey: contextKey, UseFahrenheit: false };
120
- this.contextKey = contextKey;
121
-
122
- await this.functions.saveData(this.accountFile, accountInfo);
123
- if (!refresh) this.emit('success', `Connect to MELCloud Home Success`);
124
-
125
- await browser.close();
126
- return accountInfo;
110
+ await this.functions.saveData(this.devicesFile, devices);
111
+ if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
127
112
 
113
+ return devices;
128
114
  } catch (error) {
129
- if (error.message.includes('libnspr4.so') || error.message.includes('Failed to launch the browser process')) {
130
- const inDocker = isRunningInDocker();
131
- this.emit('warn', `Missing system libraries detected.`);
132
-
133
- if (inDocker) {
134
- this.emit('warn', `Running in Docker — attempting automatic fix...`);
135
-
136
- const installCmd =
137
- 'apt-get update && apt-get install -y ' +
138
- 'libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 ' +
139
- 'libxcomposite1 libxrandr2 libxdamage1 libxkbcommon0 libpango-1.0-0 ' +
140
- 'libgbm1 libasound2 libxshmfence1 fonts-liberation libappindicator3-1 libu2f-udev';
141
-
142
- try {
143
- execSync(installCmd, { stdio: 'inherit' });
144
- this.emit('debug', `Libraries installed. Retrying Puppeteer...`);
145
-
146
- const browser = await puppeteer.launch({
147
- headless: true,
148
- args: ['--no-sandbox', '--disable-setuid-sandbox']
149
- });
150
- await browser.close();
151
- this.emit('success', `Puppeteer repaired and running.`);
152
- return true;
153
-
154
- } catch (fixError) {
155
- this.emit('error', `Automatic fix failed. You can run manually inside container:\n${installCmd}`);
156
- throw fixError;
157
- }
158
-
159
- } else {
160
- this.emit('error', `System libraries missing. Detected non-Docker environment — please install dependencies manually.`);
161
- throw error;
162
- }
163
- } else {
164
- throw new Error(`Puppeteer failed: ${error.message}`);
165
- }
115
+ throw new Error(`Check devices list error: ${error.message}`);
166
116
  }
167
117
  }
168
118
 
@@ -320,16 +270,7 @@ class MelCloud extends EventEmitter {
320
270
  }
321
271
  }
322
272
 
323
- isRunningInDocker() {
324
- try {
325
- if (fs.existsSync('/.dockerenv')) return true;
326
- const cgroup = fs.readFileSync('/proc/1/cgroup', 'utf8');
327
- return cgroup.includes('docker') || cgroup.includes('kubepods');
328
- } catch {
329
- return false;
330
- }
331
- }
332
-
273
+ // MELCloud Home
333
274
  async connectToMelCloudHome(refresh = false) {
334
275
  if (this.logDebug) this.emit('debug', `Connecting to MELCloud Home`);
335
276
 
@@ -402,7 +343,7 @@ class MelCloud extends EventEmitter {
402
343
  return accountInfo;
403
344
  } catch (error) {
404
345
  if (error.message.includes('libnspr4.so') || error.message.includes('Failed to launch the browser process')) {
405
- const inDocker = this.isRunningInDocker();
346
+ const inDocker = await this.functions.isRunningInDocker();
406
347
  if (this.logWarn) this.emit('warn', `Missing system libraries detected.`);
407
348
 
408
349
  if (inDocker) {
@@ -441,7 +382,6 @@ class MelCloud extends EventEmitter {
441
382
  }
442
383
  }
443
384
 
444
-
445
385
  async checkDevicesList(contextKey) {
446
386
  let devices = [];
447
387
  switch (this.accountType) {
@@ -174,7 +174,7 @@ class MelCloudAta extends EventEmitter {
174
174
  };
175
175
  };
176
176
 
177
- async send(accountType, displayMode, deviceData) {
177
+ async send(accountType, displayType, deviceData) {
178
178
  try {
179
179
  switch (accountType) {
180
180
  case "melcloud":
@@ -189,7 +189,7 @@ class MelCloudAta extends EventEmitter {
189
189
  withCredentials: true
190
190
  });
191
191
 
192
- if (displayMode === 1 && deviceData.Device.OperationMode === 8) {
192
+ if (displayType === 1 && deviceData.Device.OperationMode === 8) {
193
193
  deviceData.Device.SetTemperature = (deviceData.Device.DefaultCoolingSetTemperature + deviceData.Device.DefaultHeatingSetTemperature) / 2;
194
194
  }
195
195
 
@@ -238,7 +238,7 @@ class MelCloudAta extends EventEmitter {
238
238
  }
239
239
  });
240
240
 
241
- if (displayMode === 1 && deviceData.Device.OperationMode === 8) {
241
+ if (displayType === 1 && deviceData.Device.OperationMode === 8) {
242
242
  deviceData.Device.SetTemperature = (deviceData.Device.DefaultCoolingSetTemperature + deviceData.Device.DefaultHeatingSetTemperature) / 2;
243
243
 
244
244
  if (this.deviceState.DefaultCoolingSetTemperature !== deviceData.Device.DefaultCoolingSetTemperature || this.deviceState.DefaultHeatingSetTemperature !== deviceData.Device.DefaultHeatingSetTemperature) {
@@ -209,10 +209,10 @@ class MelCloudErv extends EventEmitter {
209
209
  };
210
210
  };
211
211
 
212
- async send(deviceData, displayMode) {
212
+ async send(deviceData, displayType) {
213
213
  try {
214
214
  //set target temp based on display mode and ventilation mode
215
- switch (displayMode) {
215
+ switch (displayType) {
216
216
  case 1: //Heather/Cooler
217
217
  switch (deviceData.Device.VentilationMode) {
218
218
  case 0: //LOSNAY