New date_time_utc display option added to the time_date sensor platform (#30158)

This commit is contained in:
Claudio Heckler authored and Fabian Affolter committed 2019-12-23 21:48:24 +01:00
1 parent 059e8722b6
commit edce497a0d
2 files changed
+52 -3

No files matched your search

+5 -1
View File
@@ -20,7 +20,8 @@ OPTION_TYPES = {
"time": "Time",
"date": "Date",
"date_time": "Date & Time",
"date_time_iso": "Date & Time ISO",
"date_time_utc": "Date & Time (UTC)",
"date_time_iso": "Date & Time (ISO)",
"time_date": "Time & Date",
"beat": "Internet Time",
"time_utc": "Time (UTC)",
@@ -102,6 +103,7 @@ class TimeDateSensor(Entity):
time = dt_util.as_local(time_date).strftime(TIME_STR_FORMAT)
time_utc = time_date.strftime(TIME_STR_FORMAT)
date = dt_util.as_local(time_date).date().isoformat()
date_utc = time_date.date().isoformat()
# Calculate Swatch Internet Time.
time_bmt = time_date + timedelta(hours=1)
@@ -119,6 +121,8 @@ class TimeDateSensor(Entity):
self._state = date
elif self.type == "date_time":
self._state = f"{date}, {time}"
elif self.type == "date_time_utc":
self._state = f"{date_utc}, {time_utc}"
elif self.type == "time_date":
self._state = f"{time}, {date}"
elif self.type == "time_utc":