mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Rename date_util to dt_util
Follows the rest of Home Assistant
This commit is contained in:
parent
f8668075d0
commit
934b097bc7
@ -25,7 +25,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.exceptions import (
|
from homeassistant.exceptions import (
|
||||||
HomeAssistantError, InvalidEntityFormatError)
|
HomeAssistantError, InvalidEntityFormatError)
|
||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
import homeassistant.util.dt as date_util
|
import homeassistant.util.dt as dt_util
|
||||||
import homeassistant.util.location as location
|
import homeassistant.util.location as location
|
||||||
import homeassistant.helpers.temperature as temp_helper
|
import homeassistant.helpers.temperature as temp_helper
|
||||||
from homeassistant.config import get_default_config_dir
|
from homeassistant.config import get_default_config_dir
|
||||||
@ -196,8 +196,8 @@ class Event(object):
|
|||||||
self.event_type = event_type
|
self.event_type = event_type
|
||||||
self.data = data or {}
|
self.data = data or {}
|
||||||
self.origin = origin
|
self.origin = origin
|
||||||
self.time_fired = date_util.strip_microseconds(
|
self.time_fired = dt_util.strip_microseconds(
|
||||||
time_fired or date_util.utcnow())
|
time_fired or dt_util.utcnow())
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
""" Returns a dict representation of this Event. """
|
""" Returns a dict representation of this Event. """
|
||||||
@ -205,7 +205,7 @@ class Event(object):
|
|||||||
'event_type': self.event_type,
|
'event_type': self.event_type,
|
||||||
'data': dict(self.data),
|
'data': dict(self.data),
|
||||||
'origin': str(self.origin),
|
'origin': str(self.origin),
|
||||||
'time_fired': date_util.datetime_to_str(self.time_fired),
|
'time_fired': dt_util.datetime_to_str(self.time_fired),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -351,14 +351,14 @@ class State(object):
|
|||||||
self.entity_id = entity_id.lower()
|
self.entity_id = entity_id.lower()
|
||||||
self.state = state
|
self.state = state
|
||||||
self.attributes = attributes or {}
|
self.attributes = attributes or {}
|
||||||
self.last_updated = date_util.strip_microseconds(
|
self.last_updated = dt_util.strip_microseconds(
|
||||||
last_updated or date_util.utcnow())
|
last_updated or dt_util.utcnow())
|
||||||
|
|
||||||
# Strip microsecond from last_changed else we cannot guarantee
|
# Strip microsecond from last_changed else we cannot guarantee
|
||||||
# state == State.from_dict(state.as_dict())
|
# state == State.from_dict(state.as_dict())
|
||||||
# This behavior occurs because to_dict uses datetime_to_str
|
# This behavior occurs because to_dict uses datetime_to_str
|
||||||
# which does not preserve microseconds
|
# which does not preserve microseconds
|
||||||
self.last_changed = date_util.strip_microseconds(
|
self.last_changed = dt_util.strip_microseconds(
|
||||||
last_changed or self.last_updated)
|
last_changed or self.last_updated)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -391,8 +391,8 @@ class State(object):
|
|||||||
return {'entity_id': self.entity_id,
|
return {'entity_id': self.entity_id,
|
||||||
'state': self.state,
|
'state': self.state,
|
||||||
'attributes': self.attributes,
|
'attributes': self.attributes,
|
||||||
'last_changed': date_util.datetime_to_str(self.last_changed),
|
'last_changed': dt_util.datetime_to_str(self.last_changed),
|
||||||
'last_updated': date_util.datetime_to_str(self.last_updated)}
|
'last_updated': dt_util.datetime_to_str(self.last_updated)}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, json_dict):
|
def from_dict(cls, json_dict):
|
||||||
@ -407,12 +407,12 @@ class State(object):
|
|||||||
last_changed = json_dict.get('last_changed')
|
last_changed = json_dict.get('last_changed')
|
||||||
|
|
||||||
if last_changed:
|
if last_changed:
|
||||||
last_changed = date_util.str_to_datetime(last_changed)
|
last_changed = dt_util.str_to_datetime(last_changed)
|
||||||
|
|
||||||
last_updated = json_dict.get('last_updated')
|
last_updated = json_dict.get('last_updated')
|
||||||
|
|
||||||
if last_updated:
|
if last_updated:
|
||||||
last_updated = date_util.str_to_datetime(last_updated)
|
last_updated = dt_util.str_to_datetime(last_updated)
|
||||||
|
|
||||||
return cls(json_dict['entity_id'], json_dict['state'],
|
return cls(json_dict['entity_id'], json_dict['state'],
|
||||||
json_dict.get('attributes'), last_changed, last_updated)
|
json_dict.get('attributes'), last_changed, last_updated)
|
||||||
@ -429,7 +429,7 @@ class State(object):
|
|||||||
|
|
||||||
return "<state {}={}{} @ {}>".format(
|
return "<state {}={}{} @ {}>".format(
|
||||||
self.entity_id, self.state, attr,
|
self.entity_id, self.state, attr,
|
||||||
date_util.datetime_to_local_str(self.last_changed))
|
dt_util.datetime_to_local_str(self.last_changed))
|
||||||
|
|
||||||
|
|
||||||
class StateMachine(object):
|
class StateMachine(object):
|
||||||
@ -733,7 +733,7 @@ class Config(object):
|
|||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
""" Converts config to a dictionary. """
|
""" Converts config to a dictionary. """
|
||||||
time_zone = self.time_zone or date_util.UTC
|
time_zone = self.time_zone or dt_util.UTC
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'latitude': self.latitude,
|
'latitude': self.latitude,
|
||||||
@ -767,7 +767,7 @@ def create_timer(hass, interval=TIMER_INTERVAL):
|
|||||||
|
|
||||||
last_fired_on_second = -1
|
last_fired_on_second = -1
|
||||||
|
|
||||||
calc_now = date_util.utcnow
|
calc_now = dt_util.utcnow
|
||||||
|
|
||||||
while not stop_event.isSet():
|
while not stop_event.isSet():
|
||||||
now = calc_now()
|
now = calc_now()
|
||||||
@ -833,6 +833,6 @@ def create_worker_pool(worker_count=None):
|
|||||||
|
|
||||||
for start, job in current_jobs:
|
for start, job in current_jobs:
|
||||||
_LOGGER.warning("WorkerPool:Current job from %s: %s",
|
_LOGGER.warning("WorkerPool:Current job from %s: %s",
|
||||||
date_util.datetime_to_local_str(start), job)
|
dt_util.datetime_to_local_str(start), job)
|
||||||
|
|
||||||
return util.ThreadPool(job_handler, worker_count, busy_callback)
|
return util.ThreadPool(job_handler, worker_count, busy_callback)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user