Skip to content

Commit

Permalink
make entity not required
Browse files Browse the repository at this point in the history
  • Loading branch information
iantrich committed Nov 4, 2019
1 parent c9f47fb commit 9f7ffca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 7 additions & 5 deletions dist/roku-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
Expand All @@ -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 `
<ha-card>
<div class="warning">Entity Unavailable</div>
Expand All @@ -3086,7 +3086,9 @@ let RokuCard = class RokuCard extends LitElement {
<ha-card .header="${this._config.name}">
<div class="remote">
<div class="row">
<div class="app">${stateObj.attributes.app_name}</div>
<div class="app">
${stateObj ? stateObj.attributes.app_name : ""}
</div>
${this._config.tv || (this._config.power && this._config.power.show)
? this._renderButton("power", "mdi:power", "Power")
: ""}
Expand Down
12 changes: 8 additions & 4 deletions src/roku-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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`
<ha-card>
<div class="warning">Entity Unavailable</div>
Expand All @@ -70,7 +72,9 @@ class RokuCard extends LitElement {
<ha-card .header="${this._config.name}">
<div class="remote">
<div class="row">
<div class="app">${stateObj.attributes.app_name}</div>
<div class="app">
${stateObj ? stateObj.attributes.app_name : ""}
</div>
${this._config.tv || (this._config.power && this._config.power.show)
? this._renderButton("power", "mdi:power", "Power")
: ""}
Expand Down

0 comments on commit 9f7ffca

Please sign in to comment.