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