UTC upgrades for scheduler, nmap tracker, dsl_trigger
This commit is contained in:
parent
cd2b9ce975
commit
ae0cf49560
4 changed files with 14 additions and 13 deletions
|
@ -6,8 +6,9 @@ Provides functionality to turn on lights based on
|
||||||
the state of the sun and devices.
|
the state of the sun and devices.
|
||||||
"""
|
"""
|
||||||
import logging
|
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 homeassistant.const import STATE_HOME, STATE_NOT_HOME
|
||||||
from . import light, sun, device_tracker, group
|
from . import light, sun, device_tracker, group
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ def setup(hass, config):
|
||||||
new_state.state == STATE_HOME:
|
new_state.state == STATE_HOME:
|
||||||
|
|
||||||
# These variables are needed for the elif check
|
# These variables are needed for the elif check
|
||||||
now = datetime.now()
|
now = dt_util.now()
|
||||||
start_point = calc_time_for_light_when_sunset()
|
start_point = calc_time_for_light_when_sunset()
|
||||||
|
|
||||||
# Do we need lights?
|
# Do we need lights?
|
||||||
|
|
|
@ -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).
|
the range notation (192.168.1.1-255).
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
@ -29,6 +29,7 @@ import re
|
||||||
from libnmap.process import NmapProcess
|
from libnmap.process import NmapProcess
|
||||||
from libnmap.parser import NmapParser, NmapParserException
|
from libnmap.parser import NmapParser, NmapParserException
|
||||||
|
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.const import CONF_HOSTS
|
from homeassistant.const import CONF_HOSTS
|
||||||
from homeassistant.helpers import validate_config
|
from homeassistant.helpers import validate_config
|
||||||
from homeassistant.util import Throttle, convert
|
from homeassistant.util import Throttle, convert
|
||||||
|
@ -106,7 +107,7 @@ class NmapDeviceScanner(object):
|
||||||
Returns True if successful, False otherwise. """
|
Returns True if successful, False otherwise. """
|
||||||
try:
|
try:
|
||||||
results = NmapParser.parse(stdout)
|
results = NmapParser.parse(stdout)
|
||||||
now = datetime.now()
|
now = dt_util.now()
|
||||||
self.last_results = []
|
self.last_results = []
|
||||||
for host in results.hosts:
|
for host in results.hosts:
|
||||||
if host.is_up():
|
if host.is_up():
|
||||||
|
@ -140,7 +141,7 @@ class NmapDeviceScanner(object):
|
||||||
options = "-F --host-timeout 5"
|
options = "-F --host-timeout 5"
|
||||||
exclude_targets = set()
|
exclude_targets = set()
|
||||||
if self.home_interval:
|
if self.home_interval:
|
||||||
now = datetime.now()
|
now = dt_util.now()
|
||||||
for host in self.last_results:
|
for host in self.last_results:
|
||||||
if host.last_update + self.home_interval > now:
|
if host.last_update + self.home_interval > now:
|
||||||
exclude_targets.add(host)
|
exclude_targets.add(host)
|
||||||
|
|
|
@ -13,9 +13,10 @@ which time.
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from datetime import datetime, timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.components.scheduler import ServiceEventListener
|
from homeassistant.components.scheduler import ServiceEventListener
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -46,14 +47,12 @@ class TimeEventListener(ServiceEventListener):
|
||||||
def schedule(self, hass):
|
def schedule(self, hass):
|
||||||
""" Schedule this event so that it will be called. """
|
""" Schedule this event so that it will be called. """
|
||||||
|
|
||||||
next_time = datetime.now().replace(hour=self.hour,
|
next_time = dt_util.now().replace(
|
||||||
minute=self.minute,
|
hour=self.hour, minute=self.minute, second=self.second)
|
||||||
second=self.second,
|
|
||||||
microsecond=0)
|
|
||||||
|
|
||||||
# Calculate the next time the event should be executed.
|
# Calculate the next time the event should be executed.
|
||||||
# That is the next day that the schedule is configured to run
|
# 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.weekday() not in self.my_schedule.days:
|
||||||
|
|
||||||
next_time = next_time + timedelta(days=1)
|
next_time = next_time + timedelta(days=1)
|
||||||
|
|
|
@ -22,7 +22,7 @@ which event (sunset or sunrise) and the offset.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ephem
|
import ephem
|
||||||
|
@ -233,7 +233,7 @@ class SunEventListener(ServiceEventListener):
|
||||||
else:
|
else:
|
||||||
next_time = next_event + self.offset
|
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.weekday() not in self.my_schedule.days:
|
||||||
next_time = next_time + timedelta(days=1)
|
next_time = next_time + timedelta(days=1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue