Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure device tracker #23862

Merged
merged 6 commits into from May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions homeassistant/components/bluetooth_le_tracker/device_tracker.py
Expand Up @@ -2,12 +2,15 @@
import logging

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,
load_config, SOURCE_TYPE_BLUETOOTH_LE
from homeassistant.components.device_tracker.legacy import (
YAML_DEVICES, async_load_config
)
from homeassistant.components.device_tracker.const import (
CONF_TRACK_NEW, CONF_SCAN_INTERVAL, SCAN_INTERVAL, SOURCE_TYPE_BLUETOOTH_LE
)
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
import homeassistant.util.dt as dt_util
from homeassistant.util.async_ import run_coroutine_threadsafe

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -79,7 +82,10 @@ def discover_ble_devices():
# Load all known devices.
# We just need the devices so set consider_home and home range
# to 0
for device in load_config(yaml_path, hass, 0):
for device in run_coroutine_threadsafe(
async_load_config(yaml_path, hass, 0),
hass.loop
).result():
# check if device is a valid bluetooth device
if device.mac and device.mac[:4].upper() == BLE_PREFIX:
if device.track:
Expand All @@ -97,7 +103,7 @@ def discover_ble_devices():
_LOGGER.warning("No Bluetooth LE devices to track!")
return False

interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
interval = config.get(CONF_SCAN_INTERVAL, SCAN_INTERVAL)

def update_ble(now):
"""Lookup Bluetooth LE devices and update status."""
Expand Down
20 changes: 14 additions & 6 deletions homeassistant/components/bluetooth_tracker/device_tracker.py
Expand Up @@ -5,11 +5,16 @@

import homeassistant.helpers.config_validation as cv
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,
load_config, PLATFORM_SCHEMA, DEFAULT_TRACK_NEW, SOURCE_TYPE_BLUETOOTH,
DOMAIN)
from homeassistant.components.device_tracker import PLATFORM_SCHEMA
from homeassistant.components.device_tracker.legacy import (
YAML_DEVICES, async_load_config
)
from homeassistant.components.device_tracker.const import (
CONF_TRACK_NEW, CONF_SCAN_INTERVAL, SCAN_INTERVAL, DEFAULT_TRACK_NEW,
SOURCE_TYPE_BLUETOOTH, DOMAIN
)
import homeassistant.util.dt as dt_util
from homeassistant.util.async_ import run_coroutine_threadsafe

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -60,7 +65,10 @@ def discover_devices():
# Load all known devices.
# We just need the devices so set consider_home and home range
# to 0
for device in load_config(yaml_path, hass, 0):
for device in run_coroutine_threadsafe(
async_load_config(yaml_path, hass, 0),
hass.loop
).result():
# Check if device is a valid bluetooth device
if device.mac and device.mac[:3].upper() == BT_PREFIX:
if device.track:
Expand All @@ -77,7 +85,7 @@ def discover_devices():
devs_to_track.append(dev[0])
see_device(dev[0], dev[1])

interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
interval = config.get(CONF_SCAN_INTERVAL, SCAN_INTERVAL)

request_rssi = config.get(CONF_REQUEST_RSSI, False)

Expand Down