Skip to content

Commit

Permalink
Merge pull request #36 from andythigpen/feature/device-tracker-interval
Browse files Browse the repository at this point in the history
Add configurable intervals to device tracker.
  • Loading branch information
balloob committed Feb 24, 2015
2 parents b5a3a72 + 22a2b65 commit 015e7f8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions homeassistant/components/device_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
# Filename to save known devices to
KNOWN_DEVICES_FILE = "known_devices.csv"

CONF_SECONDS = "interval_seconds"

DEFAULT_CONF_SECONDS = 12

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -126,8 +132,10 @@ def reload_known_devices_service(service):
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,
Expand Down

0 comments on commit 015e7f8

Please sign in to comment.