Use standardised datetime format
This commit is contained in:
1 parent
e7520ef401
commit
68d92c3196
29 files changed
+154
-162
No files matched your search
@@ -23,6 +23,8 @@ ATTR_TARGET = 'Destination'
|
||||
ATTR_REMAINING_TIME = 'Remaining time'
|
||||
ICON = 'mdi:bus'
|
||||
|
||||
TIME_STR_FORMAT = "%H:%M"
|
||||
|
||||
# Return cached results if last scan was less then this time ago.
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||
|
||||
@@ -126,10 +128,10 @@ class PublicTransportData(object):
|
||||
|
||||
try:
|
||||
self.times = [
|
||||
dt_util.datetime_to_time_str(
|
||||
dt_util.as_local(dt_util.utc_from_timestamp(
|
||||
item['from']['departureTimestamp']))
|
||||
)
|
||||
dt_util.as_local(
|
||||
dt_util.utc_from_timestamp(
|
||||
item['from']['departureTimestamp'])).strftime(
|
||||
TIME_STR_FORMAT)
|
||||
for item in connections
|
||||
]
|
||||
self.times.append(
|
||||
|
||||
@@ -131,9 +131,9 @@ class SystemMonitorSensor(Entity):
|
||||
elif self.type == 'ipv6_address':
|
||||
self._state = psutil.net_if_addrs()[self.argument][1][1]
|
||||
elif self.type == 'last_boot':
|
||||
self._state = dt_util.datetime_to_date_str(
|
||||
dt_util.as_local(
|
||||
dt_util.utc_from_timestamp(psutil.boot_time())))
|
||||
self._state = dt_util.as_local(
|
||||
dt_util.utc_from_timestamp(psutil.boot_time())
|
||||
).date().isoformat()
|
||||
elif self.type == 'since_last_boot':
|
||||
self._state = dt_util.utcnow() - dt_util.utc_from_timestamp(
|
||||
psutil.boot_time())
|
||||
@@ -19,6 +19,8 @@ OPTION_TYPES = {
|
||||
'time_utc': 'Time (UTC)',
|
||||
}
|
||||
|
||||
TIME_STR_FORMAT = "%H:%M"
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the Time and Date sensor."""
|
||||
@@ -70,9 +72,9 @@ class TimeDateSensor(Entity):
|
||||
def update(self):
|
||||
"""Get the latest data and updates the states."""
|
||||
time_date = dt_util.utcnow()
|
||||
time = dt_util.datetime_to_time_str(dt_util.as_local(time_date))
|
||||
time_utc = dt_util.datetime_to_time_str(time_date)
|
||||
date = dt_util.datetime_to_date_str(dt_util.as_local(time_date))
|
||||
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()
|
||||
|
||||
# Calculate the beat (Swatch Internet Time) time without date.
|
||||
hours, minutes, seconds = time_date.strftime('%H:%M:%S').split(':')
|
||||
|
||||
@@ -65,8 +65,7 @@ class VeraSensor(VeraDevice, Entity):
|
||||
last_tripped = self.vera_device.last_trip
|
||||
if last_tripped is not None:
|
||||
utc_time = dt_util.utc_from_timestamp(int(last_tripped))
|
||||
attr[ATTR_LAST_TRIP_TIME] = dt_util.datetime_to_str(
|
||||
utc_time)
|
||||
attr[ATTR_LAST_TRIP_TIME] = utc_time.isoformat()
|
||||
else:
|
||||
attr[ATTR_LAST_TRIP_TIME] = None
|
||||
tripped = self.vera_device.is_tripped
|
||||
|
||||
@@ -12,6 +12,7 @@ from homeassistant.helpers.entity import Entity
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
DEFAULT_NAME = "Worldclock Sensor"
|
||||
ICON = 'mdi:clock'
|
||||
TIME_STR_FORMAT = "%H:%M"
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
@@ -59,5 +60,5 @@ class WorldClockSensor(Entity):
|
||||
|
||||
def update(self):
|
||||
"""Get the time and updates the states."""
|
||||
self._state = dt_util.datetime_to_time_str(
|
||||
dt_util.now(time_zone=self._time_zone))
|
||||
self._state = dt_util.now(time_zone=self._time_zone).strftime(
|
||||
TIME_STR_FORMAT)
|
||||
@@ -138,10 +138,8 @@ class YrSensor(Entity):
|
||||
|
||||
# Find sensor
|
||||
for time_entry in self._weather.data['product']['time']:
|
||||
valid_from = dt_util.str_to_datetime(
|
||||
time_entry['@from'], "%Y-%m-%dT%H:%M:%SZ")
|
||||
valid_to = dt_util.str_to_datetime(
|
||||
time_entry['@to'], "%Y-%m-%dT%H:%M:%SZ")
|
||||
valid_from = dt_util.parse_datetime(time_entry['@from'])
|
||||
valid_to = dt_util.parse_datetime(time_entry['@to'])
|
||||
|
||||
loc_data = time_entry['location']
|
||||
|
||||
@@ -204,5 +202,4 @@ class YrData(object):
|
||||
model = self.data['meta']['model']
|
||||
if '@nextrun' not in model:
|
||||
model = model[0]
|
||||
self._nextrun = dt_util.str_to_datetime(model['@nextrun'],
|
||||
"%Y-%m-%dT%H:%M:%SZ")
|
||||
self._nextrun = dt_util.parse_datetime(model['@nextrun'])
|
||||
Reference in new issue
Block a user