mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
🐛 properly format timestamps in glance card (#4602)
* 🐛 properly format timestamps in glance card
* address review comments
This commit is contained in:
parent
4aa49f66bc
commit
cdf6e9eb75
@ -1,4 +1,5 @@
|
|||||||
export const UNAVAILABLE = "unavailable";
|
export const UNAVAILABLE = "unavailable";
|
||||||
|
export const UNKNOWN = "unknown";
|
||||||
|
|
||||||
export const ENTITY_COMPONENT_DOMAINS = [
|
export const ENTITY_COMPONENT_DOMAINS = [
|
||||||
"air_quality",
|
"air_quality",
|
||||||
|
@ -29,6 +29,8 @@ import { actionHandler } from "../common/directives/action-handler-directive";
|
|||||||
import { hasAction } from "../common/has-action";
|
import { hasAction } from "../common/has-action";
|
||||||
import { ActionHandlerEvent } from "../../../data/lovelace";
|
import { ActionHandlerEvent } from "../../../data/lovelace";
|
||||||
import { handleAction } from "../common/handle-action";
|
import { handleAction } from "../common/handle-action";
|
||||||
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
|
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity";
|
||||||
|
|
||||||
@customElement("hui-glance-card")
|
@customElement("hui-glance-card")
|
||||||
export class HuiGlanceCard extends LitElement implements LovelaceCard {
|
export class HuiGlanceCard extends LitElement implements LovelaceCard {
|
||||||
@ -242,7 +244,18 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
|
|||||||
${this._config!.show_state !== false && entityConf.show_state !== false
|
${this._config!.show_state !== false && entityConf.show_state !== false
|
||||||
? html`
|
? html`
|
||||||
<div>
|
<div>
|
||||||
${entityConf.show_last_changed
|
${computeDomain(entityConf.entity) === "sensor" &&
|
||||||
|
stateObj.attributes.device_class === "timestamp" &&
|
||||||
|
stateObj.state !== UNAVAILABLE &&
|
||||||
|
stateObj.state !== UNKNOWN
|
||||||
|
? html`
|
||||||
|
<hui-timestamp-display
|
||||||
|
.hass=${this.hass}
|
||||||
|
.ts=${new Date(stateObj.state)}
|
||||||
|
.format=${entityConf.format}
|
||||||
|
></hui-timestamp-display>
|
||||||
|
`
|
||||||
|
: entityConf.show_last_changed
|
||||||
? relativeTime(
|
? relativeTime(
|
||||||
new Date(stateObj.last_changed),
|
new Date(stateObj.last_changed),
|
||||||
this.hass!.localize
|
this.hass!.localize
|
||||||
|
Loading…
x
Reference in New Issue
Block a user