Fix current_humidity no shown on climate state card if also current_temperature is set (#14993)

* Also show current_humidity on climate

* Use one line

* Update src/components/ha-climate-state.ts

Co-authored-by: Paul Bottein <paul.bottein@gmail.com>

* Another blank and add import

Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
This commit is contained in:
Jan Bouwhuis 2023-01-24 17:55:13 +01:00 committed by GitHub
parent 711286f7c0
commit 363ad369fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ import { customElement, property } from "lit/decorators";
import { computeAttributeValueDisplay } from "../common/entity/compute_attribute_display";
import { computeStateDisplay } from "../common/entity/compute_state_display";
import { formatNumber } from "../common/number/format_number";
import { blankBeforePercent } from "../common/translations/blank_before_percent";
import { ClimateEntity, CLIMATE_PRESET_NONE } from "../data/climate";
import { isUnavailableState } from "../data/entity";
import type { HomeAssistant } from "../types";
@ -47,6 +48,19 @@ class HaClimateState extends LitElement {
if (!this.hass || !this.stateObj) {
return undefined;
}
if (
this.stateObj.attributes.current_temperature != null &&
this.stateObj.attributes.current_humidity != null
) {
return `${formatNumber(
this.stateObj.attributes.current_temperature,
this.hass.locale
)} ${this.hass.config.unit_system.temperature}/
${formatNumber(
this.stateObj.attributes.current_humidity,
this.hass.locale
)}${blankBeforePercent(this.hass.locale)}%`;
}
if (this.stateObj.attributes.current_temperature != null) {
return `${formatNumber(
@ -59,7 +73,7 @@ class HaClimateState extends LitElement {
return `${formatNumber(
this.stateObj.attributes.current_humidity,
this.hass.locale
)} %`;
)}${blankBeforePercent(this.hass.locale)}%`;
}
return undefined;