Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/panels/config/devices/ha-devices-data-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class HaDevicesDataTable extends LitElement {
return html`
${name}<br />
${device.area} | ${device.integration}<br />
${battery
${battery && !isNaN(battery.state as any)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

battery.state is always a string. You will need to parse it first. But I prefer that you compare it against unavailable and unknown instead

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or this:

Suggested change
${battery && !isNaN(battery.state as any)
${battery && !isNaN(Number(battery.state))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNaN does a string to number conversion, but I can also check for unavailable and unknown

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case it's fine.

? html`
${battery.state}%
<ha-state-icon
Expand Down Expand Up @@ -205,7 +205,7 @@ export class HaDevicesDataTable extends LitElement {
const battery = batteryEntity
? this.hass.states[batteryEntity]
: undefined;
return battery
return battery && !isNaN(battery.state as any)
? html`
${battery.state}%
<ha-state-icon
Expand Down
3 changes: 2 additions & 1 deletion src/panels/lovelace/entity-rows/hui-sensor-entity-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class HuiSensorEntityRow extends LitElement implements EntityRow {
<hui-generic-entity-row .hass="${this.hass}" .config="${this._config}">
<div>
${stateObj.attributes.device_class === "timestamp" &&
stateObj.state !== "unavailable"
stateObj.state !== "unavailable" &&
stateObj.state !== "unknown"
? html`
<hui-timestamp-display
.hass="${this.hass}"
Expand Down