Media Player Row: Fix State Translation (#5881)

* Fix for state display translation

* Comments
This commit is contained in:
Zack Arnett 2020-05-14 12:38:43 -04:00 committed by GitHub
parent 7ce0b34774
commit 349355584a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,13 +25,15 @@ import {
SUPPORT_VOLUME_BUTTONS, SUPPORT_VOLUME_BUTTONS,
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET, SUPPORT_VOLUME_SET,
computeMediaDescription,
} from "../../../data/media-player"; } from "../../../data/media-player";
import { HomeAssistant } from "../../../types"; import type { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-generic-entity-row"; import "../components/hui-generic-entity-row";
import "../components/hui-warning"; import "../components/hui-warning";
import { EntityConfig, LovelaceRow } from "./types"; import type { EntityConfig, LovelaceRow } from "./types";
import { installResizeObserver } from "../common/install-resize-observer"; import { installResizeObserver } from "../common/install-resize-observer";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
@customElement("hui-media-player-entity-row") @customElement("hui-media-player-entity-row")
class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow { class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
@ -128,11 +130,14 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
: ""} : ""}
`; `;
const mediaDescription = computeMediaDescription(stateObj);
return html` return html`
<hui-generic-entity-row <hui-generic-entity-row
.hass=${this.hass} .hass=${this.hass}
.config=${this._config} .config=${this._config}
.secondaryText=${this._computeMediaTitle(stateObj)} .secondaryText=${mediaDescription ||
computeStateDisplay(this.hass.localize, stateObj, this.hass.language)}
> >
<div class="controls"> <div class="controls">
${supportsFeature(stateObj, SUPPORT_TURN_ON) && ${supportsFeature(stateObj, SUPPORT_TURN_ON) &&
@ -230,30 +235,6 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
: "hass:stop"; : "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 { private _togglePower(): void {
const stateObj = this.hass!.states[this._config!.entity]; const stateObj = this.hass!.states[this._config!.entity];