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

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.
@@ -15,8 +15,9 @@
15
15
  <img src="homebridge-melcloud-control.png" alt="Image" height="100" />
16
16
  </div>
17
17
 
18
+ <!-- Config button -->
18
19
  <div class="text-center mt-3">
19
- <button type="button" class="btn btn-primary" id="configButton">⚙️ Config</button>
20
+ <button type="button" class="btn btn-primary" id="configButton" disabled>⚙️ Config</button>
20
21
  </div>
21
22
 
22
23
  <!-- Tabs -->
@@ -47,6 +48,17 @@
47
48
  const tabs = document.getElementById("accountTabs");
48
49
  const content = document.getElementById("accountTabsContent");
49
50
 
51
+ let configButtonState = false;
52
+ const configButton = document.getElementById('configButton');
53
+
54
+ function updateConfigButtonState(account) {
55
+ const hasMultipleDevices =
56
+ (account.ataDevices?.length || 0) > 1 ||
57
+ (account.atwDevices?.length || 0) > 1 ||
58
+ (account.ervDevices?.length || 0) > 1;
59
+ configButton.disabled = !hasMultipleDevices;
60
+ }
61
+
50
62
  function createAccountForm(account, i) {
51
63
  // Tab header
52
64
  const li = document.createElement("li");
@@ -127,45 +139,11 @@
127
139
  accounts.splice(i, 1);
128
140
  document.getElementById(`tab-li-${i}`).remove();
129
141
  document.getElementById(`pane-${i}`).remove();
130
-
131
- // Rebuild IDs
132
- const panes = document.querySelectorAll(".tab-pane");
133
- panes.forEach((p, index) => {
134
- p.id = `pane-${index}`;
135
- p.querySelector("form").id = `configForm-${index}`;
136
- p.querySelector(`[id^="name-"]`).id = `name-${index}`;
137
- p.querySelector(`[id^="user-"]`).id = `user-${index}`;
138
- p.querySelector(`[id^="passwd-"]`).id = `passwd-${index}`;
139
- p.querySelector(`[id^="language-"]`).id = `language-${index}`;
140
- p.querySelector(`[id^="logIn-"]`).id = `logIn-${index}`;
141
- p.querySelector(`[id^="remove-"]`).id = `remove-${index}`;
142
- });
143
- const tabButtons = document.querySelectorAll(".nav-link");
144
- tabButtons.forEach((btn, idx) => {
145
- btn.id = `tab-${idx}`;
146
- btn.dataset.bsTarget = `#pane-${idx}`;
147
- });
148
-
149
142
  await homebridge.updatePluginConfig(pluginConfig);
150
143
  await homebridge.savePluginConfig(pluginConfig);
151
-
152
144
  if (accounts.length > 0) new bootstrap.Tab(document.getElementById("tab-0")).show();
153
145
  });
154
146
 
155
- document.getElementById('configButton').addEventListener('click', async () => {
156
- if (this.configButtonState) {
157
- homebridge.hideSchemaForm();
158
- document.getElementById('configButton').className = "btn btn-secondary";
159
- } else {
160
- homebridge.showSchemaForm();
161
- document.getElementById('configButton').className = "btn btn-primary";
162
- }
163
- this.configButtonState = !this.configButtonState;
164
- });
165
-
166
- // Initialize state
167
- this.configButtonState = false;
168
-
169
147
  // Login button
170
148
  document.getElementById(`logIn-${i}`).addEventListener("click", async () => {
171
149
  homebridge.showSpinner();
@@ -204,31 +182,23 @@
204
182
  const atwDevices = account.atwDevices ?? (account.atwDevices = []);
205
183
  const ervDevices = account.ervDevices ?? (account.ervDevices = []);
206
184
 
207
- const removedAta = removeStaleDevices(ataDevices, devicesByType.ata);
208
- const removedAtw = removeStaleDevices(atwDevices, devicesByType.atw);
209
- const removedErv = removeStaleDevices(ervDevices, devicesByType.erv);
185
+ removeStaleDevices(ataDevices, devicesByType.ata);
186
+ removeStaleDevices(atwDevices, devicesByType.atw);
187
+ removeStaleDevices(ervDevices, devicesByType.erv);
210
188
 
211
189
  // Add new devices & presets
212
190
  function handleDevices(configArray, devicesArray, typeName, newDevicesArr, newPresetsArr) {
213
191
  devicesArray.forEach(d => {
214
- const existing = configArray.find(x => x.id === d.DeviceID);
192
+ let existing = configArray.find(x => x.id === d.DeviceID);
215
193
  if (!existing) {
216
- const devObj = {
217
- id: d.DeviceID,
218
- type: d.Type,
219
- typeString: typeName,
220
- name: d.DeviceName,
221
- displayMode: 1,
222
- presets: [],
223
- buttonsSensors: []
224
- };
225
- configArray.push(devObj);
226
- newDevicesArr.push(devObj);
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);
227
197
  }
228
198
  (d.Presets || []).forEach(p => {
229
199
  const preset = { ...p, id: p.ID, name: p.NumberDescription, displayType: 0, namePrefix: false };
230
- if (!existing?.presets.some(pr => pr.id === p.ID)) {
231
- existing?.presets.push(preset);
200
+ if (!existing.presets.some(pr => pr.id === p.ID)) {
201
+ existing.presets.push(preset);
232
202
  newPresetsArr.push(preset);
233
203
  }
234
204
  });
@@ -239,19 +209,17 @@
239
209
  handleDevices(atwDevices, devicesByType.atw, "Heat Pump", newDevices.atw, newDevices.atwPresets);
240
210
  handleDevices(ervDevices, devicesByType.erv, "ERV", newDevices.erv, newDevices.ervPresets);
241
211
 
242
- // Info display
212
+ // Update info
243
213
  function updateInfo(id, text, color) {
244
214
  const el = document.getElementById(id);
245
215
  if (el) { el.innerHTML = text; el.style.color = color; }
246
216
  }
247
217
 
248
218
  const textInfo = `Found devices: ATA(${newDevices.ata.length}), ATW(${newDevices.atw.length}), ERV(${newDevices.erv.length})`;
249
- const textPresets = `Found presets: ATA(${newDevices.ataPresets.length}), ATW(${newDevices.atwPresets.length}), ERV(${newDevices.ervPresets.length})`;
250
- const textRemoved = `Removed devices: ATA(${removedAta.length}), ATW(${removedAtw.length}), ERV(${removedErv.length})`;
219
+ updateInfo('info', textInfo, 'green');
251
220
 
252
- updateInfo('info', textInfo, newDevices.ata.length + newDevices.atw.length + newDevices.erv.length > 0 ? 'green' : 'white');
253
- updateInfo('info1', textPresets, newDevices.ataPresets.length + newDevices.atwPresets.length + newDevices.ervPresets.length > 0 ? 'green' : 'white');
254
- updateInfo('info2', textRemoved, removedAta.length + removedAtw.length + removedErv.length > 0 ? 'orange' : 'white');
221
+ // Update Config button state
222
+ updateConfigButtonState(account);
255
223
 
256
224
  await homebridge.updatePluginConfig(pluginConfig);
257
225
  await homebridge.savePluginConfig(pluginConfig);
@@ -273,7 +241,7 @@
273
241
  tabs.appendChild(addLi);
274
242
 
275
243
  document.getElementById("addTab").addEventListener("click", async () => {
276
- const newAccount = { name: "", user: "", passwd: "", language: 0 };
244
+ const newAccount = { name: "", user: "", passwd: "", language: 0, ataDevices: [{}], atwDevices: [{}], ervDevices: [{}] };
277
245
  accounts.push(newAccount);
278
246
  const i = accounts.length - 1;
279
247
  createAccountForm(newAccount, i);
@@ -282,6 +250,18 @@
282
250
  new bootstrap.Tab(document.getElementById(`tab-${i}`)).show();
283
251
  });
284
252
 
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
+
285
265
  })();
286
266
  </script>
287
267
  </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.10",
4
+ "version": "3.9.0-beta.12",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",