homebridge-melcloud-control 4.0.0-beta.233 → 4.0.0-beta.234

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.
@@ -109,65 +109,82 @@
109
109
 
110
110
  // 🧩 Deep clone — UI-safe copy (JSON method resets references)
111
111
  const pluginConfig = JSON.parse(JSON.stringify(config));
112
-
113
112
  this.accountIndex = 0;
114
- const accountsCount = pluginConfig[0].accounts.length;
113
+
114
+ const accounts = pluginConfig[0].accounts || [];
115
+ const accountsCount = accounts.length;
115
116
 
116
117
  const container = document.getElementById("accountButton");
117
118
  container.style.display = 'flex';
118
119
  container.style.flexWrap = 'wrap';
119
120
  container.style.justifyContent = 'center';
120
121
  container.style.gap = '0.25rem';
121
-
122
- for (let i = 0; i < accountsCount; i++) {
123
- const acc = pluginConfig[0].accounts[i];
122
+ container.style.alignItems = 'center';
123
+
124
+ const formElements = {
125
+ name: document.getElementById('name'),
126
+ user: document.getElementById('user'),
127
+ passwd: document.getElementById('passwd'),
128
+ language: document.getElementById('language'),
129
+ accountType: document.getElementById('accountType'),
130
+ logIn: document.getElementById('logIn'),
131
+ accountName: document.getElementById('accountName')
132
+ };
133
+
134
+ // Tworzenie przycisków
135
+ accounts.forEach((account, i) => {
124
136
  const button = document.createElement("button");
125
137
  button.type = "button";
126
138
  button.id = `button${i}`;
127
139
  button.className = "btn btn-primary";
128
140
  button.style.textTransform = 'none';
129
- button.innerText = acc.name;
141
+ button.innerText = account.name || `Account ${i + 1}`;
130
142
  container.appendChild(button);
131
143
 
132
144
  button.addEventListener('click', async () => {
133
- for (let j = 0; j < accountsCount; j++) {
134
- document.getElementById(`button${j}`).className = (j === i ? 'btn btn-primary' : 'btn btn-secondary');
135
- }
145
+ this.accountIndex = i;
136
146
 
137
- const acc = pluginConfig[0].accounts[i];
138
- document.getElementById('accountName').innerText = acc.name || '';
139
- document.getElementById('name').value = acc.name || '';
140
- document.getElementById('user').value = acc.user || '';
141
- document.getElementById('passwd').value = acc.passwd || '';
142
- document.getElementById('language').value = acc.language || '0';
143
- document.getElementById('accountType').value = acc.type || 'disabled';
144
- document.getElementById('logIn').disabled = !(acc.name && acc.user && acc.passwd && acc.language && acc.type);
145
- });
147
+ // Zmieniamy klasę wszystkich przycisków
148
+ accounts.forEach((_, j) => {
149
+ document.getElementById(`button${j}`).className = (j === i ? 'btn btn-primary' : 'btn btn-secondary');
150
+ });
146
151
 
147
- if (i === accountsCount - 1 && accountsCount > 0)
148
- document.getElementById(`button0`).click();
152
+ // Ustawiamy formularz
153
+ formElements.accountName.innerText = account.name || '';
154
+ formElements.name.value = account.name || '';
155
+ formElements.user.value = account.user || '';
156
+ formElements.passwd.value = account.passwd || '';
157
+ formElements.language.value = account.language || '0';
158
+ formElements.accountType.value = account.type || 'disabled';
149
159
 
150
- this.accountIndex = i;
151
- }
160
+ formElements.logIn.disabled = !(account.name && account.user && account.passwd && account.language && account.type);
161
+ });
162
+ });
152
163
 
153
- document.getElementById('melCloudAccount').style.display = 'block';
164
+ // Klikamy pierwszy przycisk po zakończeniu pętli
165
+ if (accountsCount > 0) document.getElementById('button0').click();
154
166
 
155
- // Safe update
167
+ // Jeden listener input dla całego formularza
156
168
  document.getElementById('configForm').addEventListener('input', async () => {
157
- const acc = pluginConfig[0].accounts[this.accountIndex];
158
- if (!acc) return;
159
- acc.name = document.querySelector('#name').value;
160
- acc.user = document.querySelector('#user').value;
161
- acc.passwd = document.querySelector('#passwd').value;
162
- acc.language = document.querySelector('#language').value;
163
- acc.type = document.querySelector('#accountType').value;
169
+ const account = accounts[this.accountIndex];
170
+ if (!account) return;
171
+
172
+ account.name = formElements.name.value;
173
+ account.user = formElements.user.value;
174
+ account.passwd = formElements.passwd.value;
175
+ account.language = formElements.language.value;
176
+ account.type = formElements.accountType.value;
164
177
 
165
- document.getElementById('logIn').disabled = !(acc.name && acc.user && acc.passwd && acc.language && acc.type);
178
+ formElements.logIn.disabled = !(account.name && account.user && account.passwd && account.language && account.type);
166
179
 
167
180
  await homebridge.updatePluginConfig(pluginConfig);
168
181
  await homebridge.savePluginConfig(pluginConfig);
169
182
  });
170
183
 
184
+ document.getElementById('melCloudAccount').style.display = 'block';
185
+
186
+
187
+
171
188
  // --- Config Button Toggle ---
172
189
  const configButton = document.getElementById('configButton');
173
190
  let configButtonState = false;
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.233",
4
+ "version": "4.0.0-beta.234",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",