homebridge-melcloud-control 3.9.0-beta.12 → 3.9.0-beta.14

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.
@@ -1813,7 +1813,7 @@
1813
1813
  {
1814
1814
  "key": "accounts",
1815
1815
  "type": "tabarray",
1816
- "title": "{{ value.name || 'account' }}",
1816
+ "title": "{{ value.name }}",
1817
1817
  "items": [
1818
1818
  "accounts[].name",
1819
1819
  "accounts[].user",
@@ -15,11 +15,6 @@
15
15
  <img src="homebridge-melcloud-control.png" alt="Image" height="100" />
16
16
  </div>
17
17
 
18
- <!-- Config button -->
19
- <div class="text-center mt-3">
20
- <button type="button" class="btn btn-primary" id="configButton" disabled>⚙️ Config</button>
21
- </div>
22
-
23
18
  <!-- Tabs -->
24
19
  <ul class="nav nav-tabs mt-3" id="accountTabs" role="tablist"></ul>
25
20
 
@@ -48,10 +43,7 @@
48
43
  const tabs = document.getElementById("accountTabs");
49
44
  const content = document.getElementById("accountTabsContent");
50
45
 
51
- let configButtonState = false;
52
- const configButton = document.getElementById('configButton');
53
-
54
- function updateConfigButtonState(account) {
46
+ function updateConfigButtonState(account, configButton) {
55
47
  const hasMultipleDevices =
56
48
  (account.ataDevices?.length || 0) > 1 ||
57
49
  (account.atwDevices?.length || 0) > 1 ||
@@ -117,11 +109,19 @@
117
109
  <option value="19" ${account.language == 19 ? 'selected' : ''}>Türkçe</option>
118
110
  </select>
119
111
  </div>
120
- <button type="button" class="btn btn-secondary" id="logIn-${i}">Connect</button>
121
- <button type="button" class="btn btn-danger ms-2" id="remove-${i}">❌ Remove Account</button>
112
+ <div class="mb-3">
113
+ <button type="button" class="btn btn-secondary" id="logIn-${i}">Connect</button>
114
+ <button type="button" class="btn btn-danger ms-2" id="remove-${i}">Remove Account</button>
115
+ <button type="button" class="btn btn-primary ms-2" id="config-${i}" disabled>⚙️ Config</button>
116
+ </div>
122
117
  </form>`;
123
118
  content.appendChild(pane);
124
119
 
120
+ const configButton = document.getElementById(`config-${i}`);
121
+
122
+ // Enable config button if devices > 1
123
+ updateConfigButtonState(account, configButton);
124
+
125
125
  // Handle input updates
126
126
  pane.querySelector("form").addEventListener("input", async () => {
127
127
  account.name = document.getElementById(`name-${i}`).value;
@@ -156,7 +156,6 @@
156
156
  language: account.language
157
157
  });
158
158
 
159
- const newDevices = { ata: [], ataPresets: [], atw: [], atwPresets: [], erv: [], ervPresets: [] };
160
159
  const devicesByType = { ata: [], atw: [], erv: [] };
161
160
  for (const d of devicesInMelCloud) {
162
161
  if (d.Type === 0) devicesByType.ata.push(d);
@@ -164,62 +163,39 @@
164
163
  if (d.Type === 3) devicesByType.erv.push(d);
165
164
  }
166
165
 
167
- // Remove stale function
166
+ // Initialize device arrays if missing
167
+ account.ataDevices = account.ataDevices ?? [{}];
168
+ account.atwDevices = account.atwDevices ?? [{}];
169
+ account.ervDevices = account.ervDevices ?? [{}];
170
+
171
+ // Remove stale devices
168
172
  function removeStaleDevices(configDevices, melcloudDevices) {
169
173
  const melcloudIds = melcloudDevices.map(d => d.DeviceID);
170
- const removed = [];
171
174
  for (let j = configDevices.length - 1; j >= 0; j--) {
172
175
  const dev = configDevices[j];
173
- if (dev.id !== 0 && !melcloudIds.includes(dev.id)) {
174
- removed.push(dev);
175
- configDevices.splice(j, 1);
176
- }
176
+ if (dev.id !== 0 && !melcloudIds.includes(dev.id)) configDevices.splice(j, 1);
177
177
  }
178
- return removed;
179
178
  }
180
179
 
181
- const ataDevices = account.ataDevices ?? (account.ataDevices = []);
182
- const atwDevices = account.atwDevices ?? (account.atwDevices = []);
183
- const ervDevices = account.ervDevices ?? (account.ervDevices = []);
180
+ removeStaleDevices(account.ataDevices, devicesByType.ata);
181
+ removeStaleDevices(account.atwDevices, devicesByType.atw);
182
+ removeStaleDevices(account.ervDevices, devicesByType.erv);
184
183
 
185
- removeStaleDevices(ataDevices, devicesByType.ata);
186
- removeStaleDevices(atwDevices, devicesByType.atw);
187
- removeStaleDevices(ervDevices, devicesByType.erv);
188
-
189
- // Add new devices & presets
190
- function handleDevices(configArray, devicesArray, typeName, newDevicesArr, newPresetsArr) {
184
+ // Add new devices
185
+ function addDevices(configArray, devicesArray) {
191
186
  devicesArray.forEach(d => {
192
- let existing = configArray.find(x => x.id === d.DeviceID);
193
- if (!existing) {
194
- existing = { id: d.DeviceID, type: d.Type, typeString: typeName, name: d.DeviceName, displayMode: 1, presets: [], buttonsSensors: [] };
195
- configArray.push(existing);
196
- newDevicesArr.push(existing);
187
+ if (!configArray.find(x => x.id === d.DeviceID)) {
188
+ configArray.push({ id: d.DeviceID, type: d.Type, name: d.DeviceName });
197
189
  }
198
- (d.Presets || []).forEach(p => {
199
- const preset = { ...p, id: p.ID, name: p.NumberDescription, displayType: 0, namePrefix: false };
200
- if (!existing.presets.some(pr => pr.id === p.ID)) {
201
- existing.presets.push(preset);
202
- newPresetsArr.push(preset);
203
- }
204
- });
205
190
  });
206
191
  }
207
192
 
208
- handleDevices(ataDevices, devicesByType.ata, "Air Conditioner", newDevices.ata, newDevices.ataPresets);
209
- handleDevices(atwDevices, devicesByType.atw, "Heat Pump", newDevices.atw, newDevices.atwPresets);
210
- handleDevices(ervDevices, devicesByType.erv, "ERV", newDevices.erv, newDevices.ervPresets);
211
-
212
- // Update info
213
- function updateInfo(id, text, color) {
214
- const el = document.getElementById(id);
215
- if (el) { el.innerHTML = text; el.style.color = color; }
216
- }
217
-
218
- const textInfo = `Found devices: ATA(${newDevices.ata.length}), ATW(${newDevices.atw.length}), ERV(${newDevices.erv.length})`;
219
- updateInfo('info', textInfo, 'green');
193
+ addDevices(account.ataDevices, devicesByType.ata);
194
+ addDevices(account.atwDevices, devicesByType.atw);
195
+ addDevices(account.ervDevices, devicesByType.erv);
220
196
 
221
197
  // Update Config button state
222
- updateConfigButtonState(account);
198
+ updateConfigButtonState(account, configButton);
223
199
 
224
200
  await homebridge.updatePluginConfig(pluginConfig);
225
201
  await homebridge.savePluginConfig(pluginConfig);
@@ -229,6 +205,15 @@
229
205
  homebridge.hideSpinner();
230
206
  }
231
207
  });
208
+
209
+ // Config button click
210
+ configButton.addEventListener('click', () => {
211
+ if (configButton.classList.contains('btn-primary')) {
212
+ homebridge.showSchemaForm();
213
+ } else {
214
+ homebridge.hideSchemaForm();
215
+ }
216
+ });
232
217
  }
233
218
 
234
219
  // Render accounts
@@ -250,18 +235,6 @@
250
235
  new bootstrap.Tab(document.getElementById(`tab-${i}`)).show();
251
236
  });
252
237
 
253
- // Config button toggle
254
- configButton.addEventListener('click', () => {
255
- if (configButtonState) {
256
- homebridge.hideSchemaForm();
257
- configButton.className = "btn btn-secondary";
258
- } else {
259
- homebridge.showSchemaForm();
260
- configButton.className = "btn btn-primary";
261
- }
262
- configButtonState = !configButtonState;
263
- });
264
-
265
238
  })();
266
239
  </script>
267
240
  </body>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "3.9.0-beta.12",
4
+ "version": "3.9.0-beta.14",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",