From cde106bd7793c4bb77fe32570542c4668cf86a53 Mon Sep 17 00:00:00 2001 From: Jerad Meisner Date: Thu, 23 Aug 2018 13:24:21 -0700 Subject: [PATCH] Fix custom icon colors in entities and glance cards. (#1587) * Fix custom icon colors in entities and glance cards. * Use ha-icon directly in state-badge. --- gallery/src/demos/demo-hui-entities-card.js | 4 ++- gallery/src/demos/demo-hui-glance-card.js | 3 +- src/components/entity/state-badge.js | 35 ++++++++++++------- src/panels/lovelace/cards/hui-glance-card.js | 14 +++----- .../components/hui-generic-entity-row.js | 14 +++----- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/gallery/src/demos/demo-hui-entities-card.js b/gallery/src/demos/demo-hui-entities-card.js index d79e8ba05c..3f7d7af134 100644 --- a/gallery/src/demos/demo-hui-entities-card.js +++ b/gallery/src/demos/demo-hui-entities-card.js @@ -140,7 +140,9 @@ const CONFIGS = [ - entity: group.kitchen icon: mdi:home-assistant - lock.kitchen_door - - light.bed_light + - entity: light.bed_light + icon: mdi:alarm-light + name: Bed Light Custom Icon - climate.ecobee - input_number.noise_allowance title: Random group diff --git a/gallery/src/demos/demo-hui-glance-card.js b/gallery/src/demos/demo-hui-glance-card.js index 6ba056d32a..5265c51802 100644 --- a/gallery/src/demos/demo-hui-glance-card.js +++ b/gallery/src/demos/demo-hui-glance-card.js @@ -105,7 +105,8 @@ const CONFIGS = [ - media_player.living_room - sun.sun - cover.kitchen_window - - light.kitchen_lights + - entity: light.kitchen_lights + icon: mdi:alarm-light - lock.kitchen_door - light.ceiling_lights ` diff --git a/src/components/entity/state-badge.js b/src/components/entity/state-badge.js index 1efd6c6dd7..814454924f 100644 --- a/src/components/entity/state-badge.js +++ b/src/components/entity/state-badge.js @@ -1,8 +1,9 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js'; -import './ha-state-icon.js'; +import '../ha-icon.js'; import computeStateDomain from '../../common/entity/compute_state_domain.js'; +import stateIcon from '../../common/entity/state_icon.js'; class StateBadge extends PolymerElement { static get template() { @@ -20,26 +21,31 @@ class StateBadge extends PolymerElement { line-height: 40px; } - ha-state-icon { + ha-icon { transition: color .3s ease-in-out, filter .3s ease-in-out; } /* Color the icon if light or sun is on */ - ha-state-icon[data-domain=light][data-state=on], - ha-state-icon[data-domain=switch][data-state=on], - ha-state-icon[data-domain=binary_sensor][data-state=on], - ha-state-icon[data-domain=fan][data-state=on], - ha-state-icon[data-domain=sun][data-state=above_horizon] { + ha-icon[data-domain=light][data-state=on], + ha-icon[data-domain=switch][data-state=on], + ha-icon[data-domain=binary_sensor][data-state=on], + ha-icon[data-domain=fan][data-state=on], + ha-icon[data-domain=sun][data-state=above_horizon] { color: var(--paper-item-icon-active-color, #FDD835); } /* Color the icon if unavailable */ - ha-state-icon[data-state=unavailable] { + ha-icon[data-state=unavailable] { color: var(--state-icon-unavailable-color); } - + `; } @@ -47,19 +53,22 @@ class StateBadge extends PolymerElement { return { stateObj: { type: Object, - observer: 'updateIconAppearance', + observer: '_updateIconAppearance', }, + overrideIcon: String }; } - computeDomain(stateObj) { + _computeDomain(stateObj) { return computeStateDomain(stateObj); } + _computeIcon(stateObj) { + return this.overrideIcon || stateIcon(stateObj); + } - updateIconAppearance(newVal) { + _updateIconAppearance(newVal) { const iconStyle = { - display: 'inline', color: '', filter: '', }; diff --git a/src/panels/lovelace/cards/hui-glance-card.js b/src/panels/lovelace/cards/hui-glance-card.js index 34bb2c7750..7af9cb85c5 100644 --- a/src/panels/lovelace/cards/hui-glance-card.js +++ b/src/panels/lovelace/cards/hui-glance-card.js @@ -28,10 +28,6 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) { ha-card[header] { padding-top: 0; } - ha-icon { - padding: 8px; - color: var(--paper-item-icon-color); - } .entities { display: flex; margin-bottom: -12px; @@ -67,12 +63,10 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) { - - + diff --git a/src/panels/lovelace/components/hui-generic-entity-row.js b/src/panels/lovelace/components/hui-generic-entity-row.js index 1d0eaab6da..445ceaf311 100644 --- a/src/panels/lovelace/components/hui-generic-entity-row.js +++ b/src/panels/lovelace/components/hui-generic-entity-row.js @@ -41,10 +41,6 @@ class HuiGenericEntityRow extends PolymerElement { display: block; color: var(--secondary-text-color); } - ha-icon { - padding: 8px; - color: var(--paper-item-icon-color); - } .not-found { flex: 1; background-color: yellow; @@ -55,12 +51,10 @@ class HuiGenericEntityRow extends PolymerElement { }