Skip to content

Commit 2c24403

Browse files
authored
Fix devices tab in UI (#1331)
This fixes the loading of the devices tab. The dynamic config tab is still broken, and it looks like some UI elements mistakenly appear in the devices tab.
1 parent c61acc5 commit 2c24403

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/homebridge-ui/public/index.html

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
</tr>
8585
</tbody>
8686
</table>
87+
<h5 class="mt-4">Cached Accessories</h5>
88+
<ul id="cachedAccessoriesList"></ul>
8789
<p class="text-center">External accessories will not be displayed here.</p>
8890
</div>
8991
</div>
@@ -122,7 +124,7 @@ <h5>Features</h5>
122124
<h5>Help/About</h5>
123125
<ul>
124126
<li>
125-
<a href="https://
127+
<a href="https://github.com/OpenWonderLabs/homebridge-switchbot/issues/new/choose" target="_blank">Support
126128
Request</a>
127129
</li>
128130
<li>
@@ -266,7 +268,7 @@ <h2>Dynamic Config</h2>
266268
currentConfig[0].options.devices = [];
267269
}
268270
currentConfig[0].options.devices.push({
269-
deviceId,
271+
deviceId: deviceId.replace(/:/g, ''),
270272
hide_device: false,
271273
disablePlatformBLE: false,
272274
allowPush: false,
@@ -307,19 +309,23 @@ <h2>Dynamic Config</h2>
307309

308310
const updateTableWithDetails = (deviceContext) => {
309311
const tableBody = document.querySelector('#deviceTable tbody');
310-
tableBody.innerHTML = '';
311312

312313
Object.entries(deviceContext).forEach(([key, value]) => {
313-
if (value !== undefined && value !== null && String(value).trim() !== '') {
314-
const row = document.createElement('tr');
315-
const keyCell = document.createElement('th');
316-
keyCell.scope = 'row';
317-
keyCell.textContent = key;
318-
const valueCell = document.createElement('td');
319-
valueCell.textContent = value;
320-
row.appendChild(keyCell);
321-
row.appendChild(valueCell);
322-
tableBody.appendChild(row);
314+
if (/string|number|boolean/.test(typeof value) && (typeof value !== 'string' || value.trim())) {
315+
let existingCell = document.getElementById(key);
316+
if (existingCell) {
317+
existingCell.textContent = value;
318+
} else {
319+
const row = document.createElement('tr');
320+
const keyCell = document.createElement('th');
321+
keyCell.scope = 'row';
322+
keyCell.textContent = key;
323+
const valueCell = document.createElement('td');
324+
valueCell.textContent = value;
325+
row.appendChild(keyCell);
326+
row.appendChild(valueCell);
327+
tableBody.appendChild(row);
328+
}
323329
}
324330
});
325331
};

0 commit comments

Comments
 (0)