Only add a separating colon if there is a valid prefix and suffix (#2060)

This commit changes the media player entity row to only add a colon
separator to the status line when there is both a prefix and a suffix.
This commit is contained in:
Jack Wilsdon 2018-11-19 10:59:10 +00:00 committed by Paulus Schoutsen
parent f92f89e8e8
commit 1bb62bfc05

View File

@ -103,22 +103,27 @@ class HuiMediaPlayerEntityRow extends LocalizeMixin(PolymerElement) {
_computeMediaTitle(stateObj) {
if (!stateObj || this._isOff(stateObj.state)) return null;
let prefix;
let suffix;
switch (stateObj.attributes.media_content_type) {
case "music":
return `${stateObj.attributes.media_artist}: ${
stateObj.attributes.media_title
}`;
prefix = stateObj.attributes.media_artist;
suffix = stateObj.attributes.media_title;
break;
case "tvshow":
return `${stateObj.attributes.media_series_title}: ${
stateObj.attributes.media_title
}`;
prefix = stateObj.attributes.media_series_title;
suffix = stateObj.attributes.media_title;
break;
default:
return (
prefix =
stateObj.attributes.media_title ||
stateObj.attributes.app_name ||
stateObj.state
);
stateObj.state;
suffix = "";
}
return prefix && suffix ? `${prefix}: ${suffix}` : prefix || suffix || "";
}
_computeState(state) {