Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparent unavailable state in history #14710

Merged
merged 5 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/common/color/compute-color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const THEME_COLORS = new Set([
"primary",
"accent",
"disabled",
"inactive",
"red",
"pink",
"purple",
Expand Down
7 changes: 5 additions & 2 deletions src/components/chart/timeline-chart/textbar-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ export class TextBarElement extends BarElement {
}
const textColor =
options.textColor ||
(options.backgroundColor &&
(luminosity(hex2rgb(options.backgroundColor)) > 0.5 ? "#000" : "#fff"));
(options?.backgroundColor === "transparent"
? "transparent"
: luminosity(hex2rgb(options.backgroundColor)) > 0.5
? "#000"
: "#fff");

// ctx.font = "12px arial";
ctx.fillStyle = textColor;
Expand Down
4 changes: 1 addition & 3 deletions src/components/chart/timeline-chart/timeline-color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function computeTimelineStateColor(
stateObj?: HassEntity
): string | undefined {
if (!stateObj || state === UNAVAILABLE) {
const rgb = cssToRgb("--rgb-state-unavailable-color", computedStyles);
if (!rgb) return undefined;
return rgb2hex(rgb);
return "transparent";
}

const color = stateColor(stateObj, state);
Expand Down
30 changes: 14 additions & 16 deletions src/components/entity/state-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,25 @@ export class StateBadge extends LitElement {
}
hostStyle.backgroundImage = `url(${imageUrl})`;
this._showIcon = false;
} else if (this._stateColor) {
} else if (this._stateColor && stateActive(stateObj)) {
const color = stateColorCss(stateObj);
if (color) {
iconStyle.color = `rgb(${color})`;
}
if (stateActive(stateObj)) {
if (stateObj.attributes.rgb_color) {
iconStyle.color = `rgb(${stateObj.attributes.rgb_color.join(",")})`;
}
if (stateObj.attributes.brightness) {
const brightness = stateObj.attributes.brightness;
if (typeof brightness !== "number") {
const errorMessage = `Type error: state-badge expected number, but type of ${
stateObj.entity_id
}.attributes.brightness is ${typeof brightness} (${brightness})`;
// eslint-disable-next-line
console.warn(errorMessage);
}
// lowest brightness will be around 50% (that's pretty dark)
iconStyle.filter = `brightness(${(brightness + 245) / 5}%)`;
if (stateObj.attributes.rgb_color) {
iconStyle.color = `rgb(${stateObj.attributes.rgb_color.join(",")})`;
}
if (stateObj.attributes.brightness) {
const brightness = stateObj.attributes.brightness;
if (typeof brightness !== "number") {
const errorMessage = `Type error: state-badge expected number, but type of ${
stateObj.entity_id
}.attributes.brightness is ${typeof brightness} (${brightness})`;
// eslint-disable-next-line
console.warn(errorMessage);
}
Comment on lines +120 to 126
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we should even warn about this but ok 🤷‍♂️

// lowest brightness will be around 50% (that's pretty dark)
iconStyle.filter = `brightness(${(brightness + 245) / 5}%)`;
}
}
} else if (this.overrideImage) {
Expand Down
10 changes: 6 additions & 4 deletions src/panels/lovelace/cards/hui-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
? this._config.name || (stateObj ? computeStateName(stateObj) : "")
: "";

const colored = stateObj && this.getStateColor(stateObj, this._config);
const active = stateObj && colored && stateActive(stateObj);
const active = stateObj && stateActive(stateObj);
const colored = active && this.getStateColor(stateObj, this._config);

return html`
<ha-card
Expand Down Expand Up @@ -316,15 +316,17 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
return "";
}

private _computeColor(stateObj: HassEntity | LightEntity): string {
private _computeColor(
stateObj: HassEntity | LightEntity
): string | 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 "";
return undefined;
}

private _handleAction(ev: ActionHandlerEvent) {
Expand Down
10 changes: 6 additions & 4 deletions src/panels/lovelace/cards/hui-entity-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {

const name = this._config.name || computeStateName(stateObj);

const colored = stateObj && this.getStateColor(stateObj, this._config);
const active = stateObj && colored && stateActive(stateObj);
const active = stateObj && stateActive(stateObj);
const colored = active && this.getStateColor(stateObj, this._config);

return html`
<ha-card @click=${this._handleClick} tabindex="0">
Expand Down Expand Up @@ -193,12 +193,14 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
`;
}

private _computeColor(stateObj: HassEntity | LightEntity): string {
private _computeColor(
stateObj: HassEntity | LightEntity
): string | undefined {
const iconColor = stateColorCss(stateObj);
if (iconColor) {
return `rgb(${iconColor})`;
}
return "";
return undefined;
}

protected shouldUpdate(changedProps: PropertyValues): boolean {
Expand Down
7 changes: 3 additions & 4 deletions src/resources/ha-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ documentContainer.innerHTML = `<custom-style>
--rgb-primary-color: 3, 169, 244;
--rgb-accent-color: 255, 152, 0;
--rgb-disabled-color: 189, 189, 189;
--rgb-inactive-color: 114, 114, 114;
--rgb-primary-text-color: 33, 33, 33;
--rgb-secondary-text-color: 114, 114, 114;
--rgb-text-primary-color: 255, 255, 255;
Expand Down Expand Up @@ -136,13 +135,13 @@ documentContainer.innerHTML = `<custom-style>

/* rgb state color */
--rgb-state-default-color: var(--rgb-dark-primary-color, 68, 115, 158);
--rgb-state-inactive-color: var(--rgb-inactive-color);
--rgb-state-inactive-color: var(--rgb-grey-color);
--rgb-state-unavailable-color: var(--rgb-disabled-color);

/* rgb state domain colors */
--rgb-state-alarm-armed-color: var(--rgb-green-color);
--rgb-state-alarm-arming-color: var(--rgb-orange-color);
--rgb-state-alarm-disarmed-color: var(--rgb-inactive-color);
--rgb-state-alarm-disarmed-color: var(--rgb-grey-color);
--rgb-state-alarm-pending-color: var(--rgb-orange-color);
--rgb-state-alarm-triggered-color: var(--rgb-red-color);
--rgb-state-alert-color: var(--rgb-red-color);
Expand Down Expand Up @@ -170,7 +169,7 @@ documentContainer.innerHTML = `<custom-style>
--rgb-state-lock-unlocked-color: var(--rgb-red-color);
--rgb-state-media-player-color: var(--rgb-indigo-color);
--rgb-state-person-home-color: var(--rgb-green-color);
--rgb-state-person-not-home-color: var(--rgb-inactive-color);
--rgb-state-person-not-home-color: var(--rgb-grey-color);
--rgb-state-person-zone-color: var(--rgb-blue-color);
--rgb-state-remote-color: var(--rgb-amber-color);
--rgb-state-script-color: var(--rgb-amber-color);
Expand Down
1 change: 0 additions & 1 deletion src/resources/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const darkStyles = {
"map-filter":
"invert(.9) hue-rotate(170deg) brightness(1.5) contrast(1.2) saturate(.3)",
"rgb-disabled-color": "70, 70, 70",
"rgb-inactive-color": "141, 141, 141",
};

export const derivedStyles = {
Expand Down