Add relative timestamp state_content for input_datetime (#24135)

* Fix digit grouping in input_datetime `year`

* Display `input_datetime`s `timestamp` attribute as relative time instead of number
pull/26786/head
Björn Ebbinghaus 2025-09-17 12:22:00 +02:00 committed by GitHub
parent 0e8e054db1
commit 04b01d2cd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -115,6 +115,9 @@ export const DOMAIN_ATTRIBUTES_FORMATERS: Record<
return formatDurationDigital(locale, { hours, minutes, seconds })!;
},
},
input_datetime: {
year: (value) => value.toString(),
},
};
export const NON_NUMERIC_ATTRIBUTES = [

View File

@ -104,7 +104,7 @@ class StateDisplay extends LitElement {
return html`${this.name || computeStateName(stateObj)}`;
}
let relativeDateTime: string | undefined;
let relativeDateTime: string | Date | undefined;
// Check last-changed for backwards compatibility
if (content === "last_changed" || content === "last-changed") {
@ -114,6 +114,9 @@ class StateDisplay extends LitElement {
if (content === "last_updated" || content === "last-updated") {
relativeDateTime = stateObj.last_updated;
}
if (domain === "input_datetime" && content === "timestamp") {
relativeDateTime = new Date(stateObj.attributes.timestamp * 1000);
}
if (
content === "last_triggered" ||