diff --git a/homeassistant/components/device_sun_light_trigger.py b/homeassistant/components/device_sun_light_trigger.py index 4740336767f..c53fff0e4f3 100644 --- a/homeassistant/components/device_sun_light_trigger.py +++ b/homeassistant/components/device_sun_light_trigger.py @@ -6,8 +6,9 @@ Provides functionality to turn on lights based on the state of the sun and devices. """ import logging -from datetime import datetime, timedelta +from datetime import timedelta +import homeassistant.util.dt as dt_util from homeassistant.const import STATE_HOME, STATE_NOT_HOME from . import light, sun, device_tracker, group @@ -115,7 +116,7 @@ def setup(hass, config): new_state.state == STATE_HOME: # These variables are needed for the elif check - now = datetime.now() + now = dt_util.now() start_point = calc_time_for_light_when_sunset() # Do we need lights? diff --git a/homeassistant/components/device_tracker/nmap_tracker.py b/homeassistant/components/device_tracker/nmap_tracker.py index b2d009ab199..ccd04f6cda1 100644 --- a/homeassistant/components/device_tracker/nmap_tracker.py +++ b/homeassistant/components/device_tracker/nmap_tracker.py @@ -21,7 +21,7 @@ The IP addresses to scan in the network-prefix notation (192.168.1.1/24) or the range notation (192.168.1.1-255). """ import logging -from datetime import timedelta, datetime +from datetime import timedelta from collections import namedtuple import subprocess import re @@ -29,6 +29,7 @@ import re from libnmap.process import NmapProcess from libnmap.parser import NmapParser, NmapParserException +import homeassistant.util.dt as dt_util from homeassistant.const import CONF_HOSTS from homeassistant.helpers import validate_config from homeassistant.util import Throttle, convert @@ -106,7 +107,7 @@ class NmapDeviceScanner(object): Returns True if successful, False otherwise. """ try: results = NmapParser.parse(stdout) - now = datetime.now() + now = dt_util.now() self.last_results = [] for host in results.hosts: if host.is_up(): @@ -140,7 +141,7 @@ class NmapDeviceScanner(object): options = "-F --host-timeout 5" exclude_targets = set() if self.home_interval: - now = datetime.now() + now = dt_util.now() for host in self.last_results: if host.last_update + self.home_interval > now: exclude_targets.add(host) diff --git a/homeassistant/components/scheduler/time.py b/homeassistant/components/scheduler/time.py index 94eabe7dd2b..793f33d0502 100644 --- a/homeassistant/components/scheduler/time.py +++ b/homeassistant/components/scheduler/time.py @@ -13,9 +13,10 @@ which time. } """ -from datetime import datetime, timedelta +from datetime import timedelta import logging +import homeassistant.util.dt as dt_util from homeassistant.components.scheduler import ServiceEventListener _LOGGER = logging.getLogger(__name__) @@ -46,14 +47,12 @@ class TimeEventListener(ServiceEventListener): def schedule(self, hass): """ Schedule this event so that it will be called. """ - next_time = datetime.now().replace(hour=self.hour, - minute=self.minute, - second=self.second, - microsecond=0) + next_time = dt_util.now().replace( + hour=self.hour, minute=self.minute, second=self.second) # Calculate the next time the event should be executed. # That is the next day that the schedule is configured to run - while next_time < datetime.now() or \ + while next_time < dt_util.now() or \ next_time.weekday() not in self.my_schedule.days: next_time = next_time + timedelta(days=1) diff --git a/homeassistant/components/sun.py b/homeassistant/components/sun.py index 208d17167c6..ae33f86f01e 100644 --- a/homeassistant/components/sun.py +++ b/homeassistant/components/sun.py @@ -22,7 +22,7 @@ which event (sunset or sunrise) and the offset. """ import logging -from datetime import datetime, timedelta +from datetime import timedelta try: import ephem @@ -233,7 +233,7 @@ class SunEventListener(ServiceEventListener): else: next_time = next_event + self.offset - while next_time < datetime.now() or \ + while next_time < dt_util.now() or \ next_time.weekday() not in self.my_schedule.days: next_time = next_time + timedelta(days=1)