Ensure consistent light state icon brightness (#14740)

* Ensure consistent light state icon brightness

* Update hui-entity-card.ts

* Update hui-entity-card.ts

Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
This commit is contained in:
Philip Allgaier 2022-12-13 17:23:49 +01:00 committed by GitHub
parent f2b7288e92
commit 9c27bb37a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -193,8 +193,10 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
.icon=${this._config.icon}
.state=${stateObj}
style=${styleMap({
color: colored ? this._computeColor(stateObj) : "",
filter: colored ? this._computeBrightness(stateObj) : "",
color: colored ? this._computeColor(stateObj) : undefined,
filter: colored
? this._computeBrightness(stateObj)
: undefined,
height: this._config.icon_height
? this._config.icon_height
: "",

View File

@ -29,6 +29,7 @@ import "../../../components/ha-card";
import "../../../components/ha-icon";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import { formatAttributeValue } from "../../../data/entity_attributes";
import { LightEntity } from "../../../data/light";
import { HomeAssistant } from "../../../types";
import { computeCardSize } from "../common/compute-card-size";
import { findEntities } from "../common/find-entities";
@ -149,6 +150,7 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
data-state=${stateObj.state}
style=${styleMap({
color: colored ? this._computeColor(stateObj) : undefined,
filter: colored ? this._computeBrightness(stateObj) : undefined,
height: this._config.icon_height
? this._config.icon_height
: "",
@ -201,6 +203,9 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
}
return undefined;
}
if (stateObj.attributes.rgb_color && stateActive(stateObj)) {
return `rgb(${stateObj.attributes.rgb_color.join(",")})`;
}
const iconColor = stateColorCss(stateObj);
if (iconColor) {
return `rgb(${iconColor})`;
@ -208,6 +213,14 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
return undefined;
}
private _computeBrightness(stateObj: HassEntity | LightEntity): string {
if (stateObj.attributes.brightness && stateActive(stateObj)) {
const brightness = stateObj.attributes.brightness;
return `brightness(${(brightness + 245) / 5}%)`;
}
return "";
}
protected shouldUpdate(changedProps: PropertyValues): boolean {
// Side Effect used to update footer hass while keeping optimizations
if (this._footerElement) {