mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Don't apply brightness filter to plant icons (#17029)
This commit is contained in:
parent
655cf053c7
commit
976fcab146
@ -110,3 +110,15 @@ export const stateColorProperties = (
|
|||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const stateColorBrightness = (stateObj: HassEntity): string => {
|
||||||
|
if (
|
||||||
|
stateObj.attributes.brightness &&
|
||||||
|
computeDomain(stateObj.entity_id) !== "plant"
|
||||||
|
) {
|
||||||
|
// lowest brightness will be around 50% (that's pretty dark)
|
||||||
|
const brightness = stateObj.attributes.brightness;
|
||||||
|
return `brightness(${(brightness + 245) / 5}%)`;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
@ -13,7 +13,10 @@ import { ifDefined } from "lit/directives/if-defined";
|
|||||||
import { styleMap } from "lit/directives/style-map";
|
import { styleMap } from "lit/directives/style-map";
|
||||||
import { computeDomain } from "../../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||||
import { stateColorCss } from "../../common/entity/state_color";
|
import {
|
||||||
|
stateColorCss,
|
||||||
|
stateColorBrightness,
|
||||||
|
} from "../../common/entity/state_color";
|
||||||
import { iconColorCSS } from "../../common/style/icon_color_css";
|
import { iconColorCSS } from "../../common/style/icon_color_css";
|
||||||
import { cameraUrlWithWidthHeight } from "../../data/camera";
|
import { cameraUrlWithWidthHeight } from "../../data/camera";
|
||||||
import { HVAC_ACTION_TO_MODE } from "../../data/climate";
|
import { HVAC_ACTION_TO_MODE } from "../../data/climate";
|
||||||
@ -153,8 +156,7 @@ export class StateBadge extends LitElement {
|
|||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.warn(errorMessage);
|
console.warn(errorMessage);
|
||||||
}
|
}
|
||||||
// lowest brightness will be around 50% (that's pretty dark)
|
iconStyle.filter = stateColorBrightness(stateObj);
|
||||||
iconStyle.filter = `brightness(${(brightness + 245) / 5}%)`;
|
|
||||||
}
|
}
|
||||||
if (stateObj.attributes.hvac_action) {
|
if (stateObj.attributes.hvac_action) {
|
||||||
const hvacAction = stateObj.attributes.hvac_action;
|
const hvacAction = stateObj.attributes.hvac_action;
|
||||||
|
@ -26,7 +26,10 @@ import { computeDomain } from "../../../common/entity/compute_domain";
|
|||||||
import { computeStateDisplaySingleEntity } from "../../../common/entity/compute_state_display";
|
import { computeStateDisplaySingleEntity } from "../../../common/entity/compute_state_display";
|
||||||
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
import { stateColorCss } from "../../../common/entity/state_color";
|
import {
|
||||||
|
stateColorCss,
|
||||||
|
stateColorBrightness,
|
||||||
|
} from "../../../common/entity/state_color";
|
||||||
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
|
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
|
||||||
import { iconColorCSS } from "../../../common/style/icon_color_css";
|
import { iconColorCSS } from "../../../common/style/icon_color_css";
|
||||||
import { LocalizeFunc } from "../../../common/translations/localize";
|
import { LocalizeFunc } from "../../../common/translations/localize";
|
||||||
@ -41,7 +44,6 @@ import {
|
|||||||
themesContext,
|
themesContext,
|
||||||
} from "../../../data/context";
|
} from "../../../data/context";
|
||||||
import { EntityRegistryDisplayEntry } from "../../../data/entity_registry";
|
import { EntityRegistryDisplayEntry } from "../../../data/entity_registry";
|
||||||
import { LightEntity } from "../../../data/light";
|
|
||||||
import { ActionHandlerEvent } from "../../../data/lovelace";
|
import { ActionHandlerEvent } from "../../../data/lovelace";
|
||||||
import { FrontendLocaleData } from "../../../data/translation";
|
import { FrontendLocaleData } from "../../../data/translation";
|
||||||
import { Themes } from "../../../data/ws-themes";
|
import { Themes } from "../../../data/ws-themes";
|
||||||
@ -213,9 +215,7 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
|||||||
.state=${stateObj}
|
.state=${stateObj}
|
||||||
style=${styleMap({
|
style=${styleMap({
|
||||||
color: colored ? this._computeColor(stateObj) : undefined,
|
color: colored ? this._computeColor(stateObj) : undefined,
|
||||||
filter: colored
|
filter: colored ? stateColorBrightness(stateObj) : undefined,
|
||||||
? this._computeBrightness(stateObj)
|
|
||||||
: undefined,
|
|
||||||
height: this._config.icon_height
|
height: this._config.icon_height
|
||||||
? this._config.icon_height
|
? this._config.icon_height
|
||||||
: "",
|
: "",
|
||||||
@ -337,14 +337,6 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeBrightness(stateObj: HassEntity | LightEntity): string {
|
|
||||||
if (stateObj.attributes.brightness) {
|
|
||||||
const brightness = stateObj.attributes.brightness;
|
|
||||||
return `brightness(${(brightness + 245) / 5}%)`;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private _computeColor(stateObj: HassEntity): string | undefined {
|
private _computeColor(stateObj: HassEntity): string | undefined {
|
||||||
if (stateObj.attributes.rgb_color) {
|
if (stateObj.attributes.rgb_color) {
|
||||||
return `rgb(${stateObj.attributes.rgb_color.join(",")})`;
|
return `rgb(${stateObj.attributes.rgb_color.join(",")})`;
|
||||||
|
@ -16,7 +16,10 @@ import { computeAttributeValueDisplay } from "../../../common/entity/compute_att
|
|||||||
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
||||||
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
import { stateColorCss } from "../../../common/entity/state_color";
|
import {
|
||||||
|
stateColorCss,
|
||||||
|
stateColorBrightness,
|
||||||
|
} from "../../../common/entity/state_color";
|
||||||
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
|
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
|
||||||
import {
|
import {
|
||||||
formatNumber,
|
formatNumber,
|
||||||
@ -28,7 +31,6 @@ import "../../../components/ha-card";
|
|||||||
import "../../../components/ha-icon";
|
import "../../../components/ha-icon";
|
||||||
import { HVAC_ACTION_TO_MODE } from "../../../data/climate";
|
import { HVAC_ACTION_TO_MODE } from "../../../data/climate";
|
||||||
import { isUnavailableState } from "../../../data/entity";
|
import { isUnavailableState } from "../../../data/entity";
|
||||||
import { LightEntity } from "../../../data/light";
|
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { computeCardSize } from "../common/compute-card-size";
|
import { computeCardSize } from "../common/compute-card-size";
|
||||||
import { findEntities } from "../common/find-entities";
|
import { findEntities } from "../common/find-entities";
|
||||||
@ -143,7 +145,7 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
|
|||||||
data-state=${stateObj.state}
|
data-state=${stateObj.state}
|
||||||
style=${styleMap({
|
style=${styleMap({
|
||||||
color: colored ? this._computeColor(stateObj) : undefined,
|
color: colored ? this._computeColor(stateObj) : undefined,
|
||||||
filter: colored ? this._computeBrightness(stateObj) : undefined,
|
filter: colored ? stateColorBrightness(stateObj) : undefined,
|
||||||
height: this._config.icon_height
|
height: this._config.icon_height
|
||||||
? this._config.icon_height
|
? this._config.icon_height
|
||||||
: "",
|
: "",
|
||||||
@ -214,14 +216,6 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeBrightness(stateObj: HassEntity | LightEntity): string {
|
|
||||||
if (stateObj.attributes.brightness) {
|
|
||||||
const brightness = stateObj.attributes.brightness;
|
|
||||||
return `brightness(${(brightness + 245) / 5}%)`;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||||
// Side Effect used to update footer hass while keeping optimizations
|
// Side Effect used to update footer hass while keeping optimizations
|
||||||
if (this._footerElement) {
|
if (this._footerElement) {
|
||||||
|
@ -30,6 +30,7 @@ import { hasConfigOrEntityChanged } from "../common/has-changed";
|
|||||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||||
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
||||||
import { LightCardConfig } from "./types";
|
import { LightCardConfig } from "./types";
|
||||||
|
import { stateColorBrightness } from "../../../common/entity/state_color";
|
||||||
|
|
||||||
@customElement("hui-light-card")
|
@customElement("hui-light-card")
|
||||||
export class HuiLightCard extends LitElement implements LovelaceCard {
|
export class HuiLightCard extends LitElement implements LovelaceCard {
|
||||||
@ -239,8 +240,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
if (stateObj.state === "off" || !stateObj.attributes.brightness) {
|
if (stateObj.state === "off" || !stateObj.attributes.brightness) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
const brightness = stateObj.attributes.brightness;
|
return stateColorBrightness(stateObj);
|
||||||
return `brightness(${(brightness + 245) / 5}%)`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeColor(stateObj: LightEntity): string {
|
private _computeColor(stateObj: LightEntity): string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user