From 22a2b65e3fb8a4340f45cdff26cd4eff2e418f42 Mon Sep 17 00:00:00 2001 From: andythigpen Date: Sat, 21 Feb 2015 16:03:02 -0600 Subject: [PATCH] Add configurable intervals to device tracker. Allows the user to configure a longer interval for when the device tracker should scan for devices. --- .../components/device_tracker/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py index 97b9f457703..3899f42a621 100644 --- a/homeassistant/components/device_tracker/__init__.py +++ b/homeassistant/components/device_tracker/__init__.py @@ -36,6 +36,9 @@ TIME_DEVICE_NOT_FOUND = timedelta(minutes=3) # Filename to save known devices to KNOWN_DEVICES_FILE = "known_devices.csv" +CONF_SECONDS = "interval_seconds" + +DEFAULT_CONF_SECONDS = 12 _LOGGER = logging.getLogger(__name__) @@ -81,7 +84,10 @@ def setup(hass, config): return False - tracker = DeviceTracker(hass, device_scanner) + seconds = util.convert(config[DOMAIN].get(CONF_SECONDS), int, + DEFAULT_CONF_SECONDS) + + tracker = DeviceTracker(hass, device_scanner, seconds) # We only succeeded if we got to parse the known devices file return not tracker.invalid_known_devices_file @@ -90,7 +96,7 @@ def setup(hass, config): class DeviceTracker(object): """ Class that tracks which devices are home and which are not. """ - def __init__(self, hass, device_scanner): + def __init__(self, hass, device_scanner, seconds): self.hass = hass self.device_scanner = device_scanner @@ -126,8 +132,10 @@ class DeviceTracker(object): if self.invalid_known_devices_file: return - hass.track_time_change( - update_device_state, second=range(0, 60, 12)) + seconds = range(0, 60, seconds) + + _LOGGER.info("Device tracker interval second=%s", seconds) + hass.track_time_change(update_device_state, second=seconds) hass.services.register(DOMAIN, SERVICE_DEVICE_TRACKER_RELOAD,