mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Bluetooth: keep looking for new devices (#3201)
* keep looking for new devices * Update bluetooth_tracker.py * change default value for tracking new devices * remove commented code
This commit is contained in:
parent
478c82c34c
commit
9ade87013e
@ -11,6 +11,7 @@ from homeassistant.components.device_tracker import (
|
|||||||
DEFAULT_SCAN_INTERVAL,
|
DEFAULT_SCAN_INTERVAL,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
load_config,
|
load_config,
|
||||||
|
DEFAULT_TRACK_NEW
|
||||||
)
|
)
|
||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
@ -88,7 +89,7 @@ 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 = util.convert(config.get(CONF_TRACK_NEW), bool,
|
||||||
len(devs_to_track) == 0)
|
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
|
||||||
|
@ -8,7 +8,7 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
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,
|
||||||
load_config, PLATFORM_SCHEMA)
|
load_config, PLATFORM_SCHEMA, DEFAULT_TRACK_NEW)
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -56,7 +56,7 @@ def setup_scanner(hass, config, see):
|
|||||||
devs_donot_track.append(device.mac[3:])
|
devs_donot_track.append(device.mac[3:])
|
||||||
|
|
||||||
# if track new devices is true discover new devices on startup.
|
# if track new devices is true discover new devices on startup.
|
||||||
track_new = config.get(CONF_TRACK_NEW, len(devs_to_track) == 0)
|
track_new = config.get(CONF_TRACK_NEW, DEFAULT_TRACK_NEW)
|
||||||
if track_new:
|
if track_new:
|
||||||
for dev in discover_devices():
|
for dev in discover_devices():
|
||||||
if dev[0] not in devs_to_track and \
|
if dev[0] not in devs_to_track and \
|
||||||
@ -64,15 +64,16 @@ def setup_scanner(hass, config, see):
|
|||||||
devs_to_track.append(dev[0])
|
devs_to_track.append(dev[0])
|
||||||
see_device(dev)
|
see_device(dev)
|
||||||
|
|
||||||
if not devs_to_track:
|
|
||||||
_LOGGER.warning("No bluetooth devices to track!")
|
|
||||||
return False
|
|
||||||
|
|
||||||
interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
||||||
|
|
||||||
def update_bluetooth(now):
|
def update_bluetooth(now):
|
||||||
"""Lookup bluetooth device and update status."""
|
"""Lookup bluetooth device and update status."""
|
||||||
try:
|
try:
|
||||||
|
if track_new:
|
||||||
|
for dev in discover_devices():
|
||||||
|
if dev[0] not in devs_to_track and \
|
||||||
|
dev[0] not in devs_donot_track:
|
||||||
|
devs_to_track.append(dev[0])
|
||||||
for mac in devs_to_track:
|
for mac in devs_to_track:
|
||||||
_LOGGER.debug("Scanning " + mac)
|
_LOGGER.debug("Scanning " + mac)
|
||||||
result = bluetooth.lookup_name(mac, timeout=5)
|
result = bluetooth.lookup_name(mac, timeout=5)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user