mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add support for relative start and end time displays in state-display (#22249)
* Add support for relative start and end time displays in state-display * Add support for sun attributes as well * Improve state-display code for relative-time --------- Co-authored-by: Wendelin <w@pe8.at>
This commit is contained in:
parent
ad49e9f7b0
commit
1b441a7eec
@ -99,31 +99,38 @@ class StateDisplay extends LitElement {
|
|||||||
if (content === "name") {
|
if (content === "name") {
|
||||||
return html`${this.name || stateObj.attributes.friendly_name}`;
|
return html`${this.name || stateObj.attributes.friendly_name}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let relativeDateTime: string | undefined;
|
||||||
|
|
||||||
// Check last-changed for backwards compatibility
|
// Check last-changed for backwards compatibility
|
||||||
if (content === "last_changed" || content === "last-changed") {
|
if (content === "last_changed" || content === "last-changed") {
|
||||||
return html`
|
relativeDateTime = stateObj.last_changed;
|
||||||
<ha-relative-time
|
|
||||||
.hass=${this.hass}
|
|
||||||
.datetime=${stateObj.last_changed}
|
|
||||||
capitalize
|
|
||||||
></ha-relative-time>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
// Check last_updated for backwards compatibility
|
// Check last_updated for backwards compatibility
|
||||||
if (content === "last_updated" || content === "last-updated") {
|
if (content === "last_updated" || content === "last-updated") {
|
||||||
return html`
|
relativeDateTime = stateObj.last_updated;
|
||||||
<ha-relative-time
|
|
||||||
.hass=${this.hass}
|
|
||||||
.datetime=${stateObj.last_updated}
|
|
||||||
capitalize
|
|
||||||
></ha-relative-time>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
if (content === "last_triggered") {
|
|
||||||
|
if (
|
||||||
|
content === "last_triggered" ||
|
||||||
|
(domain === "calendar" &&
|
||||||
|
(content === "start_time" || content === "end_time")) ||
|
||||||
|
(domain === "sun" &&
|
||||||
|
(content === "next_dawn" ||
|
||||||
|
content === "next_dusk" ||
|
||||||
|
content === "next_midnight" ||
|
||||||
|
content === "next_noon" ||
|
||||||
|
content === "next_rising" ||
|
||||||
|
content === "next_setting"))
|
||||||
|
) {
|
||||||
|
relativeDateTime = stateObj.attributes[content];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relativeDateTime) {
|
||||||
return html`
|
return html`
|
||||||
<ha-relative-time
|
<ha-relative-time
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.datetime=${stateObj.attributes.last_triggered}
|
.datetime=${relativeDateTime}
|
||||||
capitalize
|
capitalize
|
||||||
></ha-relative-time>
|
></ha-relative-time>
|
||||||
`;
|
`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user