|
1 | | -import { computeEntity, computeStateDomain } from 'custom-card-helpers'; |
| 1 | +import { computeEntity, computeStateDomain, formatDate, formatDateTime, formatTime } from 'custom-card-helpers'; |
2 | 2 | import { isObject, isUnavailable } from './util'; |
3 | 3 |
|
4 | 4 | export const checkEntity = (config) => { |
@@ -46,6 +46,35 @@ export const entityStateDisplay = (hass, stateObj, config) => { |
46 | 46 | } |
47 | 47 |
|
48 | 48 | const domain = computeStateDomain(stateObj); |
| 49 | + |
| 50 | + if (domain === 'input_datetime') { |
| 51 | + let date; |
| 52 | + if (!stateObj.attributes.has_time) { |
| 53 | + date = new Date(stateObj.attributes.year, stateObj.attributes.month - 1, stateObj.attributes.day); |
| 54 | + return formatDate(date, hass.language); |
| 55 | + } |
| 56 | + if (!stateObj.attributes.has_date) { |
| 57 | + const now = new Date(); |
| 58 | + date = new Date( |
| 59 | + now.getFullYear(), |
| 60 | + now.getMonth(), |
| 61 | + now.getDay(), |
| 62 | + stateObj.attributes.hour, |
| 63 | + stateObj.attributes.minute |
| 64 | + ); |
| 65 | + return formatTime(date, hass.language); |
| 66 | + } |
| 67 | + |
| 68 | + date = new Date( |
| 69 | + stateObj.attributes.year, |
| 70 | + stateObj.attributes.month - 1, |
| 71 | + stateObj.attributes.day, |
| 72 | + stateObj.attributes.hour, |
| 73 | + stateObj.attributes.minute |
| 74 | + ); |
| 75 | + return formatDateTime(date, hass.language); |
| 76 | + } |
| 77 | + |
49 | 78 | return ( |
50 | 79 | (stateObj.attributes.device_class && |
51 | 80 | hass.localize(`component.${domain}.state.${stateObj.attributes.device_class}.${stateObj.state}`)) || |
|
0 commit comments