From 9f7ffca2fe4b69483511f880329953125d71308d Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Sun, 3 Nov 2019 22:39:34 -0600 Subject: [PATCH] make entity not required --- dist/roku-card.js | 12 +++++++----- src/roku-card.ts | 12 ++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/dist/roku-card.js b/dist/roku-card.js index 1d08a43..e26ab11 100644 --- a/dist/roku-card.js +++ b/dist/roku-card.js @@ -3051,7 +3051,7 @@ const actionHandler = directive((options = {}) => (part) => { actionHandlerBind(part.committer.element, options); }); -const CARD_VERSION = '1.0.4'; +const CARD_VERSION = '1.0.5'; const defaultRemoteAction = { action: "call-service", @@ -3064,8 +3064,8 @@ let RokuCard = class RokuCard extends LitElement { return 7; } setConfig(config) { - if (!config.entity) { - console.log("Invalid configuration"); + if (!config.entity && !config.remote) { + console.log("Invalid configuration. If no entity provided, you'll need to provide a remote entity"); return; } this._config = Object.assign({ theme: "default" }, config); @@ -3075,7 +3075,7 @@ let RokuCard = class RokuCard extends LitElement { return html ``; } const stateObj = this.hass.states[this._config.entity]; - if (!stateObj) { + if (this._config.entity && !stateObj) { return html `
Entity Unavailable
@@ -3086,7 +3086,9 @@ let RokuCard = class RokuCard extends LitElement {
-
${stateObj.attributes.app_name}
+
+ ${stateObj ? stateObj.attributes.app_name : ""} +
${this._config.tv || (this._config.power && this._config.power.show) ? this._renderButton("power", "mdi:power", "Power") : ""} diff --git a/src/roku-card.ts b/src/roku-card.ts index 03d92db..cac03c4 100644 --- a/src/roku-card.ts +++ b/src/roku-card.ts @@ -40,8 +40,10 @@ class RokuCard extends LitElement { } public setConfig(config: RokuCardConfig): void { - if (!config.entity) { - console.log("Invalid configuration"); + if (!config.entity && !config.remote) { + console.log( + "Invalid configuration. If no entity provided, you'll need to provide a remote entity" + ); return; } @@ -58,7 +60,7 @@ class RokuCard extends LitElement { const stateObj = this.hass!.states[this._config.entity]; - if (!stateObj) { + if (this._config.entity && !stateObj) { return html`
Entity Unavailable
@@ -70,7 +72,9 @@ class RokuCard extends LitElement {
-
${stateObj.attributes.app_name}
+
+ ${stateObj ? stateObj.attributes.app_name : ""} +
${this._config.tv || (this._config.power && this._config.power.show) ? this._renderButton("power", "mdi:power", "Power") : ""}