-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from custom-cards/cors
📺 use new roku remote platform
- Loading branch information
Showing
4 changed files
with
157 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
if (!customElements.get("paper-input")) { | ||
console.log("imported", "paper-input"); | ||
import("https://unpkg.com/@polymer/paper-input/paper-input.js?module"); | ||
} | ||
|
||
const fireEvent = (node, type, detail, options) => { | ||
options = options || {}; | ||
detail = detail === null || detail === undefined ? {} : detail; | ||
const event = new Event(type, { | ||
bubbles: options.bubbles === undefined ? true : options.bubbles, | ||
cancelable: Boolean(options.cancelable), | ||
composed: options.composed === undefined ? true : options.composed | ||
}); | ||
event.detail = detail; | ||
node.dispatchEvent(event); | ||
return event; | ||
}; | ||
|
||
const LitElement = Object.getPrototypeOf( | ||
customElements.get("ha-panel-lovelace") | ||
); | ||
const html = LitElement.prototype.html; | ||
|
||
export class RokuCardEditor extends LitElement { | ||
setConfig(config) { | ||
this._config = config; | ||
} | ||
|
||
static get properties() { | ||
return { hass: {}, _config: {} }; | ||
} | ||
|
||
get _name() { | ||
return this._config.name || ""; | ||
} | ||
|
||
|
||
get _entity() { | ||
return this._config.entity || ""; | ||
} | ||
|
||
render() { | ||
if (!this.hass) { | ||
return html``; | ||
} | ||
|
||
return html` | ||
<div class="card-config"> | ||
<div class="side-by-side"> | ||
<paper-input | ||
label="Name" | ||
.value="${this._name}" | ||
.configValue="${"name"}" | ||
@value-changed="${this._valueChanged}" | ||
></paper-input> | ||
${ | ||
customElements.get("ha-entity-picker") | ||
? html` | ||
<ha-entity-picker | ||
.hass="${this.hass}" | ||
.value="${this._entity}" | ||
.configValue=${"entity"} | ||
domain-filter="media_player" | ||
@change="${this._valueChanged}" | ||
allow-custom-entity | ||
></ha-entity-picker> | ||
` | ||
: html` | ||
<paper-input | ||
label="Entity" | ||
.value="${this._entity}" | ||
.configValue="${"entity"}" | ||
@value-changed="${this._valueChanged}" | ||
></paper-input> | ||
` | ||
} | ||
</div> | ||
</div> | ||
`; | ||
} | ||
|
||
_valueChanged(ev) { | ||
if (!this._config || !this.hass) { | ||
return; | ||
} | ||
const target = ev.target; | ||
if (this[`_${target.configValue}`] === target.value) { | ||
return; | ||
} | ||
if (target.configValue) { | ||
if (target.value === "") { | ||
delete this._config[target.configValue]; | ||
} else { | ||
this._config = { | ||
...this._config, | ||
[target.configValue]: target.value | ||
}; | ||
} | ||
} | ||
fireEvent(this, "config-changed", { config: this._config }); | ||
} | ||
} | ||
|
||
customElements.define("roku-card-editor", RokuCardEditor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters