Merge pull request #36 from andythigpen/feature/device-tracker-interval
Add configurable intervals to device tracker.pull/40/merge
commit
015e7f8acf
|
@ -36,6 +36,9 @@ TIME_DEVICE_NOT_FOUND = timedelta(minutes=3)
|
||||||
# Filename to save known devices to
|
# Filename to save known devices to
|
||||||
KNOWN_DEVICES_FILE = "known_devices.csv"
|
KNOWN_DEVICES_FILE = "known_devices.csv"
|
||||||
|
|
||||||
|
CONF_SECONDS = "interval_seconds"
|
||||||
|
|
||||||
|
DEFAULT_CONF_SECONDS = 12
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -81,7 +84,10 @@ def setup(hass, config):
|
||||||
|
|
||||||
return False
|
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
|
# We only succeeded if we got to parse the known devices file
|
||||||
return not tracker.invalid_known_devices_file
|
return not tracker.invalid_known_devices_file
|
||||||
|
@ -90,7 +96,7 @@ def setup(hass, config):
|
||||||
class DeviceTracker(object):
|
class DeviceTracker(object):
|
||||||
""" Class that tracks which devices are home and which are not. """
|
""" 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.hass = hass
|
||||||
|
|
||||||
self.device_scanner = device_scanner
|
self.device_scanner = device_scanner
|
||||||
|
@ -126,8 +132,10 @@ class DeviceTracker(object):
|
||||||
if self.invalid_known_devices_file:
|
if self.invalid_known_devices_file:
|
||||||
return
|
return
|
||||||
|
|
||||||
hass.track_time_change(
|
seconds = range(0, 60, seconds)
|
||||||
update_device_state, second=range(0, 60, 12))
|
|
||||||
|
_LOGGER.info("Device tracker interval second=%s", seconds)
|
||||||
|
hass.track_time_change(update_device_state, second=seconds)
|
||||||
|
|
||||||
hass.services.register(DOMAIN,
|
hass.services.register(DOMAIN,
|
||||||
SERVICE_DEVICE_TRACKER_RELOAD,
|
SERVICE_DEVICE_TRACKER_RELOAD,
|
||||||
|
|
Loading…
Reference in New Issue