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

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