From 349355584aa7d13b3113cdd96b57e57f2583df5d Mon Sep 17 00:00:00 2001 From: Zack Arnett Date: Thu, 14 May 2020 12:38:43 -0400 Subject: [PATCH] Media Player Row: Fix State Translation (#5881) * Fix for state display translation * Comments --- .../hui-media-player-entity-row.ts | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts index 3792aef585..a3a41ba6d2 100644 --- a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts +++ b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts @@ -25,13 +25,15 @@ import { SUPPORT_VOLUME_BUTTONS, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, + computeMediaDescription, } from "../../../data/media-player"; -import { HomeAssistant } from "../../../types"; +import type { HomeAssistant } from "../../../types"; import { hasConfigOrEntityChanged } from "../common/has-changed"; import "../components/hui-generic-entity-row"; import "../components/hui-warning"; -import { EntityConfig, LovelaceRow } from "./types"; +import type { EntityConfig, LovelaceRow } from "./types"; import { installResizeObserver } from "../common/install-resize-observer"; +import { computeStateDisplay } from "../../../common/entity/compute_state_display"; @customElement("hui-media-player-entity-row") class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow { @@ -128,11 +130,14 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow { : ""} `; + const mediaDescription = computeMediaDescription(stateObj); + return html`
${supportsFeature(stateObj, SUPPORT_TURN_ON) && @@ -230,30 +235,6 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow { : "hass:stop"; } - private _computeMediaTitle(stateObj: HassEntity): string { - let prefix; - let suffix; - - switch (stateObj.attributes.media_content_type) { - case "music": - prefix = stateObj.attributes.media_artist; - suffix = stateObj.attributes.media_title; - break; - case "tvshow": - prefix = stateObj.attributes.media_series_title; - suffix = stateObj.attributes.media_title; - break; - default: - prefix = - stateObj.attributes.media_title || - stateObj.attributes.app_name || - stateObj.state; - suffix = ""; - } - - return prefix && suffix ? `${prefix}: ${suffix}` : prefix || suffix || ""; - } - private _togglePower(): void { const stateObj = this.hass!.states[this._config!.entity];