Fixes removing audio device (#4763)

(only the supervisor doesn't support it)
This commit is contained in:
Bram Kragten 2020-02-05 18:21:43 +01:00 committed by GitHub
parent aac7dbab58
commit c7f7ef28bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 16 deletions

View File

@ -128,16 +128,12 @@ class HassioAddonAudio extends LitElement {
private _setInputDevice(ev): void { private _setInputDevice(ev): void {
const device = ev.detail.item.getAttribute("device"); const device = ev.detail.item.getAttribute("device");
if (device) { this._selectedInput = device || null;
this._selectedInput = device;
}
} }
private _setOutputDevice(ev): void { private _setOutputDevice(ev): void {
const device = ev.detail.item.getAttribute("device"); const device = ev.detail.item.getAttribute("device");
if (device) { this._selectedOutput = device || null;
this._selectedOutput = device;
}
} }
private async _addonChanged(): Promise<void> { private async _addonChanged(): Promise<void> {
@ -147,13 +143,11 @@ class HassioAddonAudio extends LitElement {
return; return;
} }
const noDevice: HassioHardwareAudioDevice[] = [ const noDevice: HassioHardwareAudioDevice = { device: null, name: "-" };
{ device: undefined, name: "-" },
];
try { try {
const { audio } = await fetchHassioHardwareAudio(this.hass); const { audio } = await fetchHassioHardwareAudio(this.hass);
const inupt = Object.keys(audio.input).map((key) => ({ const input = Object.keys(audio.input).map((key) => ({
device: key, device: key,
name: audio.input[key], name: audio.input[key],
})); }));
@ -162,12 +156,12 @@ class HassioAddonAudio extends LitElement {
name: audio.output[key], name: audio.output[key],
})); }));
this._inputDevices = noDevice.concat(inupt); this._inputDevices = [noDevice, ...input];
this._outputDevices = noDevice.concat(output); this._outputDevices = [noDevice, ...output];
} catch { } catch {
this._error = "Failed to fetch audio hardware"; this._error = "Failed to fetch audio hardware";
this._inputDevices = noDevice; this._inputDevices = [noDevice];
this._outputDevices = noDevice; this._outputDevices = [noDevice];
} }
} }

View File

@ -2,12 +2,15 @@ import { HomeAssistant } from "../../types";
import { HassioResponse, hassioApiResultExtractor } from "./common"; import { HassioResponse, hassioApiResultExtractor } from "./common";
export interface HassioHardwareAudioDevice { export interface HassioHardwareAudioDevice {
device?: string; device?: string | null;
name: string; name: string;
} }
interface HassioHardwareAudioList { interface HassioHardwareAudioList {
audio: { input: any; output: any }; audio: {
input: { [key: string]: string };
output: { [key: string]: string };
};
} }
export interface HassioHardwareInfo { export interface HassioHardwareInfo {