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.
This commit is contained in:
Jerad Meisner 2018-08-23 13:24:21 -07:00 committed by Paulus Schoutsen
parent 144f00e2cc
commit cde106bd77
5 changed files with 35 additions and 35 deletions

View File

@ -140,7 +140,9 @@ const CONFIGS = [
- entity: group.kitchen - entity: group.kitchen
icon: mdi:home-assistant icon: mdi:home-assistant
- lock.kitchen_door - lock.kitchen_door
- light.bed_light - entity: light.bed_light
icon: mdi:alarm-light
name: Bed Light Custom Icon
- climate.ecobee - climate.ecobee
- input_number.noise_allowance - input_number.noise_allowance
title: Random group title: Random group

View File

@ -105,7 +105,8 @@ const CONFIGS = [
- media_player.living_room - media_player.living_room
- sun.sun - sun.sun
- cover.kitchen_window - cover.kitchen_window
- light.kitchen_lights - entity: light.kitchen_lights
icon: mdi:alarm-light
- lock.kitchen_door - lock.kitchen_door
- light.ceiling_lights - light.ceiling_lights
` `

View File

@ -1,8 +1,9 @@
import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.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 computeStateDomain from '../../common/entity/compute_state_domain.js';
import stateIcon from '../../common/entity/state_icon.js';
class StateBadge extends PolymerElement { class StateBadge extends PolymerElement {
static get template() { static get template() {
@ -20,26 +21,31 @@ class StateBadge extends PolymerElement {
line-height: 40px; line-height: 40px;
} }
ha-state-icon { ha-icon {
transition: color .3s ease-in-out, filter .3s ease-in-out; transition: color .3s ease-in-out, filter .3s ease-in-out;
} }
/* Color the icon if light or sun is on */ /* Color the icon if light or sun is on */
ha-state-icon[data-domain=light][data-state=on], ha-icon[data-domain=light][data-state=on],
ha-state-icon[data-domain=switch][data-state=on], ha-icon[data-domain=switch][data-state=on],
ha-state-icon[data-domain=binary_sensor][data-state=on], ha-icon[data-domain=binary_sensor][data-state=on],
ha-state-icon[data-domain=fan][data-state=on], ha-icon[data-domain=fan][data-state=on],
ha-state-icon[data-domain=sun][data-state=above_horizon] { ha-icon[data-domain=sun][data-state=above_horizon] {
color: var(--paper-item-icon-active-color, #FDD835); color: var(--paper-item-icon-active-color, #FDD835);
} }
/* Color the icon if unavailable */ /* Color the icon if unavailable */
ha-state-icon[data-state=unavailable] { ha-icon[data-state=unavailable] {
color: var(--state-icon-unavailable-color); color: var(--state-icon-unavailable-color);
} }
</style> </style>
<ha-state-icon id="icon" state-obj="[[stateObj]]" data-domain$="[[computeDomain(stateObj)]]" data-state$="[[stateObj.state]]"></ha-state-icon> <ha-icon
id="icon"
data-domain$="[[_computeDomain(stateObj)]]"
data-state$="[[stateObj.state]]"
icon="[[_computeIcon(stateObj)]]"
></ha-icon>
`; `;
} }
@ -47,19 +53,22 @@ class StateBadge extends PolymerElement {
return { return {
stateObj: { stateObj: {
type: Object, type: Object,
observer: 'updateIconAppearance', observer: '_updateIconAppearance',
}, },
overrideIcon: String
}; };
} }
computeDomain(stateObj) { _computeDomain(stateObj) {
return computeStateDomain(stateObj); return computeStateDomain(stateObj);
} }
_computeIcon(stateObj) {
return this.overrideIcon || stateIcon(stateObj);
}
updateIconAppearance(newVal) { _updateIconAppearance(newVal) {
const iconStyle = { const iconStyle = {
display: 'inline',
color: '', color: '',
filter: '', filter: '',
}; };

View File

@ -28,10 +28,6 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
ha-card[header] { ha-card[header] {
padding-top: 0; padding-top: 0;
} }
ha-icon {
padding: 8px;
color: var(--paper-item-icon-color);
}
.entities { .entities {
display: flex; display: flex;
margin-bottom: -12px; margin-bottom: -12px;
@ -67,12 +63,10 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
<template is="dom-if" if="[[_showInfo(_config.show_name)]]"> <template is="dom-if" if="[[_showInfo(_config.show_name)]]">
<div class="name">[[_computeName(item, hass.states)]]</div> <div class="name">[[_computeName(item, hass.states)]]</div>
</template> </template>
<template is="dom-if" if="[[!item.icon]]"> <state-badge
<state-badge state-obj="[[_computeStateObj(item, hass.states)]]"></state-badge> state-obj="[[_computeStateObj(item, hass.states)]]"
</template> override-icon="[[item.icon]]"
<template is="dom-if" if="[[item.icon]]"> ></state-badge>
<ha-icon icon="[[item.icon]]"></ha-icon>
</template>
<template is="dom-if" if="[[_showInfo(_config.show_state)]]"> <template is="dom-if" if="[[_showInfo(_config.show_state)]]">
<div>[[_computeState(item, hass.states)]]</div> <div>[[_computeState(item, hass.states)]]</div>
</template> </template>

View File

@ -41,10 +41,6 @@ class HuiGenericEntityRow extends PolymerElement {
display: block; display: block;
color: var(--secondary-text-color); color: var(--secondary-text-color);
} }
ha-icon {
padding: 8px;
color: var(--paper-item-icon-color);
}
.not-found { .not-found {
flex: 1; flex: 1;
background-color: yellow; background-color: yellow;
@ -55,12 +51,10 @@ class HuiGenericEntityRow extends PolymerElement {
} }
</style> </style>
<template is="dom-if" if="[[_stateObj]]"> <template is="dom-if" if="[[_stateObj]]">
<template is="dom-if" if="[[!config.icon]]"> <state-badge
<state-badge state-obj="[[_stateObj]]"></state-badge> state-obj="[[_stateObj]]"
</template> override-icon="[[config.icon]]"
<template is="dom-if" if="[[config.icon]]"> ></state-badge>
<ha-icon icon="[[config.icon]]"></ha-icon>
</template>
<div class="flex"> <div class="flex">
<div class="info"> <div class="info">
[[_computeName(config.name, _stateObj)]] [[_computeName(config.name, _stateObj)]]