homebridge-melcloud-control 3.7.2 → 3.7.3-beta.1

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.
@@ -1,391 +1,416 @@
1
- <div style="text-align: center;">
2
- </divstyle>
3
- <img src="homebridge-melcloud-control.png" alt="Image" height="120" />
4
- </div><br>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
5
3
 
6
- <div id="melCloudAccount" style="display: none;" class="card card-body">
7
- <form id="configForm">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>MELCloud Account Configuration</title>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css">
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/js/all.min.js"></script>
10
+ </head>
11
+
12
+ <body>
13
+
14
+ <div class="container mt-4">
8
15
  <div class="text-center">
9
- <label id="accountName" style="font-size: 23px">Account</label><br>
10
- <label id="info" style="text-align: center; font-size: 17px;"></label><br>
11
- <label id="info1" style="text-align: center; font-size: 15px;"></label><br>
12
- <label id="info2" style="text-align: center; font-size: 15px;"></label><br>
16
+ <img src="homebridge-melcloud-control.png" alt="Image" height="120" />
13
17
  </div>
14
- <div class="form-group">
15
- <label for="name">Name</label>
16
- <input id="name" type="text" class="form-control"><br>
17
- <label for="user">User Name</label>
18
- <input id="user" type="text" class="form-control"><br>
19
- <label for="passwd">Password</label>
20
- <input id="passwd" type="password" class="form-control"><br>
21
- <label for="language">Language</label>
22
- <select id="language" name="language" class="form-control"><br>
23
- <option value="0">English</option>
24
- <option value="1">Български</option>
25
- <option value="2">Čeština</option>
26
- <option value="3">Dansk</option>
27
- <option value="4">Deutsch</option>
28
- <option value="5">Eesti</option>
29
- <option value="6">Español</option>
30
- <option value="7">Français</option>
31
- <option value="8">Հայերեն</option>
32
- <option value="9">Latviešu</option>
33
- <option value="10">Lietuvių</option>
34
- <option value="11">Magyar</option>
35
- <option value="12">Nederlands</option>
36
- <option value="13">Norwegian</option>
37
- <option value="14">Polski</option>
38
- <option value="15">Português</option>
39
- <option value="16">Русский</option>
40
- <option value="17">Suomi</option>
41
- <option value="18">Svenska</option>
42
- <option value="19">Svenska</option>
43
- <option value="20">Українська</option>
44
- <option value="21">Türkçe</option>
45
- <option value="22">Ελληνικά</option>
46
- <option value="23">Hrvatski</option>
47
- <option value="24">Română</option>
48
- <option value="25">Slovenščina</option>
49
- </select><br>
50
- </div>
51
- <div class="text-center">
52
- <button id="logIn" type="button" class="btn btn-primary">Connect to MELCloud</button>
53
- <button id="configButton" type="button" class="btn btn-primary"><i class="fas fa-gear"></i></button>
18
+
19
+ <div id="melCloudAccount" class="card card-body mt-3">
20
+ <form id="configForm">
21
+ <div class="text-center">
22
+ <label id="accountName" class="fw-bold" style="font-size: 23px;">Account</label><br>
23
+ <label id="info" class="d-block" style="font-size: 17px;"></label>
24
+ <label id="info1" class="d-block" style="font-size: 15px;"></label>
25
+ <label id="info2" class="d-block" style="font-size: 15px;"></label>
26
+ </div>
27
+
28
+ <div class="mb-3">
29
+ <label for="name" class="form-label">Name</label>
30
+ <input id="name" type="text" class="form-control" required>
31
+ </div>
32
+
33
+ <div class="mb-3">
34
+ <label for="user" class="form-label">User Name</label>
35
+ <input id="user" type="text" class="form-control" required>
36
+ </div>
37
+
38
+ <div class="mb-3">
39
+ <label for="passwd" class="form-label">Password</label>
40
+ <input id="passwd" type="password" class="form-control" autocomplete="off" required>
41
+ </div>
42
+
43
+ <div class="mb-3">
44
+ <label for="language" class="form-label">Language</label>
45
+ <select id="language" name="language" class="form-control">
46
+ <option value="0">English</option>
47
+ <option value="1">Български</option>
48
+ <option value="2">Čeština</option>
49
+ <option value="3">Dansk</option>
50
+ <option value="4">Deutsch</option>
51
+ <option value="5">Eesti</option>
52
+ <option value="6">Español</option>
53
+ <option value="7">Français</option>
54
+ <option value="8">Հայերեն</option>
55
+ <option value="9">Latviešu</option>
56
+ <option value="10">Lietuvių</option>
57
+ <option value="11">Magyar</option>
58
+ <option value="12">Nederlands</option>
59
+ <option value="13">Norwegian</option>
60
+ <option value="14">Polski</option>
61
+ <option value="15">Português</option>
62
+ <option value="16">Русский</option>
63
+ <option value="17">Suomi</option>
64
+ <option value="18">Svenska</option>
65
+ <option value="19">Українська</option>
66
+ <option value="20">Türkçe</option>
67
+ <option value="21">Ελληνικά</option>
68
+ <option value="22">Hrvatski</option>
69
+ <option value="23">Română</option>
70
+ <option value="24">Slovenščina</option>
71
+ </select>
72
+ </div>
73
+
74
+ <div class="text-center">
75
+ <button id="logIn" type="button" class="btn btn-primary">Connect to MELCloud</button>
76
+ <button id="configButton" type="button" class="btn btn-secondary"><i class="fas fa-gear"></i></button>
77
+ </div>
78
+ </form>
54
79
  </div>
55
- </form>
56
- </div>
57
-
58
- <div id="accountButton"></div>
59
- </div>
60
-
61
- <script>
62
- (async () => {
63
- //get the plugin config array
64
- const pluginConfig = await homebridge.getPluginConfig();
65
-
66
- if (!pluginConfig.length) {
67
- pluginConfig.push({});
68
- await homebridge.updatePluginConfig(pluginConfig);
69
- homebridge.showSchemaForm();
70
- return;
71
- }
72
-
73
- //get accounts count
74
- const accountsCount = pluginConfig[0].accounts.length;
75
- this.deviceIndex = 0;
76
- for (let i = 0; i < accountsCount; i++) {
77
- //create buttons
78
- const button = document.createElement("button");
79
- button.setAttribute("type", "button");
80
- button.setAttribute("id", `button${i}`);
81
- button.setAttribute("class", "btn btn-primary");
82
- button.style.textTransform = 'none';
83
- button.innerText = pluginConfig[0].accounts[i].name;
84
- document.getElementById("accountButton").appendChild(button);
85
-
86
- //get actuall value on account select
87
- document.getElementById(`button${i}`).addEventListener('click', async () => {
88
- for (let j = 0; j < accountsCount; j++) {
89
- const setRemoveAtribute = j === i ? document.getElementById(`button${j}`).setAttribute("class", "btn btn-secondary") : document.getElementById(`button${j}`).setAttribute("class", "btn btn-primary");
90
- }
91
-
92
- document.getElementById('accountName').innerHTML = pluginConfig[0].accounts[i].name || '';
93
- document.getElementById('name').value = pluginConfig[0].accounts[i].name || '';
94
- document.getElementById('user').value = pluginConfig[0].accounts[i].user || '';
95
- document.getElementById('passwd').value = pluginConfig[0].accounts[i].passwd || '';
96
- document.getElementById('language').value = pluginConfig[0].accounts[i].language || '';
97
-
98
- const accountConfigured = pluginConfig[0].accounts[i].name && pluginConfig[0].accounts[i].user && pluginConfig[0].accounts[i].passwd && pluginConfig[0].accounts[i].language;
80
+
81
+ <div id="accountButton" class="mt-3"></div>
82
+ </div>
83
+
84
+ <script>
85
+ (async () => {
86
+ //get the plugin config array
87
+ const pluginConfig = await homebridge.getPluginConfig();
88
+
89
+ if (!pluginConfig.length) {
90
+ pluginConfig.push({});
91
+ await homebridge.updatePluginConfig(pluginConfig);
92
+ homebridge.showSchemaForm();
93
+ return;
94
+ }
95
+ this.configButtonState = false;
96
+
97
+ //get accounts count
98
+ const accountsCount = pluginConfig[0].accounts.length;
99
+ this.deviceIndex = 0;
100
+ for (let i = 0; i < accountsCount; i++) {
101
+ //create buttons
102
+ const button = document.createElement("button");
103
+ button.setAttribute("type", "button");
104
+ button.setAttribute("id", `button${i}`);
105
+ button.setAttribute("class", "btn btn-primary");
106
+ button.style.textTransform = 'none';
107
+ button.innerText = pluginConfig[0].accounts[i].name;
108
+ document.getElementById("accountButton").appendChild(button);
109
+
110
+ //get actuall value on account select
111
+ document.getElementById(`button${i}`).addEventListener('click', async () => {
112
+ for (let j = 0; j < accountsCount; j++) {
113
+ const setRemoveAtribute = j === i ? document.getElementById(`button${j}`).setAttribute("class", "btn btn-secondary") : document.getElementById(`button${j}`).setAttribute("class", "btn btn-primary");
114
+ }
115
+
116
+ document.getElementById('accountName').innerHTML = pluginConfig[0].accounts[i].name || '';
117
+ document.getElementById('name').value = pluginConfig[0].accounts[i].name || '';
118
+ document.getElementById('user').value = pluginConfig[0].accounts[i].user || '';
119
+ document.getElementById('passwd').value = pluginConfig[0].accounts[i].passwd || '';
120
+ document.getElementById('language').value = pluginConfig[0].accounts[i].language || '';
121
+
122
+ const accountConfigured = pluginConfig[0].accounts[i].name && pluginConfig[0].accounts[i].user && pluginConfig[0].accounts[i].passwd && pluginConfig[0].accounts[i].language;
123
+ const button = document.getElementById('logIn');
124
+ const setButtonState = accountConfigured ? button.disabled = false : button.disabled = true;
125
+
126
+ await homebridge.updatePluginConfig(pluginConfig);
127
+ this.deviceIndex = i;
128
+ });
129
+ const click = i === accountsCount - 1 ? document.getElementById(`button0`).click() : false;
130
+ const update = i === accountsCount - 1 ? await homebridge.updatePluginConfig(pluginConfig) : false;
131
+ };
132
+
133
+ //load melCloudAccount form
134
+ document.getElementById('melCloudAccount').style.display = 'block';
135
+
136
+ //watch for changes to the form
137
+ document.getElementById('configForm').addEventListener('input', async () => {
138
+ pluginConfig[0].accounts[this.deviceIndex].name = document.querySelector('#name').value;
139
+ pluginConfig[0].accounts[this.deviceIndex].user = document.querySelector('#user').value;
140
+ pluginConfig[0].accounts[this.deviceIndex].passwd = document.querySelector('#passwd').value;
141
+ pluginConfig[0].accounts[this.deviceIndex].language = document.querySelector('#language').value;
142
+
143
+ const accountConfigured = pluginConfig[0].accounts[this.deviceIndex].name && pluginConfig[0].accounts[this.deviceIndex].user && pluginConfig[0].accounts[this.deviceIndex].passwd && pluginConfig[0].accounts[this.deviceIndex].language;
99
144
  const button = document.getElementById('logIn');
100
145
  const setButtonState = accountConfigured ? button.disabled = false : button.disabled = true;
101
146
 
102
147
  await homebridge.updatePluginConfig(pluginConfig);
103
- this.deviceIndex = i;
148
+ await homebridge.savePluginConfig(pluginConfig);
104
149
  });
105
- const click = i === accountsCount - 1 ? document.getElementById(`button0`).click() : false;
106
- const update = i === accountsCount - 1 ? await homebridge.updatePluginConfig(pluginConfig) : false;
107
- };
108
-
109
- //load melCloudAccount form
110
- document.getElementById('melCloudAccount').style.display = 'block';
111
-
112
- //watch for changes to the form
113
- document.getElementById('configForm').addEventListener('input', async () => {
114
- pluginConfig[0].accounts[this.deviceIndex].name = document.querySelector('#name').value;
115
- pluginConfig[0].accounts[this.deviceIndex].user = document.querySelector('#user').value;
116
- pluginConfig[0].accounts[this.deviceIndex].passwd = document.querySelector('#passwd').value;
117
- pluginConfig[0].accounts[this.deviceIndex].language = document.querySelector('#language').value;
118
-
119
- const accountConfigured = pluginConfig[0].accounts[this.deviceIndex].name && pluginConfig[0].accounts[this.deviceIndex].user && pluginConfig[0].accounts[this.deviceIndex].passwd && pluginConfig[0].accounts[this.deviceIndex].language;
120
- const button = document.getElementById('logIn');
121
- const setButtonState = accountConfigured ? button.disabled = false : button.disabled = true;
122
-
123
- await homebridge.updatePluginConfig(pluginConfig);
124
- await homebridge.savePluginConfig(pluginConfig);
125
- });
126
-
127
- //watch for changes to the config button
128
- document.getElementById('configButton').addEventListener('click', async () => {
129
- const showHideSettings = this.configButtonState ? homebridge.hideSchemaForm() : homebridge.showSchemaForm();
130
- this.configButtonState = !this.configButtonState;
131
- });
132
-
133
- //watch for click on the login button
134
- document.getElementById('logIn').addEventListener('click', async () => {
135
- homebridge.showSpinner();
136
- document.getElementById('info').innerHTML = 'Connecting...';
137
- document.getElementById('info').style.color = 'yellow';
138
-
139
- try {
140
- const accountName = pluginConfig[0].accounts[this.deviceIndex].name;
141
- const user = pluginConfig[0].accounts[this.deviceIndex].user;
142
- const passwd = pluginConfig[0].accounts[this.deviceIndex].passwd;
143
- const language = pluginConfig[0].accounts[this.deviceIndex].language;
144
-
145
- const payload = {
146
- accountName: accountName,
147
- user: user,
148
- passwd: passwd,
149
- language: language
150
- };
151
- const devicesInMelCloud = await homebridge.request('/connect', payload);
152
-
153
- //new found devices
154
- const newDevices = {
155
- ata: [],
156
- ataPresets: [],
157
- atw: [],
158
- atwPresets: [],
159
- erv: [],
160
- ervPresets: [],
161
- };
162
150
 
163
- //get devices from melcloud by type
164
- const devicesByTypeInMelCloud = {
165
- ata: [],
166
- atw: [],
167
- erv: []
168
- };
151
+ //watch for changes to the config button
152
+ document.getElementById('configButton').addEventListener('click', async () => {
153
+ const showHideSettings = this.configButtonState ? homebridge.hideSchemaForm() : homebridge.showSchemaForm();
154
+ const setRemoveAtribute = this.configButtonState ? document.getElementById(`configButton`).setAttribute("class", "btn btn-secondary") : document.getElementById(`configButton`).setAttribute("class", "btn btn-primary");
155
+ this.configButtonState = !this.configButtonState;
156
+ });
169
157
 
170
- for (const deviceInMelcloud of devicesInMelCloud) {
171
- const deviceType = deviceInMelcloud.Type;
172
- const pusDeviceTypeAta = deviceType === 0 ? devicesByTypeInMelCloud.ata.push(deviceInMelcloud) : false;
173
- const pusDeviceTypeAtw = deviceType === 1 ? devicesByTypeInMelCloud.atw.push(deviceInMelcloud) : false;
174
- const pusDeviceTypeErv = deviceType === 3 ? devicesByTypeInMelCloud.erv.push(deviceInMelcloud) : false;
175
- };
158
+ //watch for click on the login button
159
+ document.getElementById('logIn').addEventListener('click', async () => {
160
+ homebridge.showSpinner();
161
+ document.getElementById('info').innerHTML = 'Connecting...';
162
+ document.getElementById('info').style.color = 'yellow';
176
163
 
177
- //devices in config
178
- const ataDevicesInConfigExist = pluginConfig[0].accounts[this.deviceIndex].ataDevices ?? false;
179
- const atwDevicesInConfigExist = pluginConfig[0].accounts[this.deviceIndex].atwDevices ?? false;
180
- const ervDevicesInConfigExist = pluginConfig[0].accounts[this.deviceIndex].ervDevices ?? false;
181
-
182
- //check key of devices in config exist
183
- const ataDevicesInConfig = !ataDevicesInConfigExist ? pluginConfig[0].accounts[this.deviceIndex].ataDevices = [] : ataDevicesInConfigExist;
184
- const atwDevicesInConfig = !atwDevicesInConfigExist ? pluginConfig[0].accounts[this.deviceIndex].atwDevices = [] : atwDevicesInConfigExist;
185
- const ervDevicesInConfig = !ervDevicesInConfigExist ? pluginConfig[0].accounts[this.deviceIndex].ervDevices = [] : ervDevicesInConfigExist;
186
-
187
- //device ata
188
- devicesByTypeInMelCloud.ata.forEach((device, index) => {
189
- const deviceId = device.DeviceID;
190
- const deviceType = device.Type;
191
- const deviceName = device.DeviceName;
192
- const devicePresets = device.Presets ?? [];
193
-
194
- const deviceAta = {
195
- id: deviceId,
196
- type: deviceType,
197
- typeString: "Air Conditioner",
198
- disableAccessory: false,
199
- name: deviceName,
200
- displayMode: 1,
201
- heatDryFanMode: 1,
202
- coolDryFanMode: 1,
203
- autoDryFanMode: 1,
204
- temperatureSensor: false,
205
- temperatureSensorOutdoor: false,
206
- presets: [],
207
- buttonsSensors: []
164
+ try {
165
+ const accountName = pluginConfig[0].accounts[this.deviceIndex].name;
166
+ const user = pluginConfig[0].accounts[this.deviceIndex].user;
167
+ const passwd = pluginConfig[0].accounts[this.deviceIndex].passwd;
168
+ const language = pluginConfig[0].accounts[this.deviceIndex].language;
169
+
170
+ const payload = {
171
+ accountName: accountName,
172
+ user: user,
173
+ passwd: passwd,
174
+ language: language
208
175
  };
209
-
210
- const deviceExistsInConfig = ataDevicesInConfig.some(device => device.id === deviceId);
211
- if (!deviceExistsInConfig) {
212
- ataDevicesInConfig.push(deviceAta);
213
- newDevices.ata.push(deviceAta);
176
+ const devicesInMelCloud = await homebridge.request('/connect', payload);
177
+
178
+ //new found devices
179
+ const newDevices = {
180
+ ata: [],
181
+ ataPresets: [],
182
+ atw: [],
183
+ atwPresets: [],
184
+ erv: [],
185
+ ervPresets: [],
214
186
  };
215
187
 
216
- //presets of device in melcloud
217
- devicePresets.forEach((preset) => {
218
- const presetId = preset.ID;
219
- const presetName = preset.NumberDescription;
220
-
221
- preset.id = presetId;
222
- preset.name = presetName;
223
- preset.displayType == 0;
224
- preset.namePrefix = false;
225
-
226
- //find the specific ataDevice to which the preset belongs
227
- const ataDevice = ataDevicesInConfig.find((device) => device.id === deviceId);
228
- if (ataDevice && !ataDevice.presets.some((p) => p.id === presetId)) {
229
- ataDevice.presets.push(preset);
230
- newDevices.ataPresets.push(preset);
231
- }
232
-
233
- });
234
- });
235
- const textAta = `ATA: ${newDevices.ata.length}`;
236
- const textAtaPresets = `ATA Presets: ${newDevices.ataPresets.length}`;
237
-
238
- //device atw
239
- devicesByTypeInMelCloud.atw.forEach((device, index) => {
240
- const deviceId = device.DeviceID;
241
- const deviceType = device.Type;
242
- const deviceName = device.DeviceName;
243
- const devicePresets = device.Presets ?? [];
244
-
245
- const deviceAtw = {
246
- id: deviceId,
247
- type: deviceType,
248
- typeString: "Heat Pump",
249
- disableAccessory: false,
250
- name: deviceName,
251
- displayMode: 1,
252
- temperatureSensor: false,
253
- temperatureSensorFlow: false,
254
- temperatureSensorReturn: false,
255
- temperatureSensorFlowZone1: false,
256
- temperatureSensorReturnZone1: false,
257
- temperatureSensorFlowWaterTank: false,
258
- temperatureSensorReturnWaterTank: false,
259
- temperatureSensorFlowZone2: false,
260
- temperatureSensorReturnZone2: false,
261
- temperatureSensor: false,
262
- temperatureSensorOutdoor: false,
263
- presets: [],
264
- buttonsSensors: []
188
+ //get devices from melcloud by type
189
+ const devicesByTypeInMelCloud = {
190
+ ata: [],
191
+ atw: [],
192
+ erv: []
265
193
  };
266
194
 
267
- const deviceExistsInConfig = atwDevicesInConfig.some(device => device.id === deviceId);
268
- if (!deviceExistsInConfig) {
269
- atwDevicesInConfig.push(deviceAtw);
270
- newDevices.atw.push(deviceAtw);
195
+ for (const deviceInMelcloud of devicesInMelCloud) {
196
+ const deviceType = deviceInMelcloud.Type;
197
+ const pusDeviceTypeAta = deviceType === 0 ? devicesByTypeInMelCloud.ata.push(deviceInMelcloud) : false;
198
+ const pusDeviceTypeAtw = deviceType === 1 ? devicesByTypeInMelCloud.atw.push(deviceInMelcloud) : false;
199
+ const pusDeviceTypeErv = deviceType === 3 ? devicesByTypeInMelCloud.erv.push(deviceInMelcloud) : false;
271
200
  };
272
201
 
273
- //presets of device in melcloud
274
- devicePresets.forEach((preset) => {
275
- const presetId = preset.ID;
276
- const presetName = preset.NumberDescription;
277
-
278
- preset.id = presetId;
279
- preset.name = presetName;
280
- preset.displayType == 0;
281
- preset.namePrefix = false;
282
-
283
- //find the specific ataDevice to which the preset belongs
284
- const atwDevice = atwDevicesInConfig.find((device) => device.id === deviceId);
285
- if (atwDevice && !atwDevice.presets.some((p) => p.id === presetId)) {
286
- atwDevice.presets.push(preset);
287
- newDevices.atwPresets.push(preset);
288
- }
289
-
202
+ //devices in config
203
+ const ataDevicesInConfigExist = pluginConfig[0].accounts[this.deviceIndex].ataDevices ?? false;
204
+ const atwDevicesInConfigExist = pluginConfig[0].accounts[this.deviceIndex].atwDevices ?? false;
205
+ const ervDevicesInConfigExist = pluginConfig[0].accounts[this.deviceIndex].ervDevices ?? false;
206
+
207
+ //check key of devices in config exist
208
+ const ataDevicesInConfig = !ataDevicesInConfigExist ? pluginConfig[0].accounts[this.deviceIndex].ataDevices = [] : ataDevicesInConfigExist;
209
+ const atwDevicesInConfig = !atwDevicesInConfigExist ? pluginConfig[0].accounts[this.deviceIndex].atwDevices = [] : atwDevicesInConfigExist;
210
+ const ervDevicesInConfig = !ervDevicesInConfigExist ? pluginConfig[0].accounts[this.deviceIndex].ervDevices = [] : ervDevicesInConfigExist;
211
+
212
+ //device ata
213
+ devicesByTypeInMelCloud.ata.forEach((device, index) => {
214
+ const deviceId = device.DeviceID;
215
+ const deviceType = device.Type;
216
+ const deviceName = device.DeviceName;
217
+ const devicePresets = device.Presets ?? [];
218
+
219
+ const deviceAta = {
220
+ id: deviceId,
221
+ type: deviceType,
222
+ typeString: "Air Conditioner",
223
+ disableAccessory: false,
224
+ name: deviceName,
225
+ displayMode: 1,
226
+ heatDryFanMode: 1,
227
+ coolDryFanMode: 1,
228
+ autoDryFanMode: 1,
229
+ temperatureSensor: false,
230
+ temperatureSensorOutdoor: false,
231
+ presets: [],
232
+ buttonsSensors: []
233
+ };
234
+
235
+ const deviceExistsInConfig = ataDevicesInConfig.some(device => device.id === deviceId);
236
+ if (!deviceExistsInConfig) {
237
+ ataDevicesInConfig.push(deviceAta);
238
+ newDevices.ata.push(deviceAta);
239
+ };
240
+
241
+ //presets of device in melcloud
242
+ devicePresets.forEach((preset) => {
243
+ const presetId = preset.ID;
244
+ const presetName = preset.NumberDescription;
245
+
246
+ preset.id = presetId;
247
+ preset.name = presetName;
248
+ preset.displayType == 0;
249
+ preset.namePrefix = false;
250
+
251
+ //find the specific ataDevice to which the preset belongs
252
+ const ataDevice = ataDevicesInConfig.find((device) => device.id === deviceId);
253
+ if (ataDevice && !ataDevice.presets.some((p) => p.id === presetId)) {
254
+ ataDevice.presets.push(preset);
255
+ newDevices.ataPresets.push(preset);
256
+ }
257
+
258
+ });
290
259
  });
291
- });
292
- const textAtw = `ATW: ${newDevices.atw.length}`;
293
- const textAtwPresets = `ATW Presets: ${newDevices.atwPresets.length}`;
294
-
295
- //device erv
296
- devicesByTypeInMelCloud.erv.forEach((device, index) => {
297
- const deviceId = device.DeviceID;
298
- const deviceType = device.Type;
299
- const deviceName = device.DeviceName;
300
- const devicePresets = device.Presets ?? [];
301
-
302
- const deviceErv = {
303
- id: deviceId,
304
- type: deviceType,
305
- typeString: "Energy Recovery Ventilation",
306
- disableAccessory: false,
307
- name: deviceName,
308
- displayMode: 1,
309
- temperatureSensor: false,
310
- temperatureSensorOutdoor: false,
311
- temperatureSensorSupply: false,
312
- temperatureSensor: false,
313
- temperatureSensorOutdoor: false,
314
- presets: [],
315
- buttonsSensors: []
260
+ const textAta = `ATA: ${newDevices.ata.length}`;
261
+ const textAtaPresets = `ATA Presets: ${newDevices.ataPresets.length}`;
262
+
263
+ //device atw
264
+ devicesByTypeInMelCloud.atw.forEach((device, index) => {
265
+ const deviceId = device.DeviceID;
266
+ const deviceType = device.Type;
267
+ const deviceName = device.DeviceName;
268
+ const devicePresets = device.Presets ?? [];
269
+
270
+ const deviceAtw = {
271
+ id: deviceId,
272
+ type: deviceType,
273
+ typeString: "Heat Pump",
274
+ disableAccessory: false,
275
+ name: deviceName,
276
+ displayMode: 1,
277
+ temperatureSensor: false,
278
+ temperatureSensorFlow: false,
279
+ temperatureSensorReturn: false,
280
+ temperatureSensorFlowZone1: false,
281
+ temperatureSensorReturnZone1: false,
282
+ temperatureSensorFlowWaterTank: false,
283
+ temperatureSensorReturnWaterTank: false,
284
+ temperatureSensorFlowZone2: false,
285
+ temperatureSensorReturnZone2: false,
286
+ temperatureSensor: false,
287
+ temperatureSensorOutdoor: false,
288
+ presets: [],
289
+ buttonsSensors: []
290
+ };
291
+
292
+ const deviceExistsInConfig = atwDevicesInConfig.some(device => device.id === deviceId);
293
+ if (!deviceExistsInConfig) {
294
+ atwDevicesInConfig.push(deviceAtw);
295
+ newDevices.atw.push(deviceAtw);
296
+ };
297
+
298
+ //presets of device in melcloud
299
+ devicePresets.forEach((preset) => {
300
+ const presetId = preset.ID;
301
+ const presetName = preset.NumberDescription;
302
+
303
+ preset.id = presetId;
304
+ preset.name = presetName;
305
+ preset.displayType == 0;
306
+ preset.namePrefix = false;
307
+
308
+ //find the specific ataDevice to which the preset belongs
309
+ const atwDevice = atwDevicesInConfig.find((device) => device.id === deviceId);
310
+ if (atwDevice && !atwDevice.presets.some((p) => p.id === presetId)) {
311
+ atwDevice.presets.push(preset);
312
+ newDevices.atwPresets.push(preset);
313
+ }
314
+
315
+ });
316
+ });
317
+ const textAtw = `ATW: ${newDevices.atw.length}`;
318
+ const textAtwPresets = `ATW Presets: ${newDevices.atwPresets.length}`;
319
+
320
+ //device erv
321
+ devicesByTypeInMelCloud.erv.forEach((device, index) => {
322
+ const deviceId = device.DeviceID;
323
+ const deviceType = device.Type;
324
+ const deviceName = device.DeviceName;
325
+ const devicePresets = device.Presets ?? [];
326
+
327
+ const deviceErv = {
328
+ id: deviceId,
329
+ type: deviceType,
330
+ typeString: "Energy Recovery Ventilation",
331
+ disableAccessory: false,
332
+ name: deviceName,
333
+ displayMode: 1,
334
+ temperatureSensor: false,
335
+ temperatureSensorOutdoor: false,
336
+ temperatureSensorSupply: false,
337
+ temperatureSensor: false,
338
+ temperatureSensorOutdoor: false,
339
+ presets: [],
340
+ buttonsSensors: []
341
+ };
342
+
343
+ const deviceExistsInConfig = ervDevicesInConfig.some(device => device.id === deviceId);
344
+ if (!deviceExistsInConfig) {
345
+ ervDevicesInConfig.push(deviceErv);
346
+ newDevices.erv.push(deviceErv);
347
+ };
348
+
349
+ //presets of device in melcloud
350
+ devicePresets.forEach((preset) => {
351
+ const presetId = preset.ID;
352
+ const presetName = preset.NumberDescription;
353
+
354
+ preset.id = presetId;
355
+ preset.name = presetName;
356
+ preset.displayType == 0;
357
+ preset.namePrefix = false;
358
+
359
+ //find the specific ataDevice to which the preset belongs
360
+ const ervDevice = ervDevicesInConfig.find((device) => device.id === deviceId);
361
+ if (ervDevice && !ervDevice.presets.some((p) => p.id === presetId)) {
362
+ ervDevice.presets.push(preset);
363
+ newDevices.ervPresets.push(preset);
364
+ }
365
+
366
+ });
367
+ });
368
+ const textErv = `ERV: ${newDevices.erv.length}`;
369
+ const textErvPresets = `ERV Presets: ${newDevices.ervPresets.length}`;
370
+
371
+ //display info
372
+ const newDevicesCount = newDevices.ata.length + newDevices.atw.length + newDevices.erv.length ?? 0;
373
+ const newPresetsCount = newDevices.ataPresets.length + newDevices.atwPresets.length + newDevices.ervPresets.length ?? 0;
374
+ if (newDevicesCount === 0 && newPresetsCount === 0) {
375
+ document.getElementById('info').innerHTML = 'No new devices found.';
376
+ document.getElementById('info').style.color = 'white';
316
377
  };
317
378
 
318
- const deviceExistsInConfig = ervDevicesInConfig.some(device => device.id === deviceId);
319
- if (!deviceExistsInConfig) {
320
- ervDevicesInConfig.push(deviceErv);
321
- newDevices.erv.push(deviceErv);
379
+ if (newDevicesCount > 0 && newPresetsCount > 0) {
380
+ document.getElementById('info').innerHTML = `Found, ${textAta}, ${textAtw}, ${textErv}.`;
381
+ document.getElementById('info').style.color = 'green';
382
+ document.getElementById('info1').innerHTML = `${textAtaPresets}, ${textAtwPresets}, ${textErvPresets}.`;
383
+ document.getElementById('info1').style.color = 'green';
384
+ document.getElementById('info2').innerHTML = 'Now You can configure it.';
385
+ document.getElementById('info2').style.color = 'green';
322
386
  };
323
387
 
324
- //presets of device in melcloud
325
- devicePresets.forEach((preset) => {
326
- const presetId = preset.ID;
327
- const presetName = preset.NumberDescription;
328
-
329
- preset.id = presetId;
330
- preset.name = presetName;
331
- preset.displayType == 0;
332
- preset.namePrefix = false;
333
-
334
- //find the specific ataDevice to which the preset belongs
335
- const ervDevice = ervDevicesInConfig.find((device) => device.id === deviceId);
336
- if (ervDevice && !ervDevice.presets.some((p) => p.id === presetId)) {
337
- ervDevice.presets.push(preset);
338
- newDevices.ervPresets.push(preset);
339
- }
340
-
341
- });
342
- });
343
- const textErv = `ERV: ${newDevices.erv.length}`;
344
- const textErvPresets = `ERV Presets: ${newDevices.ervPresets.length}`;
345
-
346
- //display info
347
- const newDevicesCount = newDevices.ata.length + newDevices.atw.length + newDevices.erv.length ?? 0;
348
- const newPresetsCount = newDevices.ataPresets.length + newDevices.atwPresets.length + newDevices.ervPresets.length ?? 0;
349
- if (newDevicesCount === 0 && newPresetsCount === 0) {
350
- document.getElementById('info').innerHTML = 'No new devices found.';
351
- document.getElementById('info').style.color = 'white';
352
- };
353
-
354
- if (newDevicesCount > 0 && newPresetsCount > 0) {
355
- document.getElementById('info').innerHTML = `Found, ${textAta}, ${textAtw}, ${textErv}.`;
356
- document.getElementById('info').style.color = 'green';
357
- document.getElementById('info1').innerHTML = `${textAtaPresets}, ${textAtwPresets}, ${textErvPresets}.`;
358
- document.getElementById('info1').style.color = 'green';
359
- document.getElementById('info2').innerHTML = 'Now You can configure it.';
360
- document.getElementById('info2').style.color = 'green';
361
- };
388
+ if (newDevicesCount > 0 && newPresetsCount === 0) {
389
+ document.getElementById('info').innerHTML = `Found, ${textAta}, ${textAtw}, ${textErv}.`;
390
+ document.getElementById('info').style.color = 'green';
391
+ document.getElementById('info1').innerHTML = 'Now You can configure it.';
392
+ document.getElementById('info1').style.color = 'green';
393
+ };
362
394
 
363
- if (newDevicesCount > 0 && newPresetsCount === 0) {
364
- document.getElementById('info').innerHTML = `Found, ${textAta}, ${textAtw}, ${textErv}.`;
365
- document.getElementById('info').style.color = 'green';
366
- document.getElementById('info1').innerHTML = 'Now You can configure it.';
367
- document.getElementById('info1').style.color = 'green';
395
+ if (newDevicesCount === 0 && newPresetsCount > 0) {
396
+ document.getElementById('info').innerHTML = `Found, ${textAtaPresets}, ${textAtwPresets}, ${textErvPresets}.`;
397
+ document.getElementById('info').style.color = 'green';
398
+ document.getElementById('info1').innerHTML = 'Now You can configure it.';
399
+ document.getElementById('info1').style.color = 'green';
400
+ }
401
+
402
+ //update ans save plugin config
403
+ await homebridge.updatePluginConfig(pluginConfig);
404
+ await homebridge.savePluginConfig(pluginConfig);
405
+ homebridge.hideSpinner();
406
+ } catch (error) {
407
+ document.getElementById('info').innerHTML = 'Check Your credentials data and try again.';
408
+ document.getElementById('info').style.color = 'yellow';
409
+ document.getElementById('info1').innerHTML = `Error: ${error}`;
410
+ document.getElementById('info1').style.color = 'red';
411
+ } finally {
412
+ homebridge.hideSpinner();
368
413
  };
369
-
370
- if (newDevicesCount === 0 && newPresetsCount > 0) {
371
- document.getElementById('info').innerHTML = `Found, ${textAtaPresets}, ${textAtwPresets}, ${textErvPresets}.`;
372
- document.getElementById('info').style.color = 'green';
373
- document.getElementById('info1').innerHTML = 'Now You can configure it.';
374
- document.getElementById('info1').style.color = 'green';
375
- }
376
-
377
- //update ans save plugin config
378
- await homebridge.updatePluginConfig(pluginConfig);
379
- await homebridge.savePluginConfig(pluginConfig);
380
- homebridge.hideSpinner();
381
- } catch (error) {
382
- document.getElementById('info').innerHTML = 'Check Your credentials data and try again.';
383
- document.getElementById('info').style.color = 'yellow';
384
- document.getElementById('info1').innerHTML = `Error: ${error}`;
385
- document.getElementById('info1').style.color = 'red';
386
- } finally {
387
- homebridge.hideSpinner();
388
- };
389
- });
390
- })();
391
- </script>
414
+ });
415
+ })();
416
+ </script>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "3.7.2",
4
+ "version": "3.7.3-beta.1",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",