From b31099c650a5e74aed40ce93c8b56ff6435260ab Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Fri, 25 Jan 2019 12:33:45 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=BA=20added=20card=20theme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- roku-card-editor.js | 26 +++++++++++++++++++++-- roku-card.js | 51 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4696303..24d095a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -[![Version](https://img.shields.io/badge/version-0.0.2-green.svg?style=for-the-badge)](#) [![mantained](https://img.shields.io/maintenance/yes/2019.svg?style=for-the-badge)](#) +[![Version](https://img.shields.io/badge/version-0.0.3-green.svg?style=for-the-badge)](#) [![mantained](https://img.shields.io/maintenance/yes/2019.svg?style=for-the-badge)](#) [![maintainer](https://img.shields.io/badge/maintainer-Ian%20Richardson%20%40iantrich-blue.svg?style=for-the-badge)](#) @@ -23,6 +23,7 @@ This card is for [Lovelace](https://www.home-assistant.io/lovelace) on [Home Ass | type | string | **Required** | `custom:roku-card` | entity | string | **Required** | `media_player` entity of Roku device | name | string | **Optional** | Card name +| theme | string | **Optional** | Card theme ## Installation @@ -56,6 +57,7 @@ Add a custom element in your `ui-lovelace.yaml` - type: custom:roku-card entity: media_player.bedroom_tv name: Bedroom TV + theme: darkpurple ``` [Troubleshooting](https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins) diff --git a/roku-card-editor.js b/roku-card-editor.js index f10fec2..a278fe0 100644 --- a/roku-card-editor.js +++ b/roku-card-editor.js @@ -34,11 +34,14 @@ export class RokuCardEditor extends LitElement { return this._config.name || ""; } - get _entity() { return this._config.entity || ""; } + get _theme() { + return this._config.theme || "default"; + } + render() { if (!this.hass) { return html``; @@ -74,6 +77,25 @@ export class RokuCardEditor extends LitElement { > ` } + ${ + customElements.get("hui-theme-select-editor") + ? html` + + ` + : html` + + ` + } `; @@ -101,4 +123,4 @@ export class RokuCardEditor extends LitElement { } } -customElements.define("roku-card-editor", RokuCardEditor); \ No newline at end of file +customElements.define("roku-card-editor", RokuCardEditor); diff --git a/roku-card.js b/roku-card.js index 409048f..9b0a370 100644 --- a/roku-card.js +++ b/roku-card.js @@ -31,7 +31,7 @@ class RokuCard extends LitElement { return; } - this._config = config; + this._config = { theme: "default", ...config }; } render() { @@ -152,6 +152,17 @@ class RokuCard extends LitElement { `; } + updated(changedProps) { + if (!this._config) { + return; + } + + const oldHass = changedProps.get("hass"); + if (!oldHass || oldHass.themes !== this.hass.themes) { + this.applyThemesOnElement(this, this.hass.themes, this._config.theme); + } + } + renderStyle() { return html`