diff --git a/src/components/entity/ha-entity-state-picker.ts b/src/components/entity/ha-entity-state-picker.ts
index 688b38e6db..b14cbeaa2f 100644
--- a/src/components/entity/ha-entity-state-picker.ts
+++ b/src/components/entity/ha-entity-state-picker.ts
@@ -1,11 +1,9 @@
import { HassEntity } from "home-assistant-js-websocket";
-import { html, LitElement, PropertyValues, nothing } from "lit";
+import { LitElement, PropertyValues, html, nothing } from "lit";
import { customElement, property, query } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event";
-import { computeStateDisplay } from "../../common/entity/compute_state_display";
import { getStates } from "../../common/entity/get_states";
-import { computeAttributeValueDisplay } from "../../common/entity/compute_attribute_display";
-import { ValueChangedEvent, HomeAssistant } from "../../types";
+import { HomeAssistant, ValueChangedEvent } from "../../types";
import "../ha-combo-box";
import type { HaComboBox } from "../ha-combo-box";
@@ -58,20 +56,9 @@ class HaEntityStatePicker extends LitElement {
? getStates(state, this.attribute).map((key) => ({
value: key,
label: !this.attribute
- ? computeStateDisplay(
- this.hass.localize,
+ ? this.hass.formatEntityState(state, key)
+ : this.hass.formatEntityAttributeValue(
state,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- key
- )
- : computeAttributeValueDisplay(
- this.hass.localize,
- state,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
this.attribute,
key
),
diff --git a/src/components/entity/ha-state-label-badge.ts b/src/components/entity/ha-state-label-badge.ts
index 417ce42024..b340893f06 100644
--- a/src/components/entity/ha-state-label-badge.ts
+++ b/src/components/entity/ha-state-label-badge.ts
@@ -12,7 +12,6 @@ import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { arrayLiteralIncludes } from "../../common/array/literal-includes";
import secondsToDuration from "../../common/datetime/seconds_to_duration";
-import { computeStateDisplay } from "../../common/entity/compute_state_display";
import { computeStateDomain } from "../../common/entity/compute_state_domain";
import { computeStateName } from "../../common/entity/compute_state_name";
import { FIXED_DOMAIN_STATES } from "../../common/entity/get_states";
@@ -192,13 +191,7 @@ export class HaStateLabelBadge extends LitElement {
this.hass!.locale,
getNumberFormatOptions(entityState, entry)
)
- : computeStateDisplay(
- this.hass!.localize,
- entityState,
- this.hass!.locale,
- this.hass!.config,
- this.hass!.entities
- );
+ : this.hass!.formatEntityState(entityState);
}
}
diff --git a/src/components/ha-climate-state.ts b/src/components/ha-climate-state.ts
index 047407f7d3..ca5d3a00e9 100644
--- a/src/components/ha-climate-state.ts
+++ b/src/components/ha-climate-state.ts
@@ -1,9 +1,14 @@
-import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
+import {
+ css,
+ CSSResultGroup,
+ html,
+ LitElement,
+ nothing,
+ TemplateResult,
+} from "lit";
import { customElement, property } from "lit/decorators";
-import { computeAttributeValueDisplay } from "../common/entity/compute_attribute_display";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
import { CLIMATE_PRESET_NONE, ClimateEntity } from "../data/climate";
-import { isUnavailableState } from "../data/entity";
+import { isUnavailableState, OFF } from "../data/entity";
import type { HomeAssistant } from "../types";
@customElement("ha-climate-state")
@@ -22,26 +27,24 @@ class HaClimateState extends LitElement {
${this.stateObj.attributes.preset_mode &&
this.stateObj.attributes.preset_mode !== CLIMATE_PRESET_NONE
? html`-
- ${computeAttributeValueDisplay(
- this.hass.localize,
+ ${this.hass.formatEntityAttributeValue(
this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"preset_mode"
)}`
- : ""}
+ : nothing}
${this._computeTarget()}
`
: this._localizeState()}
${currentStatus && !isUnavailableState(this.stateObj.state)
- ? html`
- ${this.hass.localize("ui.card.climate.currently")}:
-
${currentStatus}
-
`
- : ""}`;
+ ? html`
+
+ ${this.hass.localize("ui.card.climate.currently")}:
+
${currentStatus}
+
+ `
+ : nothing}`;
}
private _computeCurrentStatus(): string | undefined {
@@ -125,24 +128,17 @@ class HaClimateState extends LitElement {
return this.hass.localize(`state.default.${this.stateObj.state}`);
}
- const stateString = computeStateDisplay(
- this.hass.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- );
+ const stateString = this.hass.formatEntityState(this.stateObj);
- return this.stateObj.attributes.hvac_action
- ? `${computeAttributeValueDisplay(
- this.hass.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "hvac_action"
- )} (${stateString})`
- : stateString;
+ if (this.stateObj.attributes.hvac_action && this.stateObj.state !== OFF) {
+ const actionString = this.hass.formatEntityAttributeValue(
+ this.stateObj,
+ "hvac_action"
+ );
+ return `${actionString} (${stateString})`;
+ }
+
+ return stateString;
}
static get styles(): CSSResultGroup {
diff --git a/src/components/ha-humidifier-state.ts b/src/components/ha-humidifier-state.ts
index 63fd33037c..a2d6dc740b 100644
--- a/src/components/ha-humidifier-state.ts
+++ b/src/components/ha-humidifier-state.ts
@@ -1,7 +1,5 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
-import { computeAttributeValueDisplay } from "../common/entity/compute_attribute_display";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
import { isUnavailableState, OFF } from "../data/entity";
import { HumidifierEntity } from "../data/humidifier";
import type { HomeAssistant } from "../types";
@@ -21,12 +19,8 @@ class HaHumidifierState extends LitElement {
${this._localizeState()}
${this.stateObj.attributes.mode
? html`-
- ${computeAttributeValueDisplay(
- this.hass.localize,
+ ${this.hass.formatEntityAttributeValue(
this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"mode"
)}`
: ""}
@@ -78,24 +72,17 @@ class HaHumidifierState extends LitElement {
return this.hass.localize(`state.default.${this.stateObj.state}`);
}
- const stateString = computeStateDisplay(
- this.hass.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- );
+ const stateString = this.hass.formatEntityState(this.stateObj);
- return this.stateObj.attributes.action && this.stateObj.state !== OFF
- ? `${computeAttributeValueDisplay(
- this.hass.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "action"
- )} (${stateString})`
- : stateString;
+ if (this.stateObj.attributes.action && this.stateObj.state !== OFF) {
+ const actionString = this.hass.formatEntityAttributeValue(
+ this.stateObj,
+ "action"
+ );
+ return `${actionString} (${stateString})`;
+ }
+
+ return stateString;
}
static get styles(): CSSResultGroup {
diff --git a/src/components/ha-water_heater-state.js b/src/components/ha-water_heater-state.js
index 4f2220fc58..2d768acfd2 100644
--- a/src/components/ha-water_heater-state.js
+++ b/src/components/ha-water_heater-state.js
@@ -1,7 +1,6 @@
import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
import { formatNumber } from "../common/number/format_number";
import LocalizeMixin from "../mixins/localize-mixin";
@@ -84,12 +83,7 @@ class HaWaterHeaterState extends LocalizeMixin(PolymerElement) {
}
_localizeState(stateObj) {
- return computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.entities
- );
+ return this.hass.formatEntityState(stateObj);
}
}
customElements.define("ha-water_heater-state", HaWaterHeaterState);
diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts
index f0bf51c55c..244fad1ba3 100644
--- a/src/data/automation_i18n.ts
+++ b/src/data/automation_i18n.ts
@@ -6,11 +6,7 @@ import {
formatTimeWithSeconds,
} from "../common/datetime/format_time";
import secondsToDuration from "../common/datetime/seconds_to_duration";
-import {
- computeAttributeNameDisplay,
- computeAttributeValueDisplay,
-} from "../common/entity/compute_attribute_display";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
+import { computeAttributeNameDisplay } from "../common/entity/compute_attribute_display";
import { computeStateName } from "../common/entity/compute_state_name";
import "../resources/intl-polyfill";
import type { HomeAssistant } from "../types";
@@ -235,23 +231,14 @@ const tryDescribeTrigger = (
for (const state of trigger.from.values()) {
from.push(
trigger.attribute
- ? computeAttributeValueDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- trigger.attribute,
- state
- ).toString()
- : computeStateDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- state
- )
+ ? hass
+ .formatEntityAttributeValue(
+ stateObj,
+ trigger.attribute,
+ state
+ )
+ .toString()
+ : hass.formatEntityState(stateObj, state)
);
}
if (from.length !== 0) {
@@ -261,23 +248,16 @@ const tryDescribeTrigger = (
} else {
base += ` from ${
trigger.attribute
- ? computeAttributeValueDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- trigger.attribute,
- trigger.from
- ).toString()
- : computeStateDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- trigger.from.toString()
- ).toString()
+ ? hass
+ .formatEntityAttributeValue(
+ stateObj,
+ trigger.attribute,
+ trigger.from
+ )
+ .toString()
+ : hass
+ .formatEntityState(stateObj, trigger.from.toString())
+ .toString()
}`;
}
}
@@ -292,23 +272,14 @@ const tryDescribeTrigger = (
for (const state of trigger.to.values()) {
to.push(
trigger.attribute
- ? computeAttributeValueDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- trigger.attribute,
- state
- ).toString()
- : computeStateDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- state
- ).toString()
+ ? hass
+ .formatEntityAttributeValue(
+ stateObj,
+ trigger.attribute,
+ state
+ )
+ .toString()
+ : hass.formatEntityState(stateObj, state).toString()
);
}
if (to.length !== 0) {
@@ -318,23 +289,14 @@ const tryDescribeTrigger = (
} else {
base += ` to ${
trigger.attribute
- ? computeAttributeValueDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- trigger.attribute,
- trigger.to
- ).toString()
- : computeStateDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- trigger.to.toString()
- )
+ ? hass
+ .formatEntityAttributeValue(
+ stateObj,
+ trigger.attribute,
+ trigger.to
+ )
+ .toString()
+ : hass.formatEntityState(stateObj, trigger.to.toString())
}`;
}
}
@@ -822,45 +784,27 @@ const tryDescribeCondition = (
for (const state of condition.state.values()) {
states.push(
condition.attribute
- ? computeAttributeValueDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- condition.attribute,
- state
- ).toString()
- : computeStateDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- state
- )
+ ? hass
+ .formatEntityAttributeValue(
+ stateObj,
+ condition.attribute,
+ state
+ )
+ .toString()
+ : hass.formatEntityState(stateObj, state)
);
}
} else if (condition.state !== "") {
states.push(
condition.attribute
- ? computeAttributeValueDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- condition.attribute,
- condition.state
- ).toString()
- : computeStateDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- condition.state.toString()
- )
+ ? hass
+ .formatEntityAttributeValue(
+ stateObj,
+ condition.attribute,
+ condition.state
+ )
+ .toString()
+ : hass.formatEntityState(stateObj, condition.state.toString())
);
}
diff --git a/src/data/logbook.ts b/src/data/logbook.ts
index e4990da292..8534d548ce 100644
--- a/src/data/logbook.ts
+++ b/src/data/logbook.ts
@@ -5,14 +5,12 @@ import {
DOMAINS_WITH_DYNAMIC_PICTURE,
} from "../common/const";
import { computeDomain } from "../common/entity/compute_domain";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
import { computeStateDomain } from "../common/entity/compute_state_domain";
import { autoCaseNoun } from "../common/translations/auto_case_noun";
import { LocalizeFunc } from "../common/translations/localize";
import { HaEntityPickerEntityFilterFunc } from "../components/entity/ha-entity-picker";
import { HomeAssistant } from "../types";
import { UNAVAILABLE, UNKNOWN } from "./entity";
-import { computeAttributeValueDisplay } from "../common/entity/compute_attribute_display";
const LOGBOOK_LOCALIZE_PATH = "ui.components.logbook.messages";
export const CONTINUOUS_DOMAINS = ["counter", "proximity", "sensor", "zone"];
@@ -339,14 +337,9 @@ export const localizeStateMessage = (
// TODO: This is not working yet, as we don't get historic attribute values
- const event_type = computeAttributeValueDisplay(
- hass!.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- "event_type"
- )?.toString();
+ const event_type = hass
+ .formatEntityAttributeValue(stateObj, "event_type")
+ ?.toString();
if (!event_type) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.detected_unknown_event`);
@@ -392,16 +385,7 @@ export const localizeStateMessage = (
return hass.localize(
`${LOGBOOK_LOCALIZE_PATH}.changed_to_state`,
"state",
- stateObj
- ? computeStateDisplay(
- localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities,
- state
- )
- : state
+ stateObj ? hass.formatEntityState(stateObj, state) : state
);
};
diff --git a/src/data/timer.ts b/src/data/timer.ts
index 5401175d41..7dc4f8e41d 100644
--- a/src/data/timer.ts
+++ b/src/data/timer.ts
@@ -5,7 +5,6 @@ import {
} from "home-assistant-js-websocket";
import durationToSeconds from "../common/datetime/duration_to_seconds";
import secondsToDuration from "../common/datetime/seconds_to_duration";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
import { HomeAssistant } from "../types";
export type TimerEntity = HassEntityBase & {
@@ -90,25 +89,13 @@ export const computeDisplayTimer = (
}
if (stateObj.state === "idle" || timeRemaining === 0) {
- return computeStateDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities
- );
+ return hass.formatEntityState(stateObj);
}
let display = secondsToDuration(timeRemaining || 0);
if (stateObj.state === "paused") {
- display = `${display} (${computeStateDisplay(
- hass.localize,
- stateObj,
- hass.locale,
- hass.config,
- hass.entities
- )})`;
+ display = `${display} (${hass.formatEntityState(stateObj)})`;
}
return display;
diff --git a/src/dialogs/config-flow/previews/entity-preview-row.ts b/src/dialogs/config-flow/previews/entity-preview-row.ts
index 1ca2b10c13..5d5fa811fa 100644
--- a/src/dialogs/config-flow/previews/entity-preview-row.ts
+++ b/src/dialogs/config-flow/previews/entity-preview-row.ts
@@ -1,7 +1,6 @@
import { HassEntity } from "home-assistant-js-websocket";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name";
import { isUnavailableState } from "../../../data/entity";
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
@@ -35,13 +34,7 @@ class EntityPreviewRow extends LitElement {
capitalize
>
`
- : computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ : this.hass.formatEntityState(stateObj)}
`;
}
diff --git a/src/dialogs/more-info/components/climate/ha-more-info-climate-temperature.ts b/src/dialogs/more-info/components/climate/ha-more-info-climate-temperature.ts
index 25a18f810d..f0b1954f55 100644
--- a/src/dialogs/more-info/components/climate/ha-more-info-climate-temperature.ts
+++ b/src/dialogs/more-info/components/climate/ha-more-info-climate-temperature.ts
@@ -11,7 +11,6 @@ import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { styleMap } from "lit/directives/style-map";
import { UNIT_F } from "../../../../common/const";
-import { computeAttributeValueDisplay } from "../../../../common/entity/compute_attribute_display";
import { stateActive } from "../../../../common/entity/state_active";
import { stateColorCss } from "../../../../common/entity/state_color";
import { supportsFeature } from "../../../../common/entity/supports-feature";
@@ -162,14 +161,10 @@ export class HaMoreInfoClimateTemperature extends LitElement {
const action = this.stateObj.attributes.hvac_action;
- const actionLabel = computeAttributeValueDisplay(
- this.hass.localize,
+ const actionLabel = this.hass.formatEntityAttributeValue(
this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"hvac_action"
- ) as string;
+ );
return html`
diff --git a/src/dialogs/more-info/components/fan/ha-more-info-fan-speed.ts b/src/dialogs/more-info/components/fan/ha-more-info-fan-speed.ts
index 72333bd2a2..d1a641d6c5 100644
--- a/src/dialogs/more-info/components/fan/ha-more-info-fan-speed.ts
+++ b/src/dialogs/more-info/components/fan/ha-more-info-fan-speed.ts
@@ -2,7 +2,6 @@ import { css, CSSResultGroup, html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
import { computeAttributeNameDisplay } from "../../../../common/entity/compute_attribute_display";
-import { computeStateDisplay } from "../../../../common/entity/compute_state_display";
import { stateActive } from "../../../../common/entity/state_active";
import { stateColorCss } from "../../../../common/entity/state_color";
import "../../../../components/ha-control-select";
@@ -12,12 +11,12 @@ import { UNAVAILABLE } from "../../../../data/entity";
import {
computeFanSpeedCount,
computeFanSpeedIcon,
+ FAN_SPEED_COUNT_MAX_FOR_BUTTONS,
+ FAN_SPEEDS,
FanEntity,
fanPercentageToSpeed,
FanSpeed,
fanSpeedToPercentage,
- FAN_SPEEDS,
- FAN_SPEED_COUNT_MAX_FOR_BUTTONS,
} from "../../../../data/fan";
import { HomeAssistant } from "../../../../types";
@@ -68,14 +67,7 @@ export class HaMoreInfoFanSpeed extends LitElement {
private _localizeSpeed(speed: FanSpeed) {
if (speed === "on" || speed === "off") {
- return computeStateDisplay(
- this.hass.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- speed
- );
+ return this.hass.formatEntityState(this.stateObj, speed);
}
return (
this.hass.localize(`ui.dialogs.more_info_control.fan.speed.${speed}`) ||
diff --git a/src/dialogs/more-info/components/ha-more-info-state-header.ts b/src/dialogs/more-info/components/ha-more-info-state-header.ts
index 150058e89b..4697868390 100644
--- a/src/dialogs/more-info/components/ha-more-info-state-header.ts
+++ b/src/dialogs/more-info/components/ha-more-info-state-header.ts
@@ -1,7 +1,5 @@
-import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import "../../../components/ha-absolute-time";
import "../../../components/ha-relative-time";
import { isUnavailableState } from "../../../data/entity";
@@ -20,30 +18,22 @@ export class HaMoreInfoStateHeader extends LitElement {
@state() private _absoluteTime = false;
- private _computeStateDisplay(stateObj: HassEntity): TemplateResult | string {
+ private _localizeState(): TemplateResult | string {
if (
- stateObj.attributes.device_class === SENSOR_DEVICE_CLASS_TIMESTAMP &&
- !isUnavailableState(stateObj.state)
+ this.stateObj.attributes.device_class === SENSOR_DEVICE_CLASS_TIMESTAMP &&
+ !isUnavailableState(this.stateObj.state)
) {
return html`
`;
}
- const stateDisplay = computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass!.locale,
- this.hass!.config,
- this.hass!.entities
- );
-
- return stateDisplay;
+ return this.hass.formatEntityState(this.stateObj);
}
private _toggleAbsolute() {
@@ -51,8 +41,7 @@ export class HaMoreInfoStateHeader extends LitElement {
}
protected render(): TemplateResult {
- const stateDisplay =
- this.stateOverride ?? this._computeStateDisplay(this.stateObj);
+ const stateDisplay = this.stateOverride ?? this._localizeState();
return html`
${stateDisplay}
diff --git a/src/dialogs/more-info/components/humidifier/ha-more-info-humidifier-humidity.ts b/src/dialogs/more-info/components/humidifier/ha-more-info-humidifier-humidity.ts
index 1a3db1121c..d93f506f10 100644
--- a/src/dialogs/more-info/components/humidifier/ha-more-info-humidifier-humidity.ts
+++ b/src/dialogs/more-info/components/humidifier/ha-more-info-humidifier-humidity.ts
@@ -2,7 +2,6 @@ import { mdiMinus, mdiPlus } from "@mdi/js";
import { CSSResultGroup, LitElement, PropertyValues, css, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
-import { computeAttributeValueDisplay } from "../../../../common/entity/compute_attribute_display";
import { stateActive } from "../../../../common/entity/state_active";
import { stateColorCss } from "../../../../common/entity/state_color";
import { clamp } from "../../../../common/number/clamp";
@@ -92,14 +91,10 @@ export class HaMoreInfoHumidifierHumidity extends LitElement {
const action = this.stateObj.attributes.action;
- const actionLabel = computeAttributeValueDisplay(
- this.hass.localize,
+ const actionLabel = this.hass.formatEntityAttributeValue(
this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"action"
- ) as string;
+ );
return html`
diff --git a/src/dialogs/more-info/controls/more-info-cover.ts b/src/dialogs/more-info/controls/more-info-cover.ts
index d685d1bb63..02b2f2ec5a 100644
--- a/src/dialogs/more-info/controls/more-info-cover.ts
+++ b/src/dialogs/more-info/controls/more-info-cover.ts
@@ -1,22 +1,21 @@
import { mdiMenu, mdiSwapVertical } from "@mdi/js";
import {
- css,
CSSResultGroup,
- html,
LitElement,
- nothing,
PropertyValues,
+ css,
+ html,
+ nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/ha-attributes";
import "../../../components/ha-icon-button-group";
import "../../../components/ha-icon-button-toggle";
import {
- computeCoverPositionStateDisplay,
CoverEntity,
CoverEntityFeature,
+ computeCoverPositionStateDisplay,
} from "../../../data/cover";
import type { HomeAssistant } from "../../../types";
import "../components/cover/ha-more-info-cover-buttons";
@@ -83,12 +82,8 @@ class MoreInfoCover extends LitElement {
const forcedState =
liveValue != null ? (liveValue ? "open" : "closed") : undefined;
- const stateDisplay = computeStateDisplay(
- this.hass.localize,
+ const stateDisplay = this.hass.formatEntityState(
this.stateObj!,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
forcedState
);
diff --git a/src/dialogs/more-info/controls/more-info-humidifier.ts b/src/dialogs/more-info/controls/more-info-humidifier.ts
index 74754e25ad..d919753c86 100644
--- a/src/dialogs/more-info/controls/more-info-humidifier.ts
+++ b/src/dialogs/more-info/controls/more-info-humidifier.ts
@@ -10,11 +10,6 @@ import {
import { property, state } from "lit/decorators";
import { fireEvent } from "../../../common/dom/fire_event";
import { stopPropagation } from "../../../common/dom/stop_propagation";
-import {
- computeAttributeNameDisplay,
- computeAttributeValueDisplay,
-} from "../../../common/entity/compute_attribute_display";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/ha-control-select-menu";
import "../../../components/ha-list-item";
@@ -58,26 +53,21 @@ class MoreInfoHumidifier extends LitElement {
HumidifierEntityFeature.MODES
);
- const currentHumidity = this.stateObj.attributes.current_humidity as number;
-
return html`
- ${currentHumidity != null
+ ${this.stateObj.attributes.current_humidity != null
? html`
- ${computeAttributeNameDisplay(
- this.hass.localize,
+ ${this.hass.formatEntityAttributeName(
this.stateObj,
- this.hass.entities,
"current_humidity"
)}
${this.hass.formatEntityAttributeValue(
this.stateObj,
- "current_humidity",
- currentHumidity
+ "current_humidity"
)}
@@ -104,24 +94,10 @@ class MoreInfoHumidifier extends LitElement {
>
- ${computeStateDisplay(
- this.hass.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "off"
- )}
+ ${this.hass.formatEntityState(this.stateObj, "off")}
- ${computeStateDisplay(
- this.hass.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "on"
- )}
+ ${this.hass.formatEntityState(this.stateObj, "on")}
@@ -144,12 +120,8 @@ class MoreInfoHumidifier extends LitElement {
slot="graphic"
.path=${computeHumidiferModeIcon(mode)}
>
- ${computeAttributeValueDisplay(
- hass.localize,
+ ${this.hass.formatEntityAttributeValue(
stateObj!,
- hass.locale,
- hass.config,
- hass.entities,
"mode",
mode
)}
diff --git a/src/dialogs/more-info/controls/more-info-lawn_mower.ts b/src/dialogs/more-info/controls/more-info-lawn_mower.ts
index b2437bdb45..05a92ce1ce 100644
--- a/src/dialogs/more-info/controls/more-info-lawn_mower.ts
+++ b/src/dialogs/more-info/controls/more-info-lawn_mower.ts
@@ -2,7 +2,6 @@ import { mdiHomeImportOutline, mdiPause, mdiPlay } from "@mdi/js";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { blankBeforePercent } from "../../../common/translations/blank_before_percent";
@@ -74,15 +73,7 @@ class MoreInfoLawnMower extends LitElement {
)}:
-
- ${computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
-
+ ${this.hass.formatEntityState(stateObj)}
${this._renderBattery()}
diff --git a/src/dialogs/more-info/controls/more-info-media_player.ts b/src/dialogs/more-info/controls/more-info-media_player.ts
index 1d9fcbe0fc..044745d78d 100644
--- a/src/dialogs/more-info/controls/more-info-media_player.ts
+++ b/src/dialogs/more-info/controls/more-info-media_player.ts
@@ -9,24 +9,23 @@ import {
mdiVolumeOff,
mdiVolumePlus,
} from "@mdi/js";
-import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
+import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { stopPropagation } from "../../../common/dom/stop_propagation";
-import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
+import { stateActive } from "../../../common/entity/state_active";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
-import { stateActive } from "../../../common/entity/state_active";
import "../../../components/ha-icon-button";
import "../../../components/ha-select";
import "../../../components/ha-slider";
import "../../../components/ha-svg-icon";
import { showMediaBrowserDialog } from "../../../components/media-player/show-media-browser-dialog";
import {
- computeMediaControls,
- handleMediaControlClick,
MediaPickedEvent,
MediaPlayerEntity,
MediaPlayerEntityFeature,
+ computeMediaControls,
+ handleMediaControlClick,
mediaPlayerPlayMedia,
} from "../../../data/media-player";
import { HomeAssistant } from "../../../types";
@@ -157,24 +156,20 @@ class MoreInfoMediaPlayer extends LitElement {
>
${stateObj.attributes.source_list!.map(
(source) => html`
- ${computeAttributeValueDisplay(
- this.hass.localize,
+
+ ${this.hass.formatEntityAttributeValue(
stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"source",
source
- )}
+ )}
+
`
)}
`
- : ""}
+ : nothing}
${stateActive(stateObj) &&
supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOUND_MODE) &&
stateObj.attributes.sound_mode_list?.length
@@ -191,17 +186,13 @@ class MoreInfoMediaPlayer extends LitElement {
>
${stateObj.attributes.sound_mode_list.map(
(mode) => html`
- ${computeAttributeValueDisplay(
- this.hass.localize,
+
+ ${this.hass.formatEntityAttributeValue(
stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"sound_mode",
mode
- )}
+ )}
+
`
)}
diff --git a/src/dialogs/more-info/controls/more-info-remote.ts b/src/dialogs/more-info/controls/more-info-remote.ts
index 9080897c13..918ebd3a71 100644
--- a/src/dialogs/more-info/controls/more-info-remote.ts
+++ b/src/dialogs/more-info/controls/more-info-remote.ts
@@ -2,11 +2,10 @@ import "@material/mwc-list/mwc-list";
import "@material/mwc-list/mwc-list-item";
import { html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
-import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
import { stopPropagation } from "../../../common/dom/stop_propagation";
import { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/ha-attributes";
-import { RemoteEntity, REMOTE_SUPPORT_ACTIVITY } from "../../../data/remote";
+import { REMOTE_SUPPORT_ACTIVITY, RemoteEntity } from "../../../data/remote";
import { HomeAssistant } from "../../../types";
const filterExtraAttributes = "activity_list,current_activity";
@@ -40,12 +39,8 @@ class MoreInfoRemote extends LitElement {
${stateObj.attributes.activity_list!.map(
(activity) => html`
- ${computeAttributeValueDisplay(
- this.hass.localize,
+ ${this.hass.formatEntityAttributeValue(
stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"activity",
activity
)}
@@ -54,7 +49,7 @@ class MoreInfoRemote extends LitElement {
)}
`
- : ""}
+ : nothing}
${supportsFeature(stateObj, VacuumEntityFeature.STATUS) &&
stateObj.attributes.status
- ? computeAttributeValueDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "status"
- )
- : computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ ? this.hass.formatEntityAttributeValue(stateObj, "status")
+ : this.hass.formatEntityState(stateObj)}
@@ -197,12 +182,8 @@ class MoreInfoVacuum extends LitElement {
${stateObj.attributes.fan_speed_list!.map(
(mode) => html`
- ${computeAttributeValueDisplay(
- this.hass.localize,
+ ${this.hass.formatEntityAttributeValue(
stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"fan_speed",
mode
)}
@@ -215,12 +196,8 @@ class MoreInfoVacuum extends LitElement {
>
- ${computeAttributeValueDisplay(
- this.hass.localize,
+ ${this.hass.formatEntityAttributeValue(
stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"fan_speed"
)}
diff --git a/src/dialogs/notifications/configurator-notification-item.ts b/src/dialogs/notifications/configurator-notification-item.ts
index 96174e02a1..306b0f40be 100644
--- a/src/dialogs/notifications/configurator-notification-item.ts
+++ b/src/dialogs/notifications/configurator-notification-item.ts
@@ -2,7 +2,6 @@ import "@material/mwc-button";
import { html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event";
-import { computeStateDisplay } from "../../common/entity/compute_state_display";
import { domainToName } from "../../data/integration";
import { PersitentNotificationEntity } from "../../data/persistent_notification";
import { HomeAssistant } from "../../types";
@@ -33,15 +32,9 @@ export class HuiConfiguratorNotificationItem extends LitElement {
)}
- ${computeStateDisplay(
- this.hass.localize,
- this.notification,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+
+ ${this.hass.formatEntityState(this.notification)}
+
`;
}
diff --git a/src/panels/lovelace/cards/hui-entity-card.ts b/src/panels/lovelace/cards/hui-entity-card.ts
index 7acee6c5d2..be1d5102d5 100644
--- a/src/panels/lovelace/cards/hui-entity-card.ts
+++ b/src/panels/lovelace/cards/hui-entity-card.ts
@@ -12,7 +12,6 @@ import { ifDefined } from "lit/directives/if-defined";
import { styleMap } from "lit/directives/style-map";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { fireEvent } from "../../../common/dom/fire_event";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
import { computeStateName } from "../../../common/entity/compute_state_name";
import {
@@ -176,13 +175,7 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
this.hass.entities[this._config.entity]
)
)
- : computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}${showUnit
? html`
`
- : computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass!.locale,
- this.hass!.config,
- this.hass!.entities
- )}
+ : this.hass!.formatEntityState(stateObj)}
`
: ""}
diff --git a/src/panels/lovelace/cards/hui-humidifier-card.ts b/src/panels/lovelace/cards/hui-humidifier-card.ts
index 3aae9d2bf5..eae7103ec3 100644
--- a/src/panels/lovelace/cards/hui-humidifier-card.ts
+++ b/src/panels/lovelace/cards/hui-humidifier-card.ts
@@ -11,12 +11,10 @@ import {
svg,
} from "lit";
import { customElement, property, query, state } from "lit/decorators";
-import { styleMap } from "lit/directives/style-map";
import { classMap } from "lit/directives/class-map";
+import { styleMap } from "lit/directives/style-map";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { fireEvent } from "../../../common/dom/fire_event";
-import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name";
import { stateColorCss } from "../../../common/entity/state_color";
import { formatNumber } from "../../../common/number/format_number";
@@ -168,34 +166,13 @@ export class HuiHumidifierCard extends LitElement implements LovelaceCard {
>
${
stateObj.attributes.action
- ? computeAttributeValueDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "action"
- )
- : computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )
+ ? this.hass.formatEntityAttributeValue(stateObj, "action")
+ : this.hass.formatEntityState(stateObj)
}
${
stateObj.state !== UNAVAILABLE && stateObj.attributes.mode
? html`
- -
- ${computeAttributeValueDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "mode"
- )}
+ - ${this.hass.formatEntityAttributeValue(stateObj, "mode")}
`
: nothing
}
diff --git a/src/panels/lovelace/cards/hui-light-card.ts b/src/panels/lovelace/cards/hui-light-card.ts
index c2715b8007..308423d55a 100644
--- a/src/panels/lovelace/cards/hui-light-card.ts
+++ b/src/panels/lovelace/cards/hui-light-card.ts
@@ -1,11 +1,11 @@
import { mdiDotsVertical } from "@mdi/js";
import "@thomasloven/round-slider";
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -13,12 +13,12 @@ import { classMap } from "lit/directives/class-map";
import { styleMap } from "lit/directives/style-map";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { fireEvent } from "../../../common/dom/fire_event";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name";
+import { stateColorBrightness } from "../../../common/entity/state_color";
import "../../../components/ha-card";
import "../../../components/ha-icon-button";
import "../../../components/ha-state-icon";
-import { isUnavailableState, UNAVAILABLE } from "../../../data/entity";
+import { UNAVAILABLE, isUnavailableState } from "../../../data/entity";
import { LightEntity, lightSupportsBrightness } from "../../../data/light";
import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
@@ -30,7 +30,6 @@ import { hasConfigOrEntityChanged } from "../common/has-changed";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { LightCardConfig } from "./types";
-import { stateColorBrightness } from "../../../common/entity/state_color";
@customElement("hui-light-card")
export class HuiLightCard extends LitElement implements LovelaceCard {
@@ -156,17 +155,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
${isUnavailableState(stateObj.state)
- ? html`
-
- ${computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
-
- `
+ ? html`
${this.hass.formatEntityState(stateObj)}
`
: html`
%
`}
${name}
diff --git a/src/panels/lovelace/cards/hui-picture-entity-card.ts b/src/panels/lovelace/cards/hui-picture-entity-card.ts
index f1889d8f23..3f89389dad 100644
--- a/src/panels/lovelace/cards/hui-picture-entity-card.ts
+++ b/src/panels/lovelace/cards/hui-picture-entity-card.ts
@@ -1,20 +1,19 @@
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
TemplateResult,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { computeDomain } from "../../../common/entity/compute_domain";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name";
import "../../../components/ha-card";
-import { computeImageUrl, ImageEntity } from "../../../data/image";
+import { ImageEntity, computeImageUrl } from "../../../data/image";
import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive";
@@ -120,13 +119,7 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
}
const name = this._config.name || computeStateName(stateObj);
- const entityState = computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- );
+ const entityState = this.hass.formatEntityState(stateObj);
let footer: TemplateResult | string = "";
if (this._config.show_name && this._config.show_state) {
diff --git a/src/panels/lovelace/cards/hui-picture-glance-card.ts b/src/panels/lovelace/cards/hui-picture-glance-card.ts
index d8210fe807..289df6bf33 100644
--- a/src/panels/lovelace/cards/hui-picture-glance-card.ts
+++ b/src/panels/lovelace/cards/hui-picture-glance-card.ts
@@ -13,7 +13,6 @@ import { ifDefined } from "lit/directives/if-defined";
import { DOMAINS_TOGGLE } from "../../../common/const";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { computeDomain } from "../../../common/entity/compute_domain";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name";
import "../../../components/ha-card";
import "../../../components/ha-icon-button";
@@ -273,13 +272,9 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
class=${classMap({
"state-on": !STATES_OFF.has(stateObj.state),
})}
- title=${`${computeStateName(stateObj)} : ${computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass!.locale,
- this.hass!.config,
- this.hass!.entities
- )}`}
+ title=${`${computeStateName(
+ stateObj
+ )} : ${this.hass.formatEntityState(stateObj)}`}
>
`}
diff --git a/src/panels/lovelace/cards/hui-thermostat-card.ts b/src/panels/lovelace/cards/hui-thermostat-card.ts
index f26273f4ee..76de3ee618 100644
--- a/src/panels/lovelace/cards/hui-thermostat-card.ts
+++ b/src/panels/lovelace/cards/hui-thermostat-card.ts
@@ -11,12 +11,12 @@ import {
import "@thomasloven/round-slider";
import { HassEntity } from "home-assistant-js-websocket";
import {
- css,
CSSResultGroup,
- html,
LitElement,
- nothing,
PropertyValues,
+ css,
+ html,
+ nothing,
svg,
} from "lit";
import { customElement, property, query, state } from "lit/decorators";
@@ -25,8 +25,6 @@ import { styleMap } from "lit/directives/style-map";
import { UNIT_F } from "../../../common/const";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { fireEvent } from "../../../common/dom/fire_event";
-import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name";
import { stateColorCss } from "../../../common/entity/state_color";
import { formatNumber } from "../../../common/number/format_number";
@@ -34,10 +32,10 @@ import "../../../components/ha-card";
import type { HaCard } from "../../../components/ha-card";
import "../../../components/ha-icon-button";
import {
- ClimateEntity,
CLIMATE_PRESET_NONE,
- compareClimateHvacModes,
+ ClimateEntity,
HvacMode,
+ compareClimateHvacModes,
} from "../../../data/climate";
import { UNAVAILABLE } from "../../../data/entity";
import { HomeAssistant } from "../../../types";
@@ -207,21 +205,8 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
>
${
stateObj.state !== UNAVAILABLE && stateObj.attributes.hvac_action
- ? computeAttributeValueDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "hvac_action"
- )
- : computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )
+ ? this.hass.formatEntityAttributeValue(stateObj, "hvac_action")
+ : this.hass.formatEntityState(stateObj)
}
${
stateObj.state !== UNAVAILABLE &&
@@ -229,12 +214,8 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
stateObj.attributes.preset_mode !== CLIMATE_PRESET_NONE
? html`
-
- ${computeAttributeValueDisplay(
- this.hass.localize,
+ ${this.hass.formatEntityAttributeValue(
stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
"preset_mode"
)}
`
diff --git a/src/panels/lovelace/cards/hui-tile-card.ts b/src/panels/lovelace/cards/hui-tile-card.ts
index a0f7e8bcf9..915bed56d4 100644
--- a/src/panels/lovelace/cards/hui-tile-card.ts
+++ b/src/panels/lovelace/cards/hui-tile-card.ts
@@ -180,7 +180,7 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
}
);
- private _computeStateDisplay(stateObj: HassEntity): TemplateResult | string {
+ private _formatState(stateObj: HassEntity): TemplateResult | string {
const domain = computeDomain(stateObj.entity_id);
if (
@@ -308,7 +308,7 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
const name = this._config.name || stateObj.attributes.friendly_name;
- const stateDisplay = this._computeStateDisplay(stateObj);
+ const localizedState = this._formatState(stateObj);
const active = stateActive(stateObj);
const color = this._computeStateColor(stateObj, this._config.color);
@@ -381,7 +381,7 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
diff --git a/src/panels/lovelace/cards/hui-weather-forecast-card.ts b/src/panels/lovelace/cards/hui-weather-forecast-card.ts
index 2dfd3a3a88..dec8eac04c 100644
--- a/src/panels/lovelace/cards/hui-weather-forecast-card.ts
+++ b/src/panels/lovelace/cards/hui-weather-forecast-card.ts
@@ -1,16 +1,16 @@
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
+import { formatDateWeekdayShort } from "../../../common/datetime/format_date";
import { formatTime } from "../../../common/datetime/format_time";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name";
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
import { formatNumber } from "../../../common/number/format_number";
@@ -20,28 +20,27 @@ import "../../../components/ha-svg-icon";
import { UNAVAILABLE } from "../../../data/entity";
import { ActionHandlerEvent } from "../../../data/lovelace";
import {
+ ForecastEvent,
+ WeatherEntity,
getForecast,
getSecondaryWeatherAttribute,
getWeatherStateIcon,
getWeatherUnit,
getWind,
subscribeForecast,
- ForecastEvent,
weatherAttrIcons,
- WeatherEntity,
weatherSVGStyles,
} from "../../../data/weather";
+import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import type { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive";
import { findEntities } from "../common/find-entities";
import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action";
import { hasConfigOrEntityChanged } from "../common/has-changed";
-import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import type { LovelaceCard, LovelaceCardEditor } from "../types";
import type { WeatherForecastCardConfig } from "./types";
-import { formatDateWeekdayShort } from "../../../common/datetime/format_date";
@customElement("hui-weather-forecast-card")
class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
@@ -265,13 +264,7 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
- ${computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ ${this.hass.formatEntityState(stateObj)}
${name}
diff --git a/src/panels/lovelace/elements/hui-state-label-element.ts b/src/panels/lovelace/elements/hui-state-label-element.ts
index d7f3ce9872..a0427bdbcd 100644
--- a/src/panels/lovelace/elements/hui-state-label-element.ts
+++ b/src/panels/lovelace/elements/hui-state-label-element.ts
@@ -1,14 +1,13 @@
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
import { computeTooltip } from "../common/compute-tooltip";
@@ -83,13 +82,7 @@ class HuiStateLabelElement extends LitElement implements LovelaceElement {
)}
>
${this._config.prefix}${!this._config.attribute
- ? computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )
+ ? this.hass.formatEntityState(stateObj)
: stateObj.attributes[this._config.attribute]}${this._config.suffix}
`;
diff --git a/src/panels/lovelace/entity-rows/hui-event-entity-row.ts b/src/panels/lovelace/entity-rows/hui-event-entity-row.ts
index f7abad2349..565d046cae 100644
--- a/src/panels/lovelace/entity-rows/hui-event-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-event-entity-row.ts
@@ -1,14 +1,12 @@
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
-import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
import { isUnavailableState } from "../../../data/entity";
import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
@@ -70,13 +68,7 @@ class HuiEventEntityRow extends LitElement implements LovelaceRow {
>
${isUnavailableState(stateObj.state)
- ? computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )
+ ? this.hass.formatEntityState(stateObj)
: html`
${isUnavailableState(stateObj.state)
- ? ``
- : computeAttributeValueDisplay(
- this.hass!.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "event_type"
- )}
+ ? nothing
+ : this.hass.formatEntityAttributeValue(stateObj, "event_type")}
diff --git a/src/panels/lovelace/entity-rows/hui-group-entity-row.ts b/src/panels/lovelace/entity-rows/hui-group-entity-row.ts
index 146943251e..a530bdeabe 100644
--- a/src/panels/lovelace/entity-rows/hui-group-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-group-entity-row.ts
@@ -1,8 +1,7 @@
-import { html, LitElement, PropertyValues, nothing } from "lit";
+import { LitElement, PropertyValues, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { DOMAINS_TOGGLE } from "../../../common/const";
import { computeDomain } from "../../../common/entity/compute_domain";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import "../../../components/entity/ha-entity-toggle";
import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
@@ -66,13 +65,7 @@ class HuiGroupEntityRow extends LitElement implements LovelaceRow {
`
: html`
- ${computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ ${this.hass.formatEntityState(stateObj)}
`}
diff --git a/src/panels/lovelace/entity-rows/hui-input-number-entity-row.ts b/src/panels/lovelace/entity-rows/hui-input-number-entity-row.ts
index 9281d2391f..41bbd14f69 100644
--- a/src/panels/lovelace/entity-rows/hui-input-number-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-input-number-entity-row.ts
@@ -1,22 +1,21 @@
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-slider";
import "../../../components/ha-textfield";
import { isUnavailableState } from "../../../data/entity";
import { setValue } from "../../../data/input_text";
+import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
-import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import "../components/hui-generic-entity-row";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { EntityConfig, LovelaceRow } from "./types";
@@ -97,14 +96,7 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
ignore-bar-touch
>
- ${computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- stateObj.state
- )}
+ ${this.hass.formatEntityState(stateObj)}
`
diff --git a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts
index daf1aa150c..36bc2bb76a 100644
--- a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts
@@ -13,31 +13,30 @@ import {
} from "@mdi/js";
import { HassEntity } from "home-assistant-js-websocket";
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
+import { stateActive } from "../../../common/entity/state_active";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
-import { stateActive } from "../../../common/entity/state_active";
import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-icon-button";
import "../../../components/ha-slider";
import { isUnavailableState } from "../../../data/entity";
import {
- computeMediaDescription,
ControlButton,
MediaPlayerEntity,
MediaPlayerEntityFeature,
+ computeMediaDescription,
} from "../../../data/media-player";
+import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import type { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
-import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import "../components/hui-generic-entity-row";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import type { EntityConfig, LovelaceRow } from "./types";
@@ -191,13 +190,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
.hass=${this.hass}
.config=${this._config}
.secondaryText=${mediaDescription ||
- computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ this.hass.formatEntityState(stateObj)}
>
${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON) &&
diff --git a/src/panels/lovelace/entity-rows/hui-number-entity-row.ts b/src/panels/lovelace/entity-rows/hui-number-entity-row.ts
index 7b4d2a6848..83fabc5f5b 100644
--- a/src/panels/lovelace/entity-rows/hui-number-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-number-entity-row.ts
@@ -1,22 +1,21 @@
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-slider";
import "../../../components/ha-textfield";
import { UNAVAILABLE } from "../../../data/entity";
import { setValue } from "../../../data/input_text";
+import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
-import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import "../components/hui-generic-entity-row";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { EntityConfig, LovelaceRow } from "./types";
@@ -101,14 +100,7 @@ class HuiNumberEntityRow extends LitElement implements LovelaceRow {
ignore-bar-touch
>
- ${computeStateDisplay(
- this.hass.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- stateObj.state
- )}
+ ${this.hass.formatEntityState(stateObj)}
`
diff --git a/src/panels/lovelace/entity-rows/hui-select-entity-row.ts b/src/panels/lovelace/entity-rows/hui-select-entity-row.ts
index 31b51927c1..f65c945004 100644
--- a/src/panels/lovelace/entity-rows/hui-select-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-select-entity-row.ts
@@ -1,15 +1,14 @@
import "@material/mwc-list/mwc-list-item";
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { stopPropagation } from "../../../common/dom/stop_propagation";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name";
import "../../../components/ha-select";
import { UNAVAILABLE } from "../../../data/entity";
@@ -77,14 +76,7 @@ class HuiSelectEntityRow extends LitElement implements LovelaceRow {
? stateObj.attributes.options.map(
(option) => html`
- ${computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass!.locale,
- this.hass!.config,
- this.hass!.entities,
- option
- )}
+ ${this.hass!.formatEntityState(stateObj, option)}
`
)
diff --git a/src/panels/lovelace/entity-rows/hui-sensor-entity-row.ts b/src/panels/lovelace/entity-rows/hui-sensor-entity-row.ts
index 0d536ca9f9..5f6dec0d22 100644
--- a/src/panels/lovelace/entity-rows/hui-sensor-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-sensor-entity-row.ts
@@ -1,13 +1,12 @@
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { isUnavailableState } from "../../../data/entity";
import { ActionHandlerEvent } from "../../../data/lovelace";
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
@@ -79,13 +78,7 @@ class HuiSensorEntityRow extends LitElement implements LovelaceRow {
capitalize
>
`
- : computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ : this.hass.formatEntityState(stateObj)}
`;
diff --git a/src/panels/lovelace/entity-rows/hui-simple-entity-row.ts b/src/panels/lovelace/entity-rows/hui-simple-entity-row.ts
index 23b4cb8720..604c632820 100644
--- a/src/panels/lovelace/entity-rows/hui-simple-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-simple-entity-row.ts
@@ -1,13 +1,12 @@
import {
- css,
CSSResultGroup,
- html,
LitElement,
PropertyValues,
+ css,
+ html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { HomeAssistant } from "../../../types";
import { EntitiesCardEntityConfig } from "../cards/types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
@@ -49,13 +48,7 @@ class HuiSimpleEntityRow extends LitElement implements LovelaceRow {
return html`
- ${computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ ${this.hass.formatEntityState(stateObj)}
`;
}
diff --git a/src/panels/lovelace/entity-rows/hui-toggle-entity-row.ts b/src/panels/lovelace/entity-rows/hui-toggle-entity-row.ts
index 611fd2bdd5..376447f7a5 100644
--- a/src/panels/lovelace/entity-rows/hui-toggle-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-toggle-entity-row.ts
@@ -1,6 +1,5 @@
-import { html, LitElement, PropertyValues, nothing } from "lit";
+import { LitElement, PropertyValues, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import "../../../components/entity/ha-entity-toggle";
import { isUnavailableState } from "../../../data/entity";
import { HomeAssistant } from "../../../types";
@@ -61,13 +60,7 @@ class HuiToggleEntityRow extends LitElement implements LovelaceRow {
`
: html`
- ${computeStateDisplay(
- this.hass!.localize,
- stateObj,
- this.hass!.locale,
- this.hass.config,
- this.hass!.entities
- )}
+ ${this.hass.formatEntityState(stateObj)}
`}
diff --git a/src/panels/lovelace/tile-features/hui-fan-speed-tile-feature.ts b/src/panels/lovelace/tile-features/hui-fan-speed-tile-feature.ts
index da69431ad0..8e6804d1f4 100644
--- a/src/panels/lovelace/tile-features/hui-fan-speed-tile-feature.ts
+++ b/src/panels/lovelace/tile-features/hui-fan-speed-tile-feature.ts
@@ -3,7 +3,6 @@ import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { computeAttributeNameDisplay } from "../../../common/entity/compute_attribute_display";
import { computeDomain } from "../../../common/entity/compute_domain";
-import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { stateActive } from "../../../common/entity/state_active";
import { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/ha-control-select";
@@ -13,13 +12,13 @@ import { UNAVAILABLE } from "../../../data/entity";
import {
computeFanSpeedCount,
computeFanSpeedIcon,
+ FAN_SPEED_COUNT_MAX_FOR_BUTTONS,
+ FAN_SPEEDS,
FanEntity,
FanEntityFeature,
fanPercentageToSpeed,
FanSpeed,
fanSpeedToPercentage,
- FAN_SPEEDS,
- FAN_SPEED_COUNT_MAX_FOR_BUTTONS,
} from "../../../data/fan";
import { HomeAssistant } from "../../../types";
import { LovelaceTileFeature } from "../types";
@@ -55,14 +54,7 @@ class HuiFanSpeedTileFeature extends LitElement implements LovelaceTileFeature {
private _localizeSpeed(speed: FanSpeed) {
if (speed === "on" || speed === "off") {
- return computeStateDisplay(
- this.hass!.localize,
- this.stateObj!,
- this.hass!.locale,
- this.hass!.config,
- this.hass!.entities,
- speed
- );
+ return this.hass!.formatEntityState(this.stateObj!, speed);
}
return (
this.hass!.localize(`ui.dialogs.more_info_control.fan.speed.${speed}`) ||
diff --git a/src/state-summary/state-card-alert.ts b/src/state-summary/state-card-alert.ts
index 151637490b..70a4f1fd0a 100755
--- a/src/state-summary/state-card-alert.ts
+++ b/src/state-summary/state-card-alert.ts
@@ -1,11 +1,10 @@
import type { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
+import { stateActive } from "../common/entity/state_active";
import { computeRTL } from "../common/util/compute_rtl";
import "../components/entity/state-info";
import { haStyle } from "../resources/styles";
-import { stateActive } from "../common/entity/state_active";
import type { HomeAssistant } from "../types";
@customElement("state-card-alert")
@@ -34,13 +33,7 @@ export class StateCardAlert extends LitElement {
.hass=${this.hass}
.stateObj=${this.stateObj}
>`
- : computeStateDisplay(
- this.hass!.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ : this.hass.formatEntityState(this.stateObj)}
`;
diff --git a/src/state-summary/state-card-display.ts b/src/state-summary/state-card-display.ts
index a168d05711..7ddc3074db 100755
--- a/src/state-summary/state-card-display.ts
+++ b/src/state-summary/state-card-display.ts
@@ -3,7 +3,6 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { computeDomain } from "../common/entity/compute_domain";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
import { computeRTL } from "../common/util/compute_rtl";
import "../components/entity/state-info";
import { isUnavailableState } from "../data/entity";
@@ -48,13 +47,7 @@ export class StateCardDisplay extends LitElement {
format="datetime"
capitalize
>`
- : computeStateDisplay(
- this.hass!.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ : this.hass.formatEntityState(this.stateObj)}
`;
diff --git a/src/state-summary/state-card-event.ts b/src/state-summary/state-card-event.ts
index 325bc88d69..7ec097a594 100644
--- a/src/state-summary/state-card-event.ts
+++ b/src/state-summary/state-card-event.ts
@@ -3,10 +3,8 @@ import { css, CSSResultGroup, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import "../components/entity/ha-entity-toggle";
import "../components/entity/state-info";
-import { HomeAssistant } from "../types";
-import { computeAttributeValueDisplay } from "../common/entity/compute_attribute_display";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
import { haStyle } from "../resources/styles";
+import { HomeAssistant } from "../types";
@customElement("state-card-event")
export class StateCardEvent extends LitElement {
@@ -26,23 +24,10 @@ export class StateCardEvent extends LitElement {
>
- ${computeStateDisplay(
- this.hass!.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities
- )}
+ ${this.hass.formatEntityState(this.stateObj)}
- ${computeAttributeValueDisplay(
- this.hass!.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- "event_type"
- )}
+ ${this.hass.formatEntityAttributeValue(this.stateObj, "event_type")}
diff --git a/src/state-summary/state-card-input_number.ts b/src/state-summary/state-card-input_number.ts
index 6deb14392b..0b3d3b822f 100644
--- a/src/state-summary/state-card-input_number.ts
+++ b/src/state-summary/state-card-input_number.ts
@@ -1,16 +1,15 @@
-import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { HassEntity } from "home-assistant-js-websocket";
+import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
import { computeRTLDirection } from "../common/util/compute_rtl";
import { debounce } from "../common/util/debounce";
+import "../components/entity/state-info";
import "../components/ha-slider";
import "../components/ha-textfield";
-import "../components/entity/state-info";
import { isUnavailableState } from "../data/entity";
import { setValue } from "../data/input_text";
-import { HomeAssistant } from "../types";
import { loadPolyfillIfNeeded } from "../resources/resize-observer.polyfill";
+import { HomeAssistant } from "../types";
@customElement("state-card-input_number")
class StateCardInputNumber extends LitElement {
@@ -69,14 +68,7 @@ class StateCardInputNumber extends LitElement {
ignore-bar-touch
>
- ${computeStateDisplay(
- this.hass.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- this.stateObj.state
- )}
+ ${this.hass.formatEntityState(this.stateObj)}
`
diff --git a/src/state-summary/state-card-select.ts b/src/state-summary/state-card-select.ts
index 4e6b48c9dc..72f79d97a9 100644
--- a/src/state-summary/state-card-select.ts
+++ b/src/state-summary/state-card-select.ts
@@ -1,14 +1,13 @@
import "@material/mwc-list/mwc-list-item";
-import "../components/ha-select";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import { stopPropagation } from "../common/dom/stop_propagation";
import { computeStateName } from "../common/entity/compute_state_name";
import "../components/entity/state-badge";
+import "../components/ha-select";
import { UNAVAILABLE } from "../data/entity";
import { SelectEntity, setSelectOption } from "../data/select";
import type { HomeAssistant } from "../types";
-import { computeStateDisplay } from "../common/entity/compute_state_display";
@customElement("state-card-select")
class StateCardSelect extends LitElement {
@@ -31,14 +30,7 @@ class StateCardSelect extends LitElement {
${this.stateObj.attributes.options.map(
(option) => html`
- ${computeStateDisplay(
- this.hass.localize,
- this.stateObj,
- this.hass.locale,
- this.hass.config,
- this.hass.entities,
- option
- )}
+ ${this.hass.formatEntityState(this.stateObj, option)}
`
)}