Use format entity state helpers everywhere (#17757)

This commit is contained in:
Paul Bottein 2023-09-01 15:26:46 +02:00 committed by GitHub
parent 0d0fe75f4e
commit c8feded4f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 240 additions and 716 deletions

View File

@ -1,11 +1,9 @@
import { HassEntity } from "home-assistant-js-websocket"; 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 { customElement, property, query } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { computeStateDisplay } from "../../common/entity/compute_state_display";
import { getStates } from "../../common/entity/get_states"; import { getStates } from "../../common/entity/get_states";
import { computeAttributeValueDisplay } from "../../common/entity/compute_attribute_display"; import { HomeAssistant, ValueChangedEvent } from "../../types";
import { ValueChangedEvent, HomeAssistant } from "../../types";
import "../ha-combo-box"; import "../ha-combo-box";
import type { HaComboBox } from "../ha-combo-box"; import type { HaComboBox } from "../ha-combo-box";
@ -58,20 +56,9 @@ class HaEntityStatePicker extends LitElement {
? getStates(state, this.attribute).map((key) => ({ ? getStates(state, this.attribute).map((key) => ({
value: key, value: key,
label: !this.attribute label: !this.attribute
? computeStateDisplay( ? this.hass.formatEntityState(state, key)
this.hass.localize, : this.hass.formatEntityAttributeValue(
state, 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, this.attribute,
key key
), ),

View File

@ -12,7 +12,6 @@ import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
import { arrayLiteralIncludes } from "../../common/array/literal-includes"; import { arrayLiteralIncludes } from "../../common/array/literal-includes";
import secondsToDuration from "../../common/datetime/seconds_to_duration"; 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 { computeStateDomain } from "../../common/entity/compute_state_domain";
import { computeStateName } from "../../common/entity/compute_state_name"; import { computeStateName } from "../../common/entity/compute_state_name";
import { FIXED_DOMAIN_STATES } from "../../common/entity/get_states"; import { FIXED_DOMAIN_STATES } from "../../common/entity/get_states";
@ -192,13 +191,7 @@ export class HaStateLabelBadge extends LitElement {
this.hass!.locale, this.hass!.locale,
getNumberFormatOptions(entityState, entry) getNumberFormatOptions(entityState, entry)
) )
: computeStateDisplay( : this.hass!.formatEntityState(entityState);
this.hass!.localize,
entityState,
this.hass!.locale,
this.hass!.config,
this.hass!.entities
);
} }
} }

View File

@ -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 { 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 { CLIMATE_PRESET_NONE, ClimateEntity } from "../data/climate";
import { isUnavailableState } from "../data/entity"; import { isUnavailableState, OFF } from "../data/entity";
import type { HomeAssistant } from "../types"; import type { HomeAssistant } from "../types";
@customElement("ha-climate-state") @customElement("ha-climate-state")
@ -22,26 +27,24 @@ class HaClimateState extends LitElement {
${this.stateObj.attributes.preset_mode && ${this.stateObj.attributes.preset_mode &&
this.stateObj.attributes.preset_mode !== CLIMATE_PRESET_NONE this.stateObj.attributes.preset_mode !== CLIMATE_PRESET_NONE
? html`- ? html`-
${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(
this.hass.localize,
this.stateObj, this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"preset_mode" "preset_mode"
)}` )}`
: ""} : nothing}
</span> </span>
<div class="unit">${this._computeTarget()}</div>` <div class="unit">${this._computeTarget()}</div>`
: this._localizeState()} : this._localizeState()}
</div> </div>
${currentStatus && !isUnavailableState(this.stateObj.state) ${currentStatus && !isUnavailableState(this.stateObj.state)
? html`<div class="current"> ? html`
<div class="current">
${this.hass.localize("ui.card.climate.currently")}: ${this.hass.localize("ui.card.climate.currently")}:
<div class="unit">${currentStatus}</div> <div class="unit">${currentStatus}</div>
</div>` </div>
: ""}`; `
: nothing}`;
} }
private _computeCurrentStatus(): string | undefined { private _computeCurrentStatus(): string | undefined {
@ -125,24 +128,17 @@ class HaClimateState extends LitElement {
return this.hass.localize(`state.default.${this.stateObj.state}`); return this.hass.localize(`state.default.${this.stateObj.state}`);
} }
const stateString = computeStateDisplay( const stateString = this.hass.formatEntityState(this.stateObj);
this.hass.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
return this.stateObj.attributes.hvac_action if (this.stateObj.attributes.hvac_action && this.stateObj.state !== OFF) {
? `${computeAttributeValueDisplay( const actionString = this.hass.formatEntityAttributeValue(
this.hass.localize,
this.stateObj, this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"hvac_action" "hvac_action"
)} (${stateString})` );
: stateString; return `${actionString} (${stateString})`;
}
return stateString;
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -1,7 +1,5 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; 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 { isUnavailableState, OFF } from "../data/entity";
import { HumidifierEntity } from "../data/humidifier"; import { HumidifierEntity } from "../data/humidifier";
import type { HomeAssistant } from "../types"; import type { HomeAssistant } from "../types";
@ -21,12 +19,8 @@ class HaHumidifierState extends LitElement {
${this._localizeState()} ${this._localizeState()}
${this.stateObj.attributes.mode ${this.stateObj.attributes.mode
? html`- ? html`-
${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(
this.hass.localize,
this.stateObj, this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"mode" "mode"
)}` )}`
: ""} : ""}
@ -78,24 +72,17 @@ class HaHumidifierState extends LitElement {
return this.hass.localize(`state.default.${this.stateObj.state}`); return this.hass.localize(`state.default.${this.stateObj.state}`);
} }
const stateString = computeStateDisplay( const stateString = this.hass.formatEntityState(this.stateObj);
this.hass.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
return this.stateObj.attributes.action && this.stateObj.state !== OFF if (this.stateObj.attributes.action && this.stateObj.state !== OFF) {
? `${computeAttributeValueDisplay( const actionString = this.hass.formatEntityAttributeValue(
this.hass.localize,
this.stateObj, this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"action" "action"
)} (${stateString})` );
: stateString; return `${actionString} (${stateString})`;
}
return stateString;
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -1,7 +1,6 @@
import { html } from "@polymer/polymer/lib/utils/html-tag"; import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */ /* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element"; import { PolymerElement } from "@polymer/polymer/polymer-element";
import { computeStateDisplay } from "../common/entity/compute_state_display";
import { formatNumber } from "../common/number/format_number"; import { formatNumber } from "../common/number/format_number";
import LocalizeMixin from "../mixins/localize-mixin"; import LocalizeMixin from "../mixins/localize-mixin";
@ -84,12 +83,7 @@ class HaWaterHeaterState extends LocalizeMixin(PolymerElement) {
} }
_localizeState(stateObj) { _localizeState(stateObj) {
return computeStateDisplay( return this.hass.formatEntityState(stateObj);
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.entities
);
} }
} }
customElements.define("ha-water_heater-state", HaWaterHeaterState); customElements.define("ha-water_heater-state", HaWaterHeaterState);

View File

@ -6,11 +6,7 @@ import {
formatTimeWithSeconds, formatTimeWithSeconds,
} from "../common/datetime/format_time"; } from "../common/datetime/format_time";
import secondsToDuration from "../common/datetime/seconds_to_duration"; import secondsToDuration from "../common/datetime/seconds_to_duration";
import { import { computeAttributeNameDisplay } from "../common/entity/compute_attribute_display";
computeAttributeNameDisplay,
computeAttributeValueDisplay,
} from "../common/entity/compute_attribute_display";
import { computeStateDisplay } from "../common/entity/compute_state_display";
import { computeStateName } from "../common/entity/compute_state_name"; import { computeStateName } from "../common/entity/compute_state_name";
import "../resources/intl-polyfill"; import "../resources/intl-polyfill";
import type { HomeAssistant } from "../types"; import type { HomeAssistant } from "../types";
@ -235,23 +231,14 @@ const tryDescribeTrigger = (
for (const state of trigger.from.values()) { for (const state of trigger.from.values()) {
from.push( from.push(
trigger.attribute trigger.attribute
? computeAttributeValueDisplay( ? hass
hass.localize, .formatEntityAttributeValue(
stateObj, stateObj,
hass.locale,
hass.config,
hass.entities,
trigger.attribute, trigger.attribute,
state state
).toString()
: computeStateDisplay(
hass.localize,
stateObj,
hass.locale,
hass.config,
hass.entities,
state
) )
.toString()
: hass.formatEntityState(stateObj, state)
); );
} }
if (from.length !== 0) { if (from.length !== 0) {
@ -261,23 +248,16 @@ const tryDescribeTrigger = (
} else { } else {
base += ` from ${ base += ` from ${
trigger.attribute trigger.attribute
? computeAttributeValueDisplay( ? hass
hass.localize, .formatEntityAttributeValue(
stateObj, stateObj,
hass.locale,
hass.config,
hass.entities,
trigger.attribute, trigger.attribute,
trigger.from trigger.from
).toString() )
: computeStateDisplay( .toString()
hass.localize, : hass
stateObj, .formatEntityState(stateObj, trigger.from.toString())
hass.locale, .toString()
hass.config,
hass.entities,
trigger.from.toString()
).toString()
}`; }`;
} }
} }
@ -292,23 +272,14 @@ const tryDescribeTrigger = (
for (const state of trigger.to.values()) { for (const state of trigger.to.values()) {
to.push( to.push(
trigger.attribute trigger.attribute
? computeAttributeValueDisplay( ? hass
hass.localize, .formatEntityAttributeValue(
stateObj, stateObj,
hass.locale,
hass.config,
hass.entities,
trigger.attribute, trigger.attribute,
state state
).toString() )
: computeStateDisplay( .toString()
hass.localize, : hass.formatEntityState(stateObj, state).toString()
stateObj,
hass.locale,
hass.config,
hass.entities,
state
).toString()
); );
} }
if (to.length !== 0) { if (to.length !== 0) {
@ -318,23 +289,14 @@ const tryDescribeTrigger = (
} else { } else {
base += ` to ${ base += ` to ${
trigger.attribute trigger.attribute
? computeAttributeValueDisplay( ? hass
hass.localize, .formatEntityAttributeValue(
stateObj, stateObj,
hass.locale,
hass.config,
hass.entities,
trigger.attribute, trigger.attribute,
trigger.to trigger.to
).toString()
: computeStateDisplay(
hass.localize,
stateObj,
hass.locale,
hass.config,
hass.entities,
trigger.to.toString()
) )
.toString()
: hass.formatEntityState(stateObj, trigger.to.toString())
}`; }`;
} }
} }
@ -822,45 +784,27 @@ const tryDescribeCondition = (
for (const state of condition.state.values()) { for (const state of condition.state.values()) {
states.push( states.push(
condition.attribute condition.attribute
? computeAttributeValueDisplay( ? hass
hass.localize, .formatEntityAttributeValue(
stateObj, stateObj,
hass.locale,
hass.config,
hass.entities,
condition.attribute, condition.attribute,
state state
).toString()
: computeStateDisplay(
hass.localize,
stateObj,
hass.locale,
hass.config,
hass.entities,
state
) )
.toString()
: hass.formatEntityState(stateObj, state)
); );
} }
} else if (condition.state !== "") { } else if (condition.state !== "") {
states.push( states.push(
condition.attribute condition.attribute
? computeAttributeValueDisplay( ? hass
hass.localize, .formatEntityAttributeValue(
stateObj, stateObj,
hass.locale,
hass.config,
hass.entities,
condition.attribute, condition.attribute,
condition.state condition.state
).toString()
: computeStateDisplay(
hass.localize,
stateObj,
hass.locale,
hass.config,
hass.entities,
condition.state.toString()
) )
.toString()
: hass.formatEntityState(stateObj, condition.state.toString())
); );
} }

View File

@ -5,14 +5,12 @@ import {
DOMAINS_WITH_DYNAMIC_PICTURE, DOMAINS_WITH_DYNAMIC_PICTURE,
} from "../common/const"; } from "../common/const";
import { computeDomain } from "../common/entity/compute_domain"; import { computeDomain } from "../common/entity/compute_domain";
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 { autoCaseNoun } from "../common/translations/auto_case_noun"; import { autoCaseNoun } from "../common/translations/auto_case_noun";
import { LocalizeFunc } from "../common/translations/localize"; import { LocalizeFunc } from "../common/translations/localize";
import { HaEntityPickerEntityFilterFunc } from "../components/entity/ha-entity-picker"; import { HaEntityPickerEntityFilterFunc } from "../components/entity/ha-entity-picker";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
import { UNAVAILABLE, UNKNOWN } from "./entity"; import { UNAVAILABLE, UNKNOWN } from "./entity";
import { computeAttributeValueDisplay } from "../common/entity/compute_attribute_display";
const LOGBOOK_LOCALIZE_PATH = "ui.components.logbook.messages"; const LOGBOOK_LOCALIZE_PATH = "ui.components.logbook.messages";
export const CONTINUOUS_DOMAINS = ["counter", "proximity", "sensor", "zone"]; 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 // TODO: This is not working yet, as we don't get historic attribute values
const event_type = computeAttributeValueDisplay( const event_type = hass
hass!.localize, .formatEntityAttributeValue(stateObj, "event_type")
stateObj, ?.toString();
hass.locale,
hass.config,
hass.entities,
"event_type"
)?.toString();
if (!event_type) { if (!event_type) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.detected_unknown_event`); return localize(`${LOGBOOK_LOCALIZE_PATH}.detected_unknown_event`);
@ -392,16 +385,7 @@ export const localizeStateMessage = (
return hass.localize( return hass.localize(
`${LOGBOOK_LOCALIZE_PATH}.changed_to_state`, `${LOGBOOK_LOCALIZE_PATH}.changed_to_state`,
"state", "state",
stateObj stateObj ? hass.formatEntityState(stateObj, state) : state
? computeStateDisplay(
localize,
stateObj,
hass.locale,
hass.config,
hass.entities,
state
)
: state
); );
}; };

View File

@ -5,7 +5,6 @@ import {
} from "home-assistant-js-websocket"; } from "home-assistant-js-websocket";
import durationToSeconds from "../common/datetime/duration_to_seconds"; import durationToSeconds from "../common/datetime/duration_to_seconds";
import secondsToDuration from "../common/datetime/seconds_to_duration"; import secondsToDuration from "../common/datetime/seconds_to_duration";
import { computeStateDisplay } from "../common/entity/compute_state_display";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
export type TimerEntity = HassEntityBase & { export type TimerEntity = HassEntityBase & {
@ -90,25 +89,13 @@ export const computeDisplayTimer = (
} }
if (stateObj.state === "idle" || timeRemaining === 0) { if (stateObj.state === "idle" || timeRemaining === 0) {
return computeStateDisplay( return hass.formatEntityState(stateObj);
hass.localize,
stateObj,
hass.locale,
hass.config,
hass.entities
);
} }
let display = secondsToDuration(timeRemaining || 0); let display = secondsToDuration(timeRemaining || 0);
if (stateObj.state === "paused") { if (stateObj.state === "paused") {
display = `${display} (${computeStateDisplay( display = `${display} (${hass.formatEntityState(stateObj)})`;
hass.localize,
stateObj,
hass.locale,
hass.config,
hass.entities
)})`;
} }
return display; return display;

View File

@ -1,7 +1,6 @@
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name"; import { computeStateName } from "../../../common/entity/compute_state_name";
import { isUnavailableState } from "../../../data/entity"; import { isUnavailableState } from "../../../data/entity";
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor"; import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
@ -35,13 +34,7 @@ class EntityPreviewRow extends LitElement {
capitalize capitalize
></hui-timestamp-display> ></hui-timestamp-display>
` `
: computeStateDisplay( : this.hass.formatEntityState(stateObj)}
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div>`; </div>`;
} }

View File

@ -11,7 +11,6 @@ import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
import { styleMap } from "lit/directives/style-map"; import { styleMap } from "lit/directives/style-map";
import { UNIT_F } from "../../../../common/const"; import { UNIT_F } from "../../../../common/const";
import { computeAttributeValueDisplay } from "../../../../common/entity/compute_attribute_display";
import { stateActive } from "../../../../common/entity/state_active"; import { stateActive } from "../../../../common/entity/state_active";
import { stateColorCss } from "../../../../common/entity/state_color"; import { stateColorCss } from "../../../../common/entity/state_color";
import { supportsFeature } from "../../../../common/entity/supports-feature"; import { supportsFeature } from "../../../../common/entity/supports-feature";
@ -162,14 +161,10 @@ export class HaMoreInfoClimateTemperature extends LitElement {
const action = this.stateObj.attributes.hvac_action; const action = this.stateObj.attributes.hvac_action;
const actionLabel = computeAttributeValueDisplay( const actionLabel = this.hass.formatEntityAttributeValue(
this.hass.localize,
this.stateObj, this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"hvac_action" "hvac_action"
) as string; );
return html` return html`
<p class="label"> <p class="label">

View File

@ -2,7 +2,6 @@ import { css, CSSResultGroup, html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map"; import { styleMap } from "lit/directives/style-map";
import { computeAttributeNameDisplay } from "../../../../common/entity/compute_attribute_display"; import { computeAttributeNameDisplay } from "../../../../common/entity/compute_attribute_display";
import { computeStateDisplay } from "../../../../common/entity/compute_state_display";
import { stateActive } from "../../../../common/entity/state_active"; import { stateActive } from "../../../../common/entity/state_active";
import { stateColorCss } from "../../../../common/entity/state_color"; import { stateColorCss } from "../../../../common/entity/state_color";
import "../../../../components/ha-control-select"; import "../../../../components/ha-control-select";
@ -12,12 +11,12 @@ import { UNAVAILABLE } from "../../../../data/entity";
import { import {
computeFanSpeedCount, computeFanSpeedCount,
computeFanSpeedIcon, computeFanSpeedIcon,
FAN_SPEED_COUNT_MAX_FOR_BUTTONS,
FAN_SPEEDS,
FanEntity, FanEntity,
fanPercentageToSpeed, fanPercentageToSpeed,
FanSpeed, FanSpeed,
fanSpeedToPercentage, fanSpeedToPercentage,
FAN_SPEEDS,
FAN_SPEED_COUNT_MAX_FOR_BUTTONS,
} from "../../../../data/fan"; } from "../../../../data/fan";
import { HomeAssistant } from "../../../../types"; import { HomeAssistant } from "../../../../types";
@ -68,14 +67,7 @@ export class HaMoreInfoFanSpeed extends LitElement {
private _localizeSpeed(speed: FanSpeed) { private _localizeSpeed(speed: FanSpeed) {
if (speed === "on" || speed === "off") { if (speed === "on" || speed === "off") {
return computeStateDisplay( return this.hass.formatEntityState(this.stateObj, speed);
this.hass.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
speed
);
} }
return ( return (
this.hass.localize(`ui.dialogs.more_info_control.fan.speed.${speed}`) || this.hass.localize(`ui.dialogs.more_info_control.fan.speed.${speed}`) ||

View File

@ -1,7 +1,5 @@
import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import "../../../components/ha-absolute-time"; import "../../../components/ha-absolute-time";
import "../../../components/ha-relative-time"; import "../../../components/ha-relative-time";
import { isUnavailableState } from "../../../data/entity"; import { isUnavailableState } from "../../../data/entity";
@ -20,30 +18,22 @@ export class HaMoreInfoStateHeader extends LitElement {
@state() private _absoluteTime = false; @state() private _absoluteTime = false;
private _computeStateDisplay(stateObj: HassEntity): TemplateResult | string { private _localizeState(): TemplateResult | string {
if ( if (
stateObj.attributes.device_class === SENSOR_DEVICE_CLASS_TIMESTAMP && this.stateObj.attributes.device_class === SENSOR_DEVICE_CLASS_TIMESTAMP &&
!isUnavailableState(stateObj.state) !isUnavailableState(this.stateObj.state)
) { ) {
return html` return html`
<hui-timestamp-display <hui-timestamp-display
.hass=${this.hass} .hass=${this.hass}
.ts=${new Date(stateObj.state)} .ts=${new Date(this.stateObj.state)}
format="relative" format="relative"
capitalize capitalize
></hui-timestamp-display> ></hui-timestamp-display>
`; `;
} }
const stateDisplay = computeStateDisplay( return this.hass.formatEntityState(this.stateObj);
this.hass!.localize,
stateObj,
this.hass!.locale,
this.hass!.config,
this.hass!.entities
);
return stateDisplay;
} }
private _toggleAbsolute() { private _toggleAbsolute() {
@ -51,8 +41,7 @@ export class HaMoreInfoStateHeader extends LitElement {
} }
protected render(): TemplateResult { protected render(): TemplateResult {
const stateDisplay = const stateDisplay = this.stateOverride ?? this._localizeState();
this.stateOverride ?? this._computeStateDisplay(this.stateObj);
return html` return html`
<p class="state">${stateDisplay}</p> <p class="state">${stateDisplay}</p>

View File

@ -2,7 +2,6 @@ import { mdiMinus, mdiPlus } from "@mdi/js";
import { CSSResultGroup, LitElement, PropertyValues, css, html } from "lit"; import { CSSResultGroup, LitElement, PropertyValues, css, html } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map"; import { styleMap } from "lit/directives/style-map";
import { computeAttributeValueDisplay } from "../../../../common/entity/compute_attribute_display";
import { stateActive } from "../../../../common/entity/state_active"; import { stateActive } from "../../../../common/entity/state_active";
import { stateColorCss } from "../../../../common/entity/state_color"; import { stateColorCss } from "../../../../common/entity/state_color";
import { clamp } from "../../../../common/number/clamp"; import { clamp } from "../../../../common/number/clamp";
@ -92,14 +91,10 @@ export class HaMoreInfoHumidifierHumidity extends LitElement {
const action = this.stateObj.attributes.action; const action = this.stateObj.attributes.action;
const actionLabel = computeAttributeValueDisplay( const actionLabel = this.hass.formatEntityAttributeValue(
this.hass.localize,
this.stateObj, this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"action" "action"
) as string; );
return html` return html`
<p class="label"> <p class="label">

View File

@ -1,22 +1,21 @@
import { mdiMenu, mdiSwapVertical } from "@mdi/js"; import { mdiMenu, mdiSwapVertical } from "@mdi/js";
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
nothing,
PropertyValues, PropertyValues,
css,
html,
nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { supportsFeature } from "../../../common/entity/supports-feature"; import { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/ha-attributes"; import "../../../components/ha-attributes";
import "../../../components/ha-icon-button-group"; import "../../../components/ha-icon-button-group";
import "../../../components/ha-icon-button-toggle"; import "../../../components/ha-icon-button-toggle";
import { import {
computeCoverPositionStateDisplay,
CoverEntity, CoverEntity,
CoverEntityFeature, CoverEntityFeature,
computeCoverPositionStateDisplay,
} from "../../../data/cover"; } from "../../../data/cover";
import type { HomeAssistant } from "../../../types"; import type { HomeAssistant } from "../../../types";
import "../components/cover/ha-more-info-cover-buttons"; import "../components/cover/ha-more-info-cover-buttons";
@ -83,12 +82,8 @@ class MoreInfoCover extends LitElement {
const forcedState = const forcedState =
liveValue != null ? (liveValue ? "open" : "closed") : undefined; liveValue != null ? (liveValue ? "open" : "closed") : undefined;
const stateDisplay = computeStateDisplay( const stateDisplay = this.hass.formatEntityState(
this.hass.localize,
this.stateObj!, this.stateObj!,
this.hass.locale,
this.hass.config,
this.hass.entities,
forcedState forcedState
); );

View File

@ -10,11 +10,6 @@ import {
import { property, state } from "lit/decorators"; import { property, state } from "lit/decorators";
import { fireEvent } from "../../../common/dom/fire_event"; import { fireEvent } from "../../../common/dom/fire_event";
import { stopPropagation } from "../../../common/dom/stop_propagation"; 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 { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/ha-control-select-menu"; import "../../../components/ha-control-select-menu";
import "../../../components/ha-list-item"; import "../../../components/ha-list-item";
@ -58,26 +53,21 @@ class MoreInfoHumidifier extends LitElement {
HumidifierEntityFeature.MODES HumidifierEntityFeature.MODES
); );
const currentHumidity = this.stateObj.attributes.current_humidity as number;
return html` return html`
<div class="current"> <div class="current">
${currentHumidity != null ${this.stateObj.attributes.current_humidity != null
? html` ? html`
<div> <div>
<p class="label"> <p class="label">
${computeAttributeNameDisplay( ${this.hass.formatEntityAttributeName(
this.hass.localize,
this.stateObj, this.stateObj,
this.hass.entities,
"current_humidity" "current_humidity"
)} )}
</p> </p>
<p class="value"> <p class="value">
${this.hass.formatEntityAttributeValue( ${this.hass.formatEntityAttributeValue(
this.stateObj, this.stateObj,
"current_humidity", "current_humidity"
currentHumidity
)} )}
</p> </p>
</div> </div>
@ -104,24 +94,10 @@ class MoreInfoHumidifier extends LitElement {
> >
<ha-svg-icon slot="icon" .path=${mdiPower}></ha-svg-icon> <ha-svg-icon slot="icon" .path=${mdiPower}></ha-svg-icon>
<ha-list-item value="off"> <ha-list-item value="off">
${computeStateDisplay( ${this.hass.formatEntityState(this.stateObj, "off")}
this.hass.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"off"
)}
</ha-list-item> </ha-list-item>
<ha-list-item value="on"> <ha-list-item value="on">
${computeStateDisplay( ${this.hass.formatEntityState(this.stateObj, "on")}
this.hass.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"on"
)}
</ha-list-item> </ha-list-item>
</ha-control-select-menu> </ha-control-select-menu>
@ -144,12 +120,8 @@ class MoreInfoHumidifier extends LitElement {
slot="graphic" slot="graphic"
.path=${computeHumidiferModeIcon(mode)} .path=${computeHumidiferModeIcon(mode)}
></ha-svg-icon> ></ha-svg-icon>
${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(
hass.localize,
stateObj!, stateObj!,
hass.locale,
hass.config,
hass.entities,
"mode", "mode",
mode mode
)} )}

View File

@ -2,7 +2,6 @@ import { mdiHomeImportOutline, mdiPause, mdiPlay } from "@mdi/js";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
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 { supportsFeature } from "../../../common/entity/supports-feature"; import { supportsFeature } from "../../../common/entity/supports-feature";
import { blankBeforePercent } from "../../../common/translations/blank_before_percent"; import { blankBeforePercent } from "../../../common/translations/blank_before_percent";
@ -74,15 +73,7 @@ class MoreInfoLawnMower extends LitElement {
)}: )}:
</span> </span>
<span> <span>
<strong> <strong>${this.hass.formatEntityState(stateObj)}</strong>
${computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</strong>
</span> </span>
</div> </div>
${this._renderBattery()} ${this._renderBattery()}

View File

@ -9,24 +9,23 @@ import {
mdiVolumeOff, mdiVolumeOff,
mdiVolumePlus, mdiVolumePlus,
} from "@mdi/js"; } 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 { customElement, property } from "lit/decorators";
import { stopPropagation } from "../../../common/dom/stop_propagation"; 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 { supportsFeature } from "../../../common/entity/supports-feature";
import { computeRTLDirection } from "../../../common/util/compute_rtl"; import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { stateActive } from "../../../common/entity/state_active";
import "../../../components/ha-icon-button"; import "../../../components/ha-icon-button";
import "../../../components/ha-select"; import "../../../components/ha-select";
import "../../../components/ha-slider"; import "../../../components/ha-slider";
import "../../../components/ha-svg-icon"; import "../../../components/ha-svg-icon";
import { showMediaBrowserDialog } from "../../../components/media-player/show-media-browser-dialog"; import { showMediaBrowserDialog } from "../../../components/media-player/show-media-browser-dialog";
import { import {
computeMediaControls,
handleMediaControlClick,
MediaPickedEvent, MediaPickedEvent,
MediaPlayerEntity, MediaPlayerEntity,
MediaPlayerEntityFeature, MediaPlayerEntityFeature,
computeMediaControls,
handleMediaControlClick,
mediaPlayerPlayMedia, mediaPlayerPlayMedia,
} from "../../../data/media-player"; } from "../../../data/media-player";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
@ -157,24 +156,20 @@ class MoreInfoMediaPlayer extends LitElement {
> >
${stateObj.attributes.source_list!.map( ${stateObj.attributes.source_list!.map(
(source) => html` (source) => html`
<mwc-list-item .value=${source} <mwc-list-item .value=${source}>
>${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(
this.hass.localize,
stateObj, stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"source", "source",
source source
)}</mwc-list-item )}
> </mwc-list-item>
` `
)} )}
<ha-svg-icon .path=${mdiLoginVariant} slot="icon"></ha-svg-icon> <ha-svg-icon .path=${mdiLoginVariant} slot="icon"></ha-svg-icon>
</ha-select> </ha-select>
</div> </div>
` `
: ""} : nothing}
${stateActive(stateObj) && ${stateActive(stateObj) &&
supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOUND_MODE) && supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOUND_MODE) &&
stateObj.attributes.sound_mode_list?.length stateObj.attributes.sound_mode_list?.length
@ -191,17 +186,13 @@ class MoreInfoMediaPlayer extends LitElement {
> >
${stateObj.attributes.sound_mode_list.map( ${stateObj.attributes.sound_mode_list.map(
(mode) => html` (mode) => html`
<mwc-list-item .value=${mode} <mwc-list-item .value=${mode}>
>${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(
this.hass.localize,
stateObj, stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"sound_mode", "sound_mode",
mode mode
)}</mwc-list-item )}
> </mwc-list-item>
` `
)} )}
<ha-svg-icon .path=${mdiMusicNote} slot="icon"></ha-svg-icon> <ha-svg-icon .path=${mdiMusicNote} slot="icon"></ha-svg-icon>

View File

@ -2,11 +2,10 @@ import "@material/mwc-list/mwc-list";
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import { html, LitElement, nothing } from "lit"; import { html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
import { stopPropagation } from "../../../common/dom/stop_propagation"; import { stopPropagation } from "../../../common/dom/stop_propagation";
import { supportsFeature } from "../../../common/entity/supports-feature"; import { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/ha-attributes"; import "../../../components/ha-attributes";
import { RemoteEntity, REMOTE_SUPPORT_ACTIVITY } from "../../../data/remote"; import { REMOTE_SUPPORT_ACTIVITY, RemoteEntity } from "../../../data/remote";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
const filterExtraAttributes = "activity_list,current_activity"; const filterExtraAttributes = "activity_list,current_activity";
@ -40,12 +39,8 @@ class MoreInfoRemote extends LitElement {
${stateObj.attributes.activity_list!.map( ${stateObj.attributes.activity_list!.map(
(activity) => html` (activity) => html`
<mwc-list-item .value=${activity}> <mwc-list-item .value=${activity}>
${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(
this.hass.localize,
stateObj, stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"activity", "activity",
activity activity
)} )}
@ -54,7 +49,7 @@ class MoreInfoRemote extends LitElement {
)} )}
</mwc-list> </mwc-list>
` `
: ""} : nothing}
<ha-attributes <ha-attributes
.hass=${this.hass} .hass=${this.hass}

View File

@ -13,8 +13,6 @@ import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { stopPropagation } from "../../../common/dom/stop_propagation"; import { stopPropagation } from "../../../common/dom/stop_propagation";
import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_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 { supportsFeature } from "../../../common/entity/supports-feature"; import { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/entity/ha-battery-icon"; import "../../../components/entity/ha-battery-icon";
@ -127,21 +125,8 @@ class MoreInfoVacuum extends LitElement {
<strong> <strong>
${supportsFeature(stateObj, VacuumEntityFeature.STATUS) && ${supportsFeature(stateObj, VacuumEntityFeature.STATUS) &&
stateObj.attributes.status stateObj.attributes.status
? computeAttributeValueDisplay( ? this.hass.formatEntityAttributeValue(stateObj, "status")
this.hass.localize, : this.hass.formatEntityState(stateObj)}
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
)}
</strong> </strong>
</span> </span>
</div> </div>
@ -197,12 +182,8 @@ class MoreInfoVacuum extends LitElement {
${stateObj.attributes.fan_speed_list!.map( ${stateObj.attributes.fan_speed_list!.map(
(mode) => html` (mode) => html`
<mwc-list-item .value=${mode}> <mwc-list-item .value=${mode}>
${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(
this.hass.localize,
stateObj, stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"fan_speed", "fan_speed",
mode mode
)} )}
@ -215,12 +196,8 @@ class MoreInfoVacuum extends LitElement {
> >
<span> <span>
<ha-svg-icon .path=${mdiFan}></ha-svg-icon> <ha-svg-icon .path=${mdiFan}></ha-svg-icon>
${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(
this.hass.localize,
stateObj, stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"fan_speed" "fan_speed"
)} )}
</span> </span>

View File

@ -2,7 +2,6 @@ import "@material/mwc-button";
import { html, LitElement, nothing } from "lit"; import { html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { computeStateDisplay } from "../../common/entity/compute_state_display";
import { domainToName } from "../../data/integration"; import { domainToName } from "../../data/integration";
import { PersitentNotificationEntity } from "../../data/persistent_notification"; import { PersitentNotificationEntity } from "../../data/persistent_notification";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
@ -33,15 +32,9 @@ export class HuiConfiguratorNotificationItem extends LitElement {
)} )}
</div> </div>
<mwc-button slot="actions" @click=${this._handleClick} <mwc-button slot="actions" @click=${this._handleClick}>
>${computeStateDisplay( ${this.hass.formatEntityState(this.notification)}
this.hass.localize, </mwc-button>
this.notification,
this.hass.locale,
this.hass.config,
this.hass.entities
)}</mwc-button
>
</notification-item-template> </notification-item-template>
`; `;
} }

View File

@ -12,7 +12,6 @@ import { ifDefined } from "lit/directives/if-defined";
import { styleMap } from "lit/directives/style-map"; import { styleMap } from "lit/directives/style-map";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element"; import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { fireEvent } from "../../../common/dom/fire_event"; import { fireEvent } from "../../../common/dom/fire_event";
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 { import {
@ -176,13 +175,7 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
this.hass.entities[this._config.entity] this.hass.entities[this._config.entity]
) )
) )
: computeStateDisplay( : this.hass.formatEntityState(stateObj)}</span
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}</span
>${showUnit >${showUnit
? html` ? html`
<span class="measurement" <span class="measurement"

View File

@ -1,10 +1,10 @@
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
TemplateResult, TemplateResult,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
@ -12,7 +12,6 @@ import { classMap } from "lit/directives/class-map";
import { ifDefined } from "lit/directives/if-defined"; import { ifDefined } from "lit/directives/if-defined";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element"; import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { computeDomain } from "../../../common/entity/compute_domain"; import { computeDomain } from "../../../common/entity/compute_domain";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name"; import { computeStateName } from "../../../common/entity/compute_state_name";
import "../../../components/entity/state-badge"; import "../../../components/entity/state-badge";
import "../../../components/ha-card"; import "../../../components/ha-card";
@ -344,13 +343,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
capitalize capitalize
></ha-relative-time> ></ha-relative-time>
` `
: computeStateDisplay( : this.hass!.formatEntityState(stateObj)}
this.hass!.localize,
stateObj,
this.hass!.locale,
this.hass!.config,
this.hass!.entities
)}
</div> </div>
` `
: ""} : ""}

View File

@ -11,12 +11,10 @@ import {
svg, svg,
} from "lit"; } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
import { classMap } from "lit/directives/class-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 { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { fireEvent } from "../../../common/dom/fire_event"; 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 { computeStateName } from "../../../common/entity/compute_state_name";
import { stateColorCss } from "../../../common/entity/state_color"; import { stateColorCss } from "../../../common/entity/state_color";
import { formatNumber } from "../../../common/number/format_number"; import { formatNumber } from "../../../common/number/format_number";
@ -168,34 +166,13 @@ export class HuiHumidifierCard extends LitElement implements LovelaceCard {
> >
${ ${
stateObj.attributes.action stateObj.attributes.action
? computeAttributeValueDisplay( ? this.hass.formatEntityAttributeValue(stateObj, "action")
this.hass.localize, : this.hass.formatEntityState(stateObj)
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
)
} }
${ ${
stateObj.state !== UNAVAILABLE && stateObj.attributes.mode stateObj.state !== UNAVAILABLE && stateObj.attributes.mode
? html` ? html`
- - ${this.hass.formatEntityAttributeValue(stateObj, "mode")}
${computeAttributeValueDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"mode"
)}
` `
: nothing : nothing
} }

View File

@ -1,11 +1,11 @@
import { mdiDotsVertical } from "@mdi/js"; import { mdiDotsVertical } from "@mdi/js";
import "@thomasloven/round-slider"; import "@thomasloven/round-slider";
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; 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 { styleMap } from "lit/directives/style-map";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element"; import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { fireEvent } from "../../../common/dom/fire_event"; import { fireEvent } from "../../../common/dom/fire_event";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name"; import { computeStateName } from "../../../common/entity/compute_state_name";
import { stateColorBrightness } from "../../../common/entity/state_color";
import "../../../components/ha-card"; import "../../../components/ha-card";
import "../../../components/ha-icon-button"; import "../../../components/ha-icon-button";
import "../../../components/ha-state-icon"; import "../../../components/ha-state-icon";
import { isUnavailableState, UNAVAILABLE } from "../../../data/entity"; import { UNAVAILABLE, isUnavailableState } from "../../../data/entity";
import { LightEntity, lightSupportsBrightness } from "../../../data/light"; import { LightEntity, lightSupportsBrightness } from "../../../data/light";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
@ -30,7 +30,6 @@ 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 {
@ -156,17 +155,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
<div id="info" .title=${name}> <div id="info" .title=${name}>
${isUnavailableState(stateObj.state) ${isUnavailableState(stateObj.state)
? html` ? html` <div>${this.hass.formatEntityState(stateObj)}</div> `
<div>
${computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div>
`
: html` <div class="brightness">%</div> `} : html` <div class="brightness">%</div> `}
${name} ${name}
</div> </div>

View File

@ -1,20 +1,19 @@
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
TemplateResult, TemplateResult,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined"; import { ifDefined } from "lit/directives/if-defined";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element"; import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { computeDomain } from "../../../common/entity/compute_domain"; import { computeDomain } from "../../../common/entity/compute_domain";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name"; import { computeStateName } from "../../../common/entity/compute_state_name";
import "../../../components/ha-card"; import "../../../components/ha-card";
import { computeImageUrl, ImageEntity } from "../../../data/image"; import { ImageEntity, computeImageUrl } from "../../../data/image";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive"; 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 name = this._config.name || computeStateName(stateObj);
const entityState = computeStateDisplay( const entityState = this.hass.formatEntityState(stateObj);
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
);
let footer: TemplateResult | string = ""; let footer: TemplateResult | string = "";
if (this._config.show_name && this._config.show_state) { if (this._config.show_name && this._config.show_state) {

View File

@ -13,7 +13,6 @@ import { ifDefined } from "lit/directives/if-defined";
import { DOMAINS_TOGGLE } from "../../../common/const"; import { DOMAINS_TOGGLE } from "../../../common/const";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element"; import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { computeDomain } from "../../../common/entity/compute_domain"; import { computeDomain } from "../../../common/entity/compute_domain";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name"; import { computeStateName } from "../../../common/entity/compute_state_name";
import "../../../components/ha-card"; import "../../../components/ha-card";
import "../../../components/ha-icon-button"; import "../../../components/ha-icon-button";
@ -273,13 +272,9 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
class=${classMap({ class=${classMap({
"state-on": !STATES_OFF.has(stateObj.state), "state-on": !STATES_OFF.has(stateObj.state),
})} })}
title=${`${computeStateName(stateObj)} : ${computeStateDisplay( title=${`${computeStateName(
this.hass!.localize, stateObj
stateObj, )} : ${this.hass.formatEntityState(stateObj)}`}
this.hass!.locale,
this.hass!.config,
this.hass!.entities
)}`}
> >
<ha-state-icon <ha-state-icon
.icon=${entityConf.icon} .icon=${entityConf.icon}
@ -297,13 +292,7 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
entityConf.attribute entityConf.attribute
]}${entityConf.suffix} ]}${entityConf.suffix}
` `
: computeStateDisplay( : this.hass.formatEntityState(stateObj)}
this.hass!.localize,
stateObj,
this.hass!.locale,
this.hass!.config,
this.hass!.entities
)}
</div> </div>
`} `}
</div> </div>

View File

@ -11,12 +11,12 @@ import {
import "@thomasloven/round-slider"; import "@thomasloven/round-slider";
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
nothing,
PropertyValues, PropertyValues,
css,
html,
nothing,
svg, svg,
} from "lit"; } from "lit";
import { customElement, property, query, state } from "lit/decorators"; 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 { UNIT_F } from "../../../common/const";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element"; import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { fireEvent } from "../../../common/dom/fire_event"; 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 { computeStateName } from "../../../common/entity/compute_state_name";
import { stateColorCss } from "../../../common/entity/state_color"; import { stateColorCss } from "../../../common/entity/state_color";
import { formatNumber } from "../../../common/number/format_number"; import { formatNumber } from "../../../common/number/format_number";
@ -34,10 +32,10 @@ import "../../../components/ha-card";
import type { HaCard } from "../../../components/ha-card"; import type { HaCard } from "../../../components/ha-card";
import "../../../components/ha-icon-button"; import "../../../components/ha-icon-button";
import { import {
ClimateEntity,
CLIMATE_PRESET_NONE, CLIMATE_PRESET_NONE,
compareClimateHvacModes, ClimateEntity,
HvacMode, HvacMode,
compareClimateHvacModes,
} from "../../../data/climate"; } from "../../../data/climate";
import { UNAVAILABLE } from "../../../data/entity"; import { UNAVAILABLE } from "../../../data/entity";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
@ -207,21 +205,8 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
> >
${ ${
stateObj.state !== UNAVAILABLE && stateObj.attributes.hvac_action stateObj.state !== UNAVAILABLE && stateObj.attributes.hvac_action
? computeAttributeValueDisplay( ? this.hass.formatEntityAttributeValue(stateObj, "hvac_action")
this.hass.localize, : this.hass.formatEntityState(stateObj)
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
)
} }
${ ${
stateObj.state !== UNAVAILABLE && stateObj.state !== UNAVAILABLE &&
@ -229,12 +214,8 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
stateObj.attributes.preset_mode !== CLIMATE_PRESET_NONE stateObj.attributes.preset_mode !== CLIMATE_PRESET_NONE
? html` ? html`
- -
${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(
this.hass.localize,
stateObj, stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"preset_mode" "preset_mode"
)} )}
` `

View File

@ -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); const domain = computeDomain(stateObj.entity_id);
if ( if (
@ -308,7 +308,7 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
const name = this._config.name || stateObj.attributes.friendly_name; const name = this._config.name || stateObj.attributes.friendly_name;
const stateDisplay = this._computeStateDisplay(stateObj); const localizedState = this._formatState(stateObj);
const active = stateActive(stateObj); const active = stateActive(stateObj);
const color = this._computeStateColor(stateObj, this._config.color); const color = this._computeStateColor(stateObj, this._config.color);
@ -381,7 +381,7 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
<ha-tile-info <ha-tile-info
class="info" class="info"
.primary=${name} .primary=${name}
.secondary=${stateDisplay} .secondary=${localizedState}
></ha-tile-info> ></ha-tile-info>
</div> </div>
</div> </div>

View File

@ -1,16 +1,16 @@
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined"; import { ifDefined } from "lit/directives/if-defined";
import { formatDateWeekdayShort } from "../../../common/datetime/format_date";
import { formatTime } from "../../../common/datetime/format_time"; import { formatTime } from "../../../common/datetime/format_time";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element"; 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 { computeStateName } from "../../../common/entity/compute_state_name";
import { isValidEntityId } from "../../../common/entity/valid_entity_id"; import { isValidEntityId } from "../../../common/entity/valid_entity_id";
import { formatNumber } from "../../../common/number/format_number"; import { formatNumber } from "../../../common/number/format_number";
@ -20,28 +20,27 @@ import "../../../components/ha-svg-icon";
import { UNAVAILABLE } from "../../../data/entity"; import { UNAVAILABLE } from "../../../data/entity";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { import {
ForecastEvent,
WeatherEntity,
getForecast, getForecast,
getSecondaryWeatherAttribute, getSecondaryWeatherAttribute,
getWeatherStateIcon, getWeatherStateIcon,
getWeatherUnit, getWeatherUnit,
getWind, getWind,
subscribeForecast, subscribeForecast,
ForecastEvent,
weatherAttrIcons, weatherAttrIcons,
WeatherEntity,
weatherSVGStyles, weatherSVGStyles,
} from "../../../data/weather"; } from "../../../data/weather";
import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import type { HomeAssistant } from "../../../types"; import type { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive"; import { actionHandler } from "../common/directives/action-handler-directive";
import { findEntities } from "../common/find-entities"; import { findEntities } from "../common/find-entities";
import { handleAction } from "../common/handle-action"; import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action"; import { hasAction } from "../common/has-action";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import { createEntityNotFoundWarning } from "../components/hui-warning"; import { createEntityNotFoundWarning } from "../components/hui-warning";
import type { LovelaceCard, LovelaceCardEditor } from "../types"; import type { LovelaceCard, LovelaceCardEditor } from "../types";
import type { WeatherForecastCardConfig } from "./types"; import type { WeatherForecastCardConfig } from "./types";
import { formatDateWeekdayShort } from "../../../common/datetime/format_date";
@customElement("hui-weather-forecast-card") @customElement("hui-weather-forecast-card")
class HuiWeatherForecastCard extends LitElement implements LovelaceCard { class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
@ -265,13 +264,7 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
<div class="info"> <div class="info">
<div class="name-state"> <div class="name-state">
<div class="state"> <div class="state">
${computeStateDisplay( ${this.hass.formatEntityState(stateObj)}
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div> </div>
<div class="name" .title=${name}>${name}</div> <div class="name" .title=${name}>${name}</div>
</div> </div>

View File

@ -1,14 +1,13 @@
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined"; import { ifDefined } from "lit/directives/if-defined";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { computeTooltip } from "../common/compute-tooltip"; import { computeTooltip } from "../common/compute-tooltip";
@ -83,13 +82,7 @@ class HuiStateLabelElement extends LitElement implements LovelaceElement {
)} )}
> >
${this._config.prefix}${!this._config.attribute ${this._config.prefix}${!this._config.attribute
? computeStateDisplay( ? this.hass.formatEntityState(stateObj)
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)
: stateObj.attributes[this._config.attribute]}${this._config.suffix} : stateObj.attributes[this._config.attribute]}${this._config.suffix}
</div> </div>
`; `;

View File

@ -1,14 +1,12 @@
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; 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 { isUnavailableState } from "../../../data/entity";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
@ -70,13 +68,7 @@ class HuiEventEntityRow extends LitElement implements LovelaceRow {
> >
<div class="when"> <div class="when">
${isUnavailableState(stateObj.state) ${isUnavailableState(stateObj.state)
? computeStateDisplay( ? this.hass.formatEntityState(stateObj)
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)
: html`<hui-timestamp-display : html`<hui-timestamp-display
.hass=${this.hass} .hass=${this.hass}
.ts=${new Date(stateObj.state)} .ts=${new Date(stateObj.state)}
@ -86,15 +78,8 @@ class HuiEventEntityRow extends LitElement implements LovelaceRow {
</div> </div>
<div class="what"> <div class="what">
${isUnavailableState(stateObj.state) ${isUnavailableState(stateObj.state)
? `` ? nothing
: computeAttributeValueDisplay( : this.hass.formatEntityAttributeValue(stateObj, "event_type")}
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"event_type"
)}
</div> </div>
</div> </div>
</hui-generic-entity-row> </hui-generic-entity-row>

View File

@ -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 { customElement, property, state } from "lit/decorators";
import { DOMAINS_TOGGLE } from "../../../common/const"; import { DOMAINS_TOGGLE } from "../../../common/const";
import { computeDomain } from "../../../common/entity/compute_domain"; import { computeDomain } from "../../../common/entity/compute_domain";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import "../../../components/entity/ha-entity-toggle"; import "../../../components/entity/ha-entity-toggle";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
@ -66,13 +65,7 @@ class HuiGroupEntityRow extends LitElement implements LovelaceRow {
` `
: html` : html`
<div class="text-content"> <div class="text-content">
${computeStateDisplay( ${this.hass.formatEntityState(stateObj)}
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div> </div>
`} `}
</hui-generic-entity-row> </hui-generic-entity-row>

View File

@ -1,22 +1,21 @@
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeRTLDirection } from "../../../common/util/compute_rtl"; import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { debounce } from "../../../common/util/debounce"; import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-slider"; import "../../../components/ha-slider";
import "../../../components/ha-textfield"; import "../../../components/ha-textfield";
import { isUnavailableState } from "../../../data/entity"; import { isUnavailableState } from "../../../data/entity";
import { setValue } from "../../../data/input_text"; import { setValue } from "../../../data/input_text";
import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import "../components/hui-generic-entity-row"; import "../components/hui-generic-entity-row";
import { createEntityNotFoundWarning } from "../components/hui-warning"; import { createEntityNotFoundWarning } from "../components/hui-warning";
import { EntityConfig, LovelaceRow } from "./types"; import { EntityConfig, LovelaceRow } from "./types";
@ -97,14 +96,7 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
ignore-bar-touch ignore-bar-touch
></ha-slider> ></ha-slider>
<span class="state"> <span class="state">
${computeStateDisplay( ${this.hass.formatEntityState(stateObj)}
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
stateObj.state
)}
</span> </span>
</div> </div>
` `

View File

@ -13,31 +13,30 @@ import {
} from "@mdi/js"; } from "@mdi/js";
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; 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 { supportsFeature } from "../../../common/entity/supports-feature";
import { computeRTLDirection } from "../../../common/util/compute_rtl"; import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { stateActive } from "../../../common/entity/state_active";
import { debounce } from "../../../common/util/debounce"; import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-icon-button"; import "../../../components/ha-icon-button";
import "../../../components/ha-slider"; import "../../../components/ha-slider";
import { isUnavailableState } from "../../../data/entity"; import { isUnavailableState } from "../../../data/entity";
import { import {
computeMediaDescription,
ControlButton, ControlButton,
MediaPlayerEntity, MediaPlayerEntity,
MediaPlayerEntityFeature, MediaPlayerEntityFeature,
computeMediaDescription,
} from "../../../data/media-player"; } from "../../../data/media-player";
import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import type { HomeAssistant } from "../../../types"; import type { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import "../components/hui-generic-entity-row"; import "../components/hui-generic-entity-row";
import { createEntityNotFoundWarning } from "../components/hui-warning"; import { createEntityNotFoundWarning } from "../components/hui-warning";
import type { EntityConfig, LovelaceRow } from "./types"; import type { EntityConfig, LovelaceRow } from "./types";
@ -191,13 +190,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
.hass=${this.hass} .hass=${this.hass}
.config=${this._config} .config=${this._config}
.secondaryText=${mediaDescription || .secondaryText=${mediaDescription ||
computeStateDisplay( this.hass.formatEntityState(stateObj)}
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
> >
<div class="controls"> <div class="controls">
${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON) && ${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON) &&

View File

@ -1,22 +1,21 @@
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeRTLDirection } from "../../../common/util/compute_rtl"; import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { debounce } from "../../../common/util/debounce"; import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-slider"; import "../../../components/ha-slider";
import "../../../components/ha-textfield"; import "../../../components/ha-textfield";
import { UNAVAILABLE } from "../../../data/entity"; import { UNAVAILABLE } from "../../../data/entity";
import { setValue } from "../../../data/input_text"; import { setValue } from "../../../data/input_text";
import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
import { loadPolyfillIfNeeded } from "../../../resources/resize-observer.polyfill";
import "../components/hui-generic-entity-row"; import "../components/hui-generic-entity-row";
import { createEntityNotFoundWarning } from "../components/hui-warning"; import { createEntityNotFoundWarning } from "../components/hui-warning";
import { EntityConfig, LovelaceRow } from "./types"; import { EntityConfig, LovelaceRow } from "./types";
@ -101,14 +100,7 @@ class HuiNumberEntityRow extends LitElement implements LovelaceRow {
ignore-bar-touch ignore-bar-touch
></ha-slider> ></ha-slider>
<span class="state"> <span class="state">
${computeStateDisplay( ${this.hass.formatEntityState(stateObj)}
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
stateObj.state
)}
</span> </span>
</div> </div>
` `

View File

@ -1,15 +1,14 @@
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { stopPropagation } from "../../../common/dom/stop_propagation"; import { stopPropagation } from "../../../common/dom/stop_propagation";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name"; import { computeStateName } from "../../../common/entity/compute_state_name";
import "../../../components/ha-select"; import "../../../components/ha-select";
import { UNAVAILABLE } from "../../../data/entity"; import { UNAVAILABLE } from "../../../data/entity";
@ -77,14 +76,7 @@ class HuiSelectEntityRow extends LitElement implements LovelaceRow {
? stateObj.attributes.options.map( ? stateObj.attributes.options.map(
(option) => html` (option) => html`
<mwc-list-item .value=${option}> <mwc-list-item .value=${option}>
${computeStateDisplay( ${this.hass!.formatEntityState(stateObj, option)}
this.hass!.localize,
stateObj,
this.hass!.locale,
this.hass!.config,
this.hass!.entities,
option
)}
</mwc-list-item> </mwc-list-item>
` `
) )

View File

@ -1,13 +1,12 @@
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { isUnavailableState } from "../../../data/entity"; import { isUnavailableState } from "../../../data/entity";
import { ActionHandlerEvent } from "../../../data/lovelace"; import { ActionHandlerEvent } from "../../../data/lovelace";
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor"; import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
@ -79,13 +78,7 @@ class HuiSensorEntityRow extends LitElement implements LovelaceRow {
capitalize capitalize
></hui-timestamp-display> ></hui-timestamp-display>
` `
: computeStateDisplay( : this.hass.formatEntityState(stateObj)}
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div> </div>
</hui-generic-entity-row> </hui-generic-entity-row>
`; `;

View File

@ -1,13 +1,12 @@
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { EntitiesCardEntityConfig } from "../cards/types"; import { EntitiesCardEntityConfig } from "../cards/types";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
@ -49,13 +48,7 @@ class HuiSimpleEntityRow extends LitElement implements LovelaceRow {
return html` return html`
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}> <hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
${computeStateDisplay( ${this.hass.formatEntityState(stateObj)}
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</hui-generic-entity-row> </hui-generic-entity-row>
`; `;
} }

View File

@ -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 { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import "../../../components/entity/ha-entity-toggle"; import "../../../components/entity/ha-entity-toggle";
import { isUnavailableState } from "../../../data/entity"; import { isUnavailableState } from "../../../data/entity";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
@ -61,13 +60,7 @@ class HuiToggleEntityRow extends LitElement implements LovelaceRow {
` `
: html` : html`
<div class="text-content"> <div class="text-content">
${computeStateDisplay( ${this.hass.formatEntityState(stateObj)}
this.hass!.localize,
stateObj,
this.hass!.locale,
this.hass.config,
this.hass!.entities
)}
</div> </div>
`} `}
</hui-generic-entity-row> </hui-generic-entity-row>

View File

@ -3,7 +3,6 @@ import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeAttributeNameDisplay } from "../../../common/entity/compute_attribute_display"; import { computeAttributeNameDisplay } from "../../../common/entity/compute_attribute_display";
import { computeDomain } from "../../../common/entity/compute_domain"; import { computeDomain } from "../../../common/entity/compute_domain";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { stateActive } from "../../../common/entity/state_active"; import { stateActive } from "../../../common/entity/state_active";
import { supportsFeature } from "../../../common/entity/supports-feature"; import { supportsFeature } from "../../../common/entity/supports-feature";
import "../../../components/ha-control-select"; import "../../../components/ha-control-select";
@ -13,13 +12,13 @@ import { UNAVAILABLE } from "../../../data/entity";
import { import {
computeFanSpeedCount, computeFanSpeedCount,
computeFanSpeedIcon, computeFanSpeedIcon,
FAN_SPEED_COUNT_MAX_FOR_BUTTONS,
FAN_SPEEDS,
FanEntity, FanEntity,
FanEntityFeature, FanEntityFeature,
fanPercentageToSpeed, fanPercentageToSpeed,
FanSpeed, FanSpeed,
fanSpeedToPercentage, fanSpeedToPercentage,
FAN_SPEEDS,
FAN_SPEED_COUNT_MAX_FOR_BUTTONS,
} from "../../../data/fan"; } from "../../../data/fan";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { LovelaceTileFeature } from "../types"; import { LovelaceTileFeature } from "../types";
@ -55,14 +54,7 @@ class HuiFanSpeedTileFeature extends LitElement implements LovelaceTileFeature {
private _localizeSpeed(speed: FanSpeed) { private _localizeSpeed(speed: FanSpeed) {
if (speed === "on" || speed === "off") { if (speed === "on" || speed === "off") {
return computeStateDisplay( return this.hass!.formatEntityState(this.stateObj!, speed);
this.hass!.localize,
this.stateObj!,
this.hass!.locale,
this.hass!.config,
this.hass!.entities,
speed
);
} }
return ( return (
this.hass!.localize(`ui.dialogs.more_info_control.fan.speed.${speed}`) || this.hass!.localize(`ui.dialogs.more_info_control.fan.speed.${speed}`) ||

View File

@ -1,11 +1,10 @@
import type { HassEntity } from "home-assistant-js-websocket"; import type { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; 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 { computeRTL } from "../common/util/compute_rtl";
import "../components/entity/state-info"; import "../components/entity/state-info";
import { haStyle } from "../resources/styles"; import { haStyle } from "../resources/styles";
import { stateActive } from "../common/entity/state_active";
import type { HomeAssistant } from "../types"; import type { HomeAssistant } from "../types";
@customElement("state-card-alert") @customElement("state-card-alert")
@ -34,13 +33,7 @@ export class StateCardAlert extends LitElement {
.hass=${this.hass} .hass=${this.hass}
.stateObj=${this.stateObj} .stateObj=${this.stateObj}
></ha-entity-toggle>` ></ha-entity-toggle>`
: computeStateDisplay( : this.hass.formatEntityState(this.stateObj)}
this.hass!.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div> </div>
</div> </div>
`; `;

View File

@ -3,7 +3,6 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
import { computeDomain } from "../common/entity/compute_domain"; import { computeDomain } from "../common/entity/compute_domain";
import { computeStateDisplay } from "../common/entity/compute_state_display";
import { computeRTL } from "../common/util/compute_rtl"; import { computeRTL } from "../common/util/compute_rtl";
import "../components/entity/state-info"; import "../components/entity/state-info";
import { isUnavailableState } from "../data/entity"; import { isUnavailableState } from "../data/entity";
@ -48,13 +47,7 @@ export class StateCardDisplay extends LitElement {
format="datetime" format="datetime"
capitalize capitalize
></hui-timestamp-display>` ></hui-timestamp-display>`
: computeStateDisplay( : this.hass.formatEntityState(this.stateObj)}
this.hass!.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div> </div>
</div> </div>
`; `;

View File

@ -3,10 +3,8 @@ import { css, CSSResultGroup, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import "../components/entity/ha-entity-toggle"; import "../components/entity/ha-entity-toggle";
import "../components/entity/state-info"; 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 { haStyle } from "../resources/styles";
import { HomeAssistant } from "../types";
@customElement("state-card-event") @customElement("state-card-event")
export class StateCardEvent extends LitElement { export class StateCardEvent extends LitElement {
@ -26,23 +24,10 @@ export class StateCardEvent extends LitElement {
></state-info> ></state-info>
<div class="container"> <div class="container">
<div class="event_type"> <div class="event_type">
${computeStateDisplay( ${this.hass.formatEntityState(this.stateObj)}
this.hass!.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div> </div>
<div class="event_data"> <div class="event_data">
${computeAttributeValueDisplay( ${this.hass.formatEntityAttributeValue(this.stateObj, "event_type")}
this.hass!.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
"event_type"
)}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,16 +1,15 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { computeStateDisplay } from "../common/entity/compute_state_display";
import { computeRTLDirection } from "../common/util/compute_rtl"; import { computeRTLDirection } from "../common/util/compute_rtl";
import { debounce } from "../common/util/debounce"; import { debounce } from "../common/util/debounce";
import "../components/entity/state-info";
import "../components/ha-slider"; import "../components/ha-slider";
import "../components/ha-textfield"; import "../components/ha-textfield";
import "../components/entity/state-info";
import { isUnavailableState } from "../data/entity"; import { isUnavailableState } from "../data/entity";
import { setValue } from "../data/input_text"; import { setValue } from "../data/input_text";
import { HomeAssistant } from "../types";
import { loadPolyfillIfNeeded } from "../resources/resize-observer.polyfill"; import { loadPolyfillIfNeeded } from "../resources/resize-observer.polyfill";
import { HomeAssistant } from "../types";
@customElement("state-card-input_number") @customElement("state-card-input_number")
class StateCardInputNumber extends LitElement { class StateCardInputNumber extends LitElement {
@ -69,14 +68,7 @@ class StateCardInputNumber extends LitElement {
ignore-bar-touch ignore-bar-touch
></ha-slider> ></ha-slider>
<span class="state"> <span class="state">
${computeStateDisplay( ${this.hass.formatEntityState(this.stateObj)}
this.hass.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
this.stateObj.state
)}
</span> </span>
</div> </div>
` `

View File

@ -1,14 +1,13 @@
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import "../components/ha-select";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { stopPropagation } from "../common/dom/stop_propagation"; import { stopPropagation } from "../common/dom/stop_propagation";
import { computeStateName } from "../common/entity/compute_state_name"; import { computeStateName } from "../common/entity/compute_state_name";
import "../components/entity/state-badge"; import "../components/entity/state-badge";
import "../components/ha-select";
import { UNAVAILABLE } from "../data/entity"; import { UNAVAILABLE } from "../data/entity";
import { SelectEntity, setSelectOption } from "../data/select"; import { SelectEntity, setSelectOption } from "../data/select";
import type { HomeAssistant } from "../types"; import type { HomeAssistant } from "../types";
import { computeStateDisplay } from "../common/entity/compute_state_display";
@customElement("state-card-select") @customElement("state-card-select")
class StateCardSelect extends LitElement { class StateCardSelect extends LitElement {
@ -31,14 +30,7 @@ class StateCardSelect extends LitElement {
${this.stateObj.attributes.options.map( ${this.stateObj.attributes.options.map(
(option) => html` (option) => html`
<mwc-list-item .value=${option}> <mwc-list-item .value=${option}>
${computeStateDisplay( ${this.hass.formatEntityState(this.stateObj, option)}
this.hass.localize,
this.stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities,
option
)}
</mwc-list-item> </mwc-list-item>
` `
)} )}