Add device_id configuration option to Bluetooth tracker (#18539)

* Bluetooth tracker: add device_id configuration option

Makes the device id that bluetooth tracker is using configurable instead 
of using the first available device.

* Remove unncessary default in config.get

It is already handled in the configuration validation.
pull/19551/head
Igor Motov 2018-12-25 12:29:44 -05:00 committed by Fabian Affolter
parent 6b204941cf
commit b9a0f40827
1 changed files with 10 additions and 2 deletions

View File

@ -24,9 +24,15 @@ BT_PREFIX = 'BT_'
CONF_REQUEST_RSSI = 'request_rssi'
CONF_DEVICE_ID = "device_id"
DEFAULT_DEVICE_ID = -1
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_TRACK_NEW): cv.boolean,
vol.Optional(CONF_REQUEST_RSSI): cv.boolean
vol.Optional(CONF_REQUEST_RSSI): cv.boolean,
vol.Optional(CONF_DEVICE_ID, default=DEFAULT_DEVICE_ID):
vol.All(vol.Coerce(int), vol.Range(min=-1))
})
@ -44,11 +50,13 @@ def setup_scanner(hass, config, see, discovery_info=None):
see(mac="{}{}".format(BT_PREFIX, mac), host_name=name,
attributes=attributes, source_type=SOURCE_TYPE_BLUETOOTH)
device_id = config.get(CONF_DEVICE_ID)
def discover_devices():
"""Discover Bluetooth devices."""
result = bluetooth.discover_devices(
duration=8, lookup_names=True, flush_cache=True,
lookup_class=False)
lookup_class=False, device_id=device_id)
_LOGGER.debug("Bluetooth devices discovered = %d", len(result))
return result