-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add device_tracker.bluetooth_update service #15252
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
Changes from 4 commits
97a6d98
a4299d4
5b4bfa4
a6d6f76
867c913
4d1c0e3
b7144e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,8 @@ | |
| 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) | ||
| load_config, PLATFORM_SCHEMA, DEFAULT_TRACK_NEW, SOURCE_TYPE_BLUETOOTH, | ||
| DOMAIN) | ||
| import homeassistant.util.dt as dt_util | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
@@ -80,6 +81,12 @@ def discover_devices(): | |
| request_rssi = config.get(CONF_REQUEST_RSSI, False) | ||
|
|
||
| def update_bluetooth(now): | ||
| """Update Bluetooth and set timer for the next update""" | ||
| update_bluetooth_once() | ||
| track_point_in_utc_time( | ||
| hass, update_bluetooth, dt_util.utcnow() + interval) | ||
|
|
||
| def update_bluetooth_once(): | ||
| """Lookup Bluetooth device and update status.""" | ||
| try: | ||
| if track_new: | ||
|
|
@@ -99,9 +106,14 @@ def update_bluetooth(now): | |
| see_device(mac, result, rssi) | ||
| except bluetooth.BluetoothError: | ||
| _LOGGER.exception("Error looking up Bluetooth device") | ||
| track_point_in_utc_time( | ||
| hass, update_bluetooth, dt_util.utcnow() + interval) | ||
|
|
||
| def handle_update_bluetooth(call): | ||
| """Update bluetooth devices on demand.""" | ||
| now = dt_util.utcnow() | ||
| update_bluetooth(now, True) | ||
|
|
||
| update_bluetooth(dt_util.utcnow()) | ||
|
|
||
| hass.services.register(DOMAIN, "bluetooth_tracker_update", handle_update_bluetooth) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (87 > 79 characters)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fun story: PyCharm for some weird totally non PEP 8 reason has a default gutter of 120, rather than 80. They fooled me! |
||
|
|
||
| return True | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this function?
Why not call
update_bluetooth_oncedirectly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certianly could, I just left it using the handle function per a previous comment you said:
I assumed you wanted it left using the
handle_update_bluetoothfunction, to absorb the unusedcallparameter.