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

Align state display with Home Assistant #1592

Merged
merged 4 commits into from
Nov 22, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/cards/chips-card/chips/alarm-control-panel-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
actionHandler,
ActionHandlerEvent,
computeRTL,
computeStateDisplay,
handleAction,
hasAction,
HomeAssistant,
Expand Down Expand Up @@ -82,15 +81,7 @@ export class AlarmControlPanelChip extends LitElement implements LovelaceChip {
const iconColor = getStateColor(stateObj.state);
const iconPulse = shouldPulse(stateObj.state);

const stateDisplay = this.hass.formatEntityState
? this.hass.formatEntityState(stateObj)
: computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
const stateDisplay = this.hass.formatEntityState(stateObj);

const iconStyle = {};
if (iconColor) {
Expand Down
13 changes: 2 additions & 11 deletions src/cards/chips-card/chips/entity-chip.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HassEntity } from "home-assistant-js-websocket";
import {
css,
CSSResultGroup,
Expand All @@ -13,7 +14,6 @@ import {
actionHandler,
ActionHandlerEvent,
computeRTL,
computeStateDisplay,
getEntityPicture,
handleAction,
hasAction,
Expand All @@ -31,7 +31,6 @@ import {
LovelaceChip,
} from "../../../utils/lovelace/chip/types";
import { LovelaceChipEditor } from "../../../utils/lovelace/types";
import { HassEntity } from "home-assistant-js-websocket";

@customElement(computeChipComponentName("entity"))
export class EntityChip extends LitElement implements LovelaceChip {
Expand Down Expand Up @@ -84,15 +83,7 @@ export class EntityChip extends LitElement implements LovelaceChip {
? getEntityPicture(stateObj)
: undefined;

const stateDisplay = this.hass.formatEntityState
? this.hass.formatEntityState(stateObj)
: computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
const stateDisplay = this.hass.formatEntityState(stateObj);

const active = isActive(stateObj);

Expand Down
11 changes: 1 addition & 10 deletions src/cards/chips-card/chips/light-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
actionHandler,
ActionHandlerEvent,
computeRTL,
computeStateDisplay,
handleAction,
hasAction,
HomeAssistant,
Expand Down Expand Up @@ -80,15 +79,7 @@ export class LightChip extends LitElement implements LovelaceChip {
const name = this._config.name || stateObj.attributes.friendly_name || "";
const icon = this._config.icon;

const stateDisplay = this.hass.formatEntityState
? this.hass.formatEntityState(stateObj)
: computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
const stateDisplay = this.hass.formatEntityState(stateObj);

const active = isActive(stateObj);

Expand Down
23 changes: 7 additions & 16 deletions src/cards/chips-card/chips/weather-chip.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import {
actionHandler,
ActionHandlerEvent,
computeRTL,
computeStateDisplay,
formatNumber,
handleAction,
hasAction,
Expand All @@ -20,7 +20,6 @@ import {
} from "../../../utils/lovelace/chip/types";
import { LovelaceChipEditor } from "../../../utils/lovelace/types";
import { getWeatherStateSVG, weatherSVGStyles } from "../../../utils/weather";
import { HassEntity } from "home-assistant-js-websocket";

@customElement(computeChipComponentName("weather"))
export class WeatherChip extends LitElement implements LovelaceChip {
Expand Down Expand Up @@ -71,23 +70,15 @@ export class WeatherChip extends LitElement implements LovelaceChip {
const displayLabels: string[] = [];

if (this._config.show_conditions) {
const stateDisplay = this.hass.formatEntityState
? this.hass.formatEntityState(stateObj)
: computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
const stateDisplay = this.hass.formatEntityState(stateObj);
displayLabels.push(stateDisplay);
}

if (this._config.show_temperature) {
const temperatureDisplay = `${formatNumber(
stateObj.attributes.temperature,
this.hass.locale
)} ${this.hass.config.unit_system.temperature}`;
const temperatureDisplay = this.hass.formatEntityAttributeValue(
stateObj,
"temperature"
);
displayLabels.push(temperatureDisplay);
}

Expand All @@ -104,7 +95,7 @@ export class WeatherChip extends LitElement implements LovelaceChip {
>
${weatherIcon}
${displayLabels.length > 0
? html`<span>${displayLabels.join(" / ")}</span>`
? html`<span>${displayLabels.join(" ")}</span>`
: nothing}
</mushroom-chip>
`;
Expand Down
20 changes: 5 additions & 15 deletions src/cards/climate-card/climate-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
ActionHandlerEvent,
ClimateEntity,
computeRTL,
computeStateDisplay,
formatNumber,
handleAction,
hasAction,
Expand Down Expand Up @@ -167,22 +166,13 @@ export class ClimateCard
const appearance = computeAppearance(this._config);
const picture = computeEntityPicture(stateObj, appearance.icon_type);

let stateDisplay = this.hass.formatEntityState
? this.hass.formatEntityState(stateObj)
: computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
let stateDisplay = this.hass.formatEntityState(stateObj);
if (stateObj.attributes.current_temperature !== null) {
const temperature = formatNumber(
stateObj.attributes.current_temperature,
this.hass.locale
const temperature = this.hass.formatEntityAttributeValue(
stateObj,
"current_temperature"
);
const unit = this.hass.config.unit_system.temperature;
stateDisplay += ` - ${temperature} ${unit}`;
stateDisplay += ` ⸱ ${temperature}`;
}
const rtl = computeRTL(this.hass);

Expand Down
19 changes: 7 additions & 12 deletions src/cards/cover-card/cover-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import { styleMap } from "lit/directives/style-map.js";
import {
actionHandler,
ActionHandlerEvent,
blankBeforePercent,
computeRTL,
computeStateDisplay,
CoverEntity,
handleAction,
hasAction,
Expand Down Expand Up @@ -195,17 +193,14 @@ export class CoverCard
const appearance = computeAppearance(this._config);
const picture = computeEntityPicture(stateObj, appearance.icon_type);

let stateDisplay = this.hass.formatEntityState
? this.hass.formatEntityState(stateObj)
: computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
let stateDisplay = this.hass.formatEntityState(stateObj);
if (this.position) {
stateDisplay += ` - ${this.position}${blankBeforePercent(this.hass.locale)}%`;
const position = this.hass.formatEntityAttributeValue(
stateObj,
"current_position",
this.position
);
stateDisplay += ` ⸱ ${position}`;
}

const rtl = computeRTL(this.hass);
Expand Down
19 changes: 7 additions & 12 deletions src/cards/fan-card/fan-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { styleMap } from "lit/directives/style-map.js";
import {
actionHandler,
ActionHandlerEvent,
blankBeforePercent,
computeRTL,
computeStateDisplay,
handleAction,
hasAction,
HomeAssistant,
Expand Down Expand Up @@ -137,17 +135,14 @@ export class FanCard
const appearance = computeAppearance(this._config);
const picture = computeEntityPicture(stateObj, appearance.icon_type);

let stateDisplay = this.hass.formatEntityState
? this.hass.formatEntityState(stateObj)
: computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
let stateDisplay = this.hass.formatEntityState(stateObj);
if (this.percentage != null && stateObj.state === "on") {
stateDisplay = `${this.percentage}${blankBeforePercent(this.hass.locale)}%`;
const percentage = this.hass.formatEntityAttributeValue(
stateObj,
"percentage",
this.percentage
);
stateDisplay = percentage;
}

const rtl = computeRTL(this.hass);
Expand Down
19 changes: 7 additions & 12 deletions src/cards/humidifier-card/humidifier-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { classMap } from "lit/directives/class-map.js";
import {
actionHandler,
ActionHandlerEvent,
blankBeforePercent,
computeRTL,
computeStateDisplay,
handleAction,
hasAction,
HomeAssistant,
Expand Down Expand Up @@ -110,17 +108,14 @@ export class HumidifierCard
const appearance = computeAppearance(this._config);
const picture = computeEntityPicture(stateObj, appearance.icon_type);

let stateDisplay = this.hass.formatEntityState
? this.hass.formatEntityState(stateObj)
: computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
let stateDisplay = this.hass.formatEntityState(stateObj);
if (this.humidity) {
stateDisplay = `${this.humidity}${blankBeforePercent(this.hass.locale)}%`;
const humidity = this.hass.formatEntityAttributeValue(
stateObj,
"current_humidity",
this.humidity
);
stateDisplay = humidity;
}

const rtl = computeRTL(this.hass);
Expand Down
24 changes: 9 additions & 15 deletions src/cards/light-card/light-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import { styleMap } from "lit/directives/style-map.js";
import {
actionHandler,
ActionHandlerEvent,
blankBeforePercent,
computeRTL,
computeStateDisplay,
handleAction,
hasAction,
HomeAssistant,
Expand Down Expand Up @@ -46,7 +44,6 @@ import "./controls/light-color-control";
import "./controls/light-color-temp-control";
import { LightCardConfig } from "./light-card-config";
import {
getBrightness,
getRGBColor,
isColorLight,
isColorSuperLight,
Expand Down Expand Up @@ -158,12 +155,12 @@ export class LightCard
const stateObj = this._stateObj;

if (!stateObj) return;
this.brightness = getBrightness(stateObj);
this.brightness = stateObj.attributes.brightness;
}

private onCurrentBrightnessChange(e: CustomEvent<{ value?: number }>): void {
if (e.detail.value != null) {
this.brightness = e.detail.value;
this.brightness = (e.detail.value * 255) / 100;
}
}

Expand Down Expand Up @@ -196,17 +193,14 @@ export class LightCard
const appearance = computeAppearance(this._config);
const picture = computeEntityPicture(stateObj, appearance.icon_type);

let stateDisplay = this.hass.formatEntityState
? this.hass.formatEntityState(stateObj)
: computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
let stateDisplay = this.hass.formatEntityState(stateObj);
if (this.brightness != null) {
stateDisplay = `${this.brightness}${blankBeforePercent(this.hass.locale)}%`;
const brightness = this.hass.formatEntityAttributeValue(
stateObj,
"brightness",
this.brightness
);
stateDisplay = brightness;
}

const rtl = computeRTL(this.hass);
Expand Down
Loading
Loading