homebridge-midea-platform 1.2.6-beta.7 → 1.2.6-beta.9

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.
@@ -199,6 +199,7 @@
199
199
  createForm(configSchema, configuration);
200
200
  homebridge.hideSpinner();
201
201
 
202
+ const main = document.getElementById('main');
202
203
  const loginSection = document.getElementById('login')
203
204
  const userPass = document.getElementById('userPass');
204
205
 
@@ -286,27 +287,64 @@
286
287
  download_btn.className = 'btn btn-outline-secondary btn-sm';
287
288
  download_btn.addEventListener('click', async () => {
288
289
  try {
290
+ homebridge.showSpinner();
289
291
  const file_data_str = await homebridge.request('/downloadLua', { deviceType: device.type, deviceSn: device.sn });
290
- const blob = new Blob([file_data_str], { type: 'text/plain' });
291
292
 
292
- const dataUrl = 'data:text/plain;charset=utf-8,' + encodeURIComponent(file_data_str);
293
-
294
- const a = document.createElement('a');
295
- a.href = dataUrl;
296
- a.download = `${device.type.toString(16)}_${device.model}.lua`;
293
+ const modal = document.createElement("div");
294
+ modal.className = 'modal fade';
295
+ modal.id = 'luaCodeModal';
296
+ modal.setAttribute('tabindex', '-1');
297
+ modal.setAttribute('aria-labelledby', 'luaCodeModalLabel');
298
+ modal.setAttribute('aria-hidden', 'true');
299
+
300
+ modal.innerHTML = `
301
+ <div class="modal-dialog modal-lg modal-dialog-scrollable">
302
+ <div class="modal-content">
303
+ <div class="modal-header">
304
+ <h5 class="modal-title" id="luaCodeModalLabel">Lua Code for ${device.model}</h5>
305
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
306
+ </div>
307
+ <div class="modal-body">
308
+ <div class="mb-3 btn-toolbar">
309
+ <div class="btn-group me-2">
310
+ <button id="selectAllLuaBtn" class="btn btn-secondary">Select All</button>
311
+ </div>
312
+ <small class="text-warning ms-2 align-self-center">Save this as ${device.type.toString(16)}_${device.model}.lua</small>
313
+ </div>
314
+ <pre id="luaCodePre"><code style="color: var(--bs-body-color);">${file_data_str}</code></pre>
315
+ </div>
316
+ <div class="modal-footer">
317
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
318
+ </div>
319
+ </div>
320
+ </div>
321
+ `;
322
+
323
+ main.appendChild(modal);
324
+
325
+ // Initialize the Bootstrap modal
326
+ const bootstrapModal = new bootstrap.Modal(modal);
327
+ bootstrapModal.show();
328
+
329
+ document.getElementById('selectAllLuaBtn').addEventListener('click', () => {
330
+ const codeElement = document.getElementById('luaCodePre');
331
+ const selection = window.getSelection();
332
+ const range = document.createRange();
333
+
334
+ range.selectNodeContents(codeElement);
335
+ selection.removeAllRanges();
336
+ selection.addRange(range);
337
+ });
297
338
 
298
- document.body.appendChild(a);
339
+ // Clean up when modal is hidden
340
+ modal.addEventListener('hidden.bs.modal', () => {
341
+ main.removeChild(modal);
342
+ });
299
343
 
300
- a.dispatchEvent(
301
- new MouseEvent('click', {
302
- bubbles: true,
303
- cancelable: true,
304
- view: window
305
- })
306
- );
344
+ homebridge.hideSpinner();
307
345
 
308
- document.body.removeChild(a);
309
346
  } catch (e) {
347
+ homebridge.hideSpinner();
310
348
  homebridge.toast.error(e.message);
311
349
  }
312
350
  });
@@ -253,8 +253,10 @@ class UiServer extends HomebridgePluginUiServer {
253
253
  msg: 'Start device discovery',
254
254
  });
255
255
  // If IP addresses provided then probe them directly
256
- for (const ip of ipAddrs) {
257
- discover.discoverDeviceByIP(ip);
256
+ if (ipAddrs && ipAddrs.length > 0) {
257
+ for (const ip of ipAddrs) {
258
+ discover.discoverDeviceByIP(ip);
259
+ }
258
260
  }
259
261
  // And then send broadcast to network(s)
260
262
  discover.startDiscover();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "displayName": "Homebridge Midea Platform",
3
3
  "name": "homebridge-midea-platform",
4
4
  "type": "module",
5
- "version": "1.2.6-beta.7",
5
+ "version": "1.2.6-beta.9",
6
6
  "description": "Homebridge plugin for Midea devices",
7
7
  "license": "Apache-2.0",
8
8
  "repository": {