Skip to content

Commit

Permalink
Ensure consistent light state icon brightness (#14740)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
spacegaier and piitaya committed Dec 13, 2022
1 parent f2b7288 commit 9c27bb3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/panels/lovelace/cards/hui-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
: "",
Expand Down
13 changes: 13 additions & 0 deletions src/panels/lovelace/cards/hui-entity-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
: "",
Expand Down Expand Up @@ -201,13 +203,24 @@ 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})`;
}
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) {
Expand Down

0 comments on commit 9c27bb3

Please sign in to comment.