Add entity attribute value translations for humidifier (#16565)

This commit is contained in:
Franck Nijhof 2023-05-17 15:26:16 +02:00 committed by GitHub
parent e354f5de12
commit d873f26db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 31 deletions

View File

@ -3,14 +3,11 @@ import {
HassEntityBase,
} from "home-assistant-js-websocket";
import { FIXED_DOMAIN_STATES } from "../common/entity/get_states";
import { TranslationDict } from "../types";
import { UNAVAILABLE_STATES } from "./entity";
type HumidifierState =
| (typeof FIXED_DOMAIN_STATES.humidifier)[number]
| (typeof UNAVAILABLE_STATES)[number];
type HumidifierMode =
keyof TranslationDict["state_attributes"]["humidifier"]["mode"];
export type HumidifierEntity = HassEntityBase & {
state: HumidifierState;
@ -18,8 +15,8 @@ export type HumidifierEntity = HassEntityBase & {
humidity?: number;
min_humidity?: number;
max_humidity?: number;
mode?: HumidifierMode;
available_modes?: HumidifierMode[];
mode?: string;
available_modes?: string[];
};
};

View File

@ -10,6 +10,7 @@ import {
import { property } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { fireEvent } from "../../../common/dom/fire_event";
import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
import { stopPropagation } from "../../../common/dom/stop_propagation";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
@ -78,9 +79,14 @@ class MoreInfoHumidifier extends LitElement {
${stateObj.attributes.available_modes!.map(
(mode) => html`
<mwc-list-item .value=${mode}>
${hass.localize(
`state_attributes.humidifier.mode.${mode}`
) || mode}
${computeAttributeValueDisplay(
hass.localize,
stateObj,
hass.locale,
hass.entities,
"mode",
mode
)}
</mwc-list-item>
`
)}

View File

@ -14,6 +14,7 @@ import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-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 { computeStateName } from "../../../common/entity/compute_state_name";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
import "../../../components/ha-card";
@ -135,9 +136,13 @@ export class HuiHumidifierCard extends LitElement implements LovelaceCard {
${stateObj.attributes.mode && !isUnavailableState(stateObj.state)
? html`
-
${this.hass!.localize(
`state_attributes.humidifier.mode.${stateObj.attributes.mode}`
) || stateObj.attributes.mode}
${computeAttributeValueDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.entities,
"mode"
)}
`
: ""}
</text>

View File

@ -5,6 +5,7 @@ import { HumidifierEntity } from "../../../data/humidifier";
import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-generic-entity-row";
import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { EntityConfig, LovelaceRow } from "./types";
@ -49,11 +50,13 @@ class HuiHumidifierEntityRow extends LitElement implements LovelaceRow {
? `${this.hass!.localize("ui.card.humidifier.humidity")}:
${stateObj.attributes.humidity} %${
stateObj.attributes.mode
? ` (${
this.hass!.localize(
`state_attributes.humidifier.mode.${stateObj.attributes.mode}`
) || stateObj.attributes.mode
})`
? ` (${computeAttributeValueDisplay(
this.hass.localize,
stateObj,
this.hass.locale,
this.hass.entities,
"mode"
)})`
: ""
}`
: ""}

View File

@ -21,21 +21,6 @@
"unavailable": "Unavailable"
}
},
"state_attributes": {
"humidifier": {
"mode": {
"normal": "Normal",
"eco": "Eco",
"away": "Away",
"boost": "Boost",
"comfort": "Comfort",
"home": "Home",
"sleep": "Sleep",
"auto": "Auto",
"baby": "Baby"
}
}
},
"state_badge": {
"default": {
"unknown": "Unk",