diff --git a/gallery/src/pages/lovelace/entities-card.ts b/gallery/src/pages/lovelace/entities-card.ts index a4fc76a510..6cec33cba5 100644 --- a/gallery/src/pages/lovelace/entities-card.ts +++ b/gallery/src/pages/lovelace/entities-card.ts @@ -75,6 +75,10 @@ const ENTITIES = [ timestamp: 1641801600, friendly_name: "Date and Time", }), + getEntity("sensor", "humidity", "23.2", { + friendly_name: "Humidity", + unit_of_measurement: "%", + }), getEntity("input_select", "dropdown", "Soda", { friendly_name: "Dropdown", options: ["Soda", "Beer", "Wine"], @@ -142,6 +146,7 @@ const CONFIGS = [ - light.non_existing - climate.ecobee - input_number.number + - sensor.humidity `, }, { diff --git a/src/common/entity/compute_state_display.ts b/src/common/entity/compute_state_display.ts index bc7e1de564..ba759b197f 100644 --- a/src/common/entity/compute_state_display.ts +++ b/src/common/entity/compute_state_display.ts @@ -64,9 +64,12 @@ export const computeStateDisplayFromEntityAttributes = ( // fallback to default } } - return `${formatNumber(state, locale)}${ - attributes.unit_of_measurement ? " " + attributes.unit_of_measurement : "" - }`; + const unit = !attributes.unit_of_measurement + ? "" + : attributes.unit_of_measurement === "%" + ? "%" + : ` ${attributes.unit_of_measurement}`; + return `${formatNumber(state, locale)}${unit}`; } const domain = computeDomain(entityId); diff --git a/src/components/ha-gauge.ts b/src/components/ha-gauge.ts index 1d60da1b3c..e37d80a0b1 100644 --- a/src/components/ha-gauge.ts +++ b/src/components/ha-gauge.ts @@ -132,7 +132,9 @@ export class Gauge extends LitElement { this._segment_label ? this._segment_label : this.valueText || formatNumber(this.value, this.locale) - } ${this._segment_label ? "" : this.label} + }${ + this._segment_label ? "" : this.label === "%" ? "%" : ` ${this.label}` + } `; }