Bugfix timedelta v2 (#5349)

* Bugfix timedelta v2

* fix volvo

* fix lint
This commit is contained in:
Pascal Vizeli 2017-01-15 23:53:37 +01:00 committed by GitHub
parent 6b91d9a75c
commit 2e3d5302bf
3 changed files with 8 additions and 15 deletions

View File

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

View File

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

View File

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