From 613da8367450ca0847bfd61bd04a52cef5dd10cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Mon, 3 May 2021 16:07:46 +0200 Subject: [PATCH] Add: Hide play button if unsupported entity given --- plex-meets-homeassistant.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/plex-meets-homeassistant.js b/plex-meets-homeassistant.js index c539259..4fa7dd5 100644 --- a/plex-meets-homeassistant.js +++ b/plex-meets-homeassistant.js @@ -11,6 +11,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { requestTimeout = 3000; loading = false; maxCount = false; + playSupported = false; escapeHtml = (unsafe) => { return unsafe @@ -58,7 +59,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.detailElem = document.createElement("div"); this.detailElem.className = "detail"; this.detailElem.innerHTML = - "

"; + "

"; this.content.appendChild(this.detailElem); //todo: figure out why timeout is needed here and do it properly @@ -90,6 +91,12 @@ class PlexMeetsHomeAssistant extends HTMLElement { set hass(hass) { if (!this.content) { + this.playSupported = + hass.states[this.config.entity_id] && + hass.states[this.config.entity_id].attributes && + hass.states[this.config.entity_id].attributes.adb_response !== + undefined; + const _this = this; this.error = ""; if (!this.loading) { @@ -225,6 +232,12 @@ class PlexMeetsHomeAssistant extends HTMLElement { art: title.attributes.art ? title.attributes.art.textContent : undefined, + contentRating: title.attributes.contentRating + ? title.attributes.contentRating.textContent + : undefined, + duration: title.attributes.duration + ? title.attributes.duration.textContent + : undefined, }); }); }); @@ -310,7 +323,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { _this.detailElem.children[0].innerHTML = _this.escapeHtml(data.title); _this.detailElem.children[1].innerHTML = _this.escapeHtml(data.year); - _this.detailElem.children[2].innerHTML = _this.escapeHtml(data.summary); + _this.detailElem.children[2].innerHTML = + _this.escapeHtml(data.duration) / 60 / 1000 + " min"; + _this.detailElem.children[3].innerHTML = _this.escapeHtml(data.summary); _this.detailElem.style.color = "rgba(255,255,255,1)"; _this.detailElem.style["z-index"] = "4"; }, 1); @@ -352,6 +367,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { const movieElem = document.createElement("div"); movieElem.className = "movieElem"; + movieElem.style = "width:" + this.width + @@ -360,6 +376,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { "px; background-image: url('" + thumbURL + "'); "; + if (!this.playSupported) { + movieElem.style.cursor = "pointer"; + } movieElem.addEventListener("click", function (event) { console.log(data); @@ -396,7 +415,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { const playButton = this.getPlayButton(); const interactiveArea = document.createElement("div"); interactiveArea.className = "interactiveArea"; - interactiveArea.append(playButton); + if (this.playSupported) { + interactiveArea.append(playButton); + } movieElem.append(interactiveArea); @@ -439,6 +460,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { let style = document.createElement("style"); style.textContent = ` + .detail .metaInfo { + display: block; + } .detail h2 { text-overflow: ellipsis; white-space: nowrap;