Round battery values in device table to whole numbers (to fit in the column width) (#14927)

* Increase battery column width to fit 100.0%

* drop trailing 0s from battery decimals

* round values to whole numbers
This commit is contained in:
karwosts 2023-01-24 08:16:03 -08:00 committed by GitHub
parent 78857357f3
commit 711286f7c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -338,11 +338,14 @@ export class HaConfigDeviceDashboard extends LitElement {
: undefined;
const batteryIsBinary =
battery && computeStateDomain(battery) === "binary_sensor";
return battery && (batteryIsBinary || !isNaN(battery.state as any))
? html`
${batteryIsBinary
? ""
: battery.state + blankBeforePercent(this.hass.locale) + "%"}
: Number(battery.state).toFixed() +
blankBeforePercent(this.hass.locale) +
"%"}
<ha-battery-icon
.hass=${this.hass!}
.batteryStateObj=${battery}