filter disabled hardware integrations (#14964)

This commit is contained in:
Bram Kragten 2023-01-16 07:10:36 +01:00 committed by GitHub
parent 932614e31a
commit 21f3eb9103
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,6 +39,7 @@ import {
rebootHost, rebootHost,
shutdownHost, shutdownHost,
} from "../../../data/hassio/host"; } from "../../../data/hassio/host";
import { scanUSBDevices } from "../../../data/usb";
import { showOptionsFlowDialog } from "../../../dialogs/config-flow/show-dialog-options-flow"; import { showOptionsFlowDialog } from "../../../dialogs/config-flow/show-dialog-options-flow";
import { import {
showAlertDialog, showAlertDialog,
@ -219,6 +220,10 @@ class HaConfigHardware extends SubscribeMixin(LitElement) {
} }
protected render(): TemplateResult { protected render(): TemplateResult {
if (!this._configEntries) {
return html``;
}
let boardId: string | undefined; let boardId: string | undefined;
let boardName: string | undefined; let boardName: string | undefined;
let imageURL: string | undefined; let imageURL: string | undefined;
@ -230,13 +235,22 @@ class HaConfigHardware extends SubscribeMixin(LitElement) {
); );
const dongles = this._hardwareInfo?.hardware.filter( const dongles = this._hardwareInfo?.hardware.filter(
(hw) => hw.dongle !== null (hw) =>
hw.dongle !== null &&
(!hw.config_entries.length ||
hw.config_entries.some(
(entryId) =>
this._configEntries![entryId] &&
!this._configEntries![entryId].disabled_by
))
); );
if (boardData) { if (boardData) {
boardConfigEntries = boardData.config_entries boardConfigEntries = boardData.config_entries
.map((id) => this._configEntries?.[id]) .map((id) => this._configEntries![id])
.filter((entry) => entry?.supports_options) as ConfigEntry[]; .filter(
(entry) => entry?.supports_options && !entry.disabled_by
) as ConfigEntry[];
boardId = boardData.board!.hassio_board_id; boardId = boardData.board!.hassio_board_id;
boardName = boardData.name; boardName = boardData.name;
documentationURL = boardData.url; documentationURL = boardData.url;
@ -362,8 +376,10 @@ class HaConfigHardware extends SubscribeMixin(LitElement) {
? html`<ha-card> ? html`<ha-card>
${dongles.map((dongle) => { ${dongles.map((dongle) => {
const configEntry = dongle.config_entries const configEntry = dongle.config_entries
.map((id) => this._configEntries?.[id]) .map((id) => this._configEntries![id])
.filter((entry) => entry?.supports_options)[0]; .filter(
(entry) => entry?.supports_options && !entry.disabled_by
)[0];
return html`<div class="row"> return html`<div class="row">
${dongle.name}${configEntry ${dongle.name}${configEntry
? html`<mwc-button ? html`<mwc-button
@ -444,6 +460,10 @@ class HaConfigHardware extends SubscribeMixin(LitElement) {
} }
private async _load() { private async _load() {
if (isComponentLoaded(this.hass, "usb")) {
await scanUSBDevices(this.hass);
}
const isHassioLoaded = isComponentLoaded(this.hass, "hassio"); const isHassioLoaded = isComponentLoaded(this.hass, "hassio");
try { try {
if (isComponentLoaded(this.hass, "hardware")) { if (isComponentLoaded(this.hass, "hardware")) {