Ping device tracker now respects interval_seconds (#11348)
* Ping device tracker now respects interval_secondspull/11374/head
parent
f07a4684e0
commit
4914ad1dd9
|
@ -13,8 +13,8 @@ import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
PLATFORM_SCHEMA, DEFAULT_SCAN_INTERVAL, SOURCE_TYPE_ROUTER)
|
PLATFORM_SCHEMA, CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL,
|
||||||
from homeassistant.helpers.event import track_point_in_utc_time
|
SOURCE_TYPE_ROUTER)
|
||||||
from homeassistant import util
|
from homeassistant import util
|
||||||
from homeassistant import const
|
from homeassistant import const
|
||||||
|
|
||||||
|
@ -70,16 +70,21 @@ def setup_scanner(hass, config, see, discovery_info=None):
|
||||||
"""Set up the Host objects and return the update function."""
|
"""Set up the Host objects and return the update function."""
|
||||||
hosts = [Host(ip, dev_id, hass, config) for (dev_id, ip) in
|
hosts = [Host(ip, dev_id, hass, config) for (dev_id, ip) in
|
||||||
config[const.CONF_HOSTS].items()]
|
config[const.CONF_HOSTS].items()]
|
||||||
interval = timedelta(seconds=len(hosts) * config[CONF_PING_COUNT]) + \
|
interval = config.get(CONF_SCAN_INTERVAL,
|
||||||
DEFAULT_SCAN_INTERVAL
|
timedelta(seconds=len(hosts) *
|
||||||
_LOGGER.info("Started ping tracker with interval=%s on hosts: %s",
|
config[CONF_PING_COUNT])
|
||||||
|
+ DEFAULT_SCAN_INTERVAL)
|
||||||
|
_LOGGER.debug("Started ping tracker with interval=%s on hosts: %s",
|
||||||
interval, ",".join([host.ip_address for host in hosts]))
|
interval, ",".join([host.ip_address for host in hosts]))
|
||||||
|
|
||||||
def update(now):
|
def update_interval(now):
|
||||||
"""Update all the hosts on every interval time."""
|
"""Update all the hosts on every interval time."""
|
||||||
|
try:
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
host.update(see)
|
host.update(see)
|
||||||
track_point_in_utc_time(hass, update, util.dt.utcnow() + interval)
|
finally:
|
||||||
return True
|
hass.helpers.event.track_point_in_utc_time(
|
||||||
|
update_interval, util.dt.utcnow() + interval)
|
||||||
|
|
||||||
return update(util.dt.utcnow())
|
update_interval(None)
|
||||||
|
return True
|
||||||
|
|
Loading…
Reference in New Issue