Bugfix timedelta v2 (#5349)

* Bugfix timedelta v2

* fix volvo

* fix lint
pull/5384/head
Pascal Vizeli 2017-01-15 23:53:37 +01:00 committed by Paulus Schoutsen
parent 29e2613c75
commit 8a95cc4104
3 changed files with 8 additions and 15 deletions

View File

@ -1,14 +1,12 @@
"""Tracking for bluetooth low energy devices."""
import logging
from datetime import timedelta
import voluptuous as vol
from homeassistant.helpers.event import track_point_in_utc_time
from homeassistant.components.device_tracker import (
YAML_DEVICES, CONF_TRACK_NEW, CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL,
PLATFORM_SCHEMA, load_config, DEFAULT_TRACK_NEW
PLATFORM_SCHEMA, load_config
)
import homeassistant.util as util
import homeassistant.util.dt as dt_util
import homeassistant.helpers.config_validation as cv
@ -86,14 +84,13 @@ def setup_scanner(hass, config, see):
# if track new devices is true discover new devices
# on every scan.
track_new = util.convert(config.get(CONF_TRACK_NEW), bool,
DEFAULT_TRACK_NEW)
track_new = config.get(CONF_TRACK_NEW)
if not devs_to_track and not track_new:
_LOGGER.warning("No Bluetooth LE devices to track!")
return False
interval = util.convert(config.get(CONF_SCAN_INTERVAL), int,
DEFAULT_SCAN_INTERVAL)
interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
def update_ble(now):
"""Lookup Bluetooth LE devices and update status."""
@ -113,8 +110,7 @@ def setup_scanner(hass, config, see):
_LOGGER.info("Discovered Bluetooth LE device %s", address)
see_device(address, devs[address], new_device=True)
track_point_in_utc_time(hass, update_ble,
now + timedelta(seconds=interval))
track_point_in_utc_time(hass, update_ble, now + interval)
update_ble(dt_util.utcnow())

View File

@ -1,6 +1,5 @@
"""Tracking for bluetooth devices."""
import logging
from datetime import timedelta
import voluptuous as vol
@ -83,8 +82,7 @@ def setup_scanner(hass, config, see):
see_device((mac, result))
except bluetooth.BluetoothError:
_LOGGER.exception('Error looking up bluetooth device!')
track_point_in_utc_time(hass, update_bluetooth,
now + timedelta(seconds=interval))
track_point_in_utc_time(hass, update_bluetooth, now + interval)
update_bluetooth(dt_util.utcnow())

View File

@ -37,7 +37,7 @@ def setup_scanner(hass, config, see):
config.get(CONF_USERNAME),
config.get(CONF_PASSWORD))
interval = max(MIN_TIME_BETWEEN_SCANS.seconds,
interval = max(MIN_TIME_BETWEEN_SCANS,
config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL))
def _see_vehicle(vehicle):
@ -91,8 +91,7 @@ def setup_scanner(hass, config, see):
return True
finally:
track_point_in_utc_time(hass, update,
now + timedelta(seconds=interval))
track_point_in_utc_time(hass, update, now + interval)
_LOGGER.info('Logging in to service')
return update(utcnow())