Add open label if cover is open on tile card (#14632)

This commit is contained in:
Paul Bottein 2022-12-08 13:19:49 +01:00 committed by GitHub
parent a8d242719f
commit ba09120ff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,7 @@ import { computeStateDisplay } from "../../../common/entity/compute_state_displa
import { stateActive } from "../../../common/entity/state_active";
import { stateColorCss } from "../../../common/entity/state_color";
import { stateIconPath } from "../../../common/entity/state_icon_path";
import { blankBeforePercent } from "../../../common/translations/blank_before_percent";
import "../../../components/ha-card";
import "../../../components/tile/ha-tile-badge";
import "../../../components/tile/ha-tile-icon";
@ -192,30 +193,35 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
if (domain === "light" && stateObj.state === ON) {
const brightness = (stateObj as LightEntity).attributes.brightness;
if (brightness) {
return `${Math.round((brightness * 100) / 255)}%`;
}
}
if (domain === "cover" && stateObj.state === "open") {
const position = (stateObj as CoverEntity).attributes.current_position;
if (position) {
return `${Math.round(position)}%`;
return `${Math.round((brightness * 100) / 255)}${blankBeforePercent(
this.hass!.locale
)}%`;
}
}
if (domain === "fan" && stateObj.state === ON) {
const speed = (stateObj as FanEntity).attributes.percentage;
if (speed) {
return `${Math.round(speed)}%`;
return `${Math.round(speed)}${blankBeforePercent(this.hass!.locale)}%`;
}
}
return computeStateDisplay(
const stateDisplay = computeStateDisplay(
this.hass!.localize,
stateObj,
this.hass!.locale,
this.hass!.entities
);
if (domain === "cover" && stateObj.state === "open") {
const position = (stateObj as CoverEntity).attributes.current_position;
if (position && position !== 100) {
return `${stateDisplay} - ${Math.round(position)}${blankBeforePercent(
this.hass!.locale
)}%`;
}
}
return stateDisplay;
}
protected render(): TemplateResult {