From c7f7ef28bfaaa21b38fbe65bbe93d80b01cbfcda Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 5 Feb 2020 18:21:43 +0100 Subject: [PATCH] Fixes removing audio device (#4763) (only the supervisor doesn't support it) --- hassio/src/addon-view/hassio-addon-audio.ts | 22 ++++++++------------- src/data/hassio/hardware.ts | 7 +++++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/hassio/src/addon-view/hassio-addon-audio.ts b/hassio/src/addon-view/hassio-addon-audio.ts index d41e7ee11c..84357963b4 100644 --- a/hassio/src/addon-view/hassio-addon-audio.ts +++ b/hassio/src/addon-view/hassio-addon-audio.ts @@ -128,16 +128,12 @@ class HassioAddonAudio extends LitElement { private _setInputDevice(ev): void { const device = ev.detail.item.getAttribute("device"); - if (device) { - this._selectedInput = device; - } + this._selectedInput = device || null; } private _setOutputDevice(ev): void { const device = ev.detail.item.getAttribute("device"); - if (device) { - this._selectedOutput = device; - } + this._selectedOutput = device || null; } private async _addonChanged(): Promise { @@ -147,13 +143,11 @@ class HassioAddonAudio extends LitElement { return; } - const noDevice: HassioHardwareAudioDevice[] = [ - { device: undefined, name: "-" }, - ]; + const noDevice: HassioHardwareAudioDevice = { device: null, name: "-" }; try { const { audio } = await fetchHassioHardwareAudio(this.hass); - const inupt = Object.keys(audio.input).map((key) => ({ + const input = Object.keys(audio.input).map((key) => ({ device: key, name: audio.input[key], })); @@ -162,12 +156,12 @@ class HassioAddonAudio extends LitElement { name: audio.output[key], })); - this._inputDevices = noDevice.concat(inupt); - this._outputDevices = noDevice.concat(output); + this._inputDevices = [noDevice, ...input]; + this._outputDevices = [noDevice, ...output]; } catch { this._error = "Failed to fetch audio hardware"; - this._inputDevices = noDevice; - this._outputDevices = noDevice; + this._inputDevices = [noDevice]; + this._outputDevices = [noDevice]; } } diff --git a/src/data/hassio/hardware.ts b/src/data/hassio/hardware.ts index ee18581f2b..98a4b3ca57 100644 --- a/src/data/hassio/hardware.ts +++ b/src/data/hassio/hardware.ts @@ -2,12 +2,15 @@ import { HomeAssistant } from "../../types"; import { HassioResponse, hassioApiResultExtractor } from "./common"; export interface HassioHardwareAudioDevice { - device?: string; + device?: string | null; name: string; } interface HassioHardwareAudioList { - audio: { input: any; output: any }; + audio: { + input: { [key: string]: string }; + output: { [key: string]: string }; + }; } export interface HassioHardwareInfo {