Add device_tracker.bluetooth_update service#15252
Add device_tracker.bluetooth_update service#15252Danielhiversen merged 7 commits intohome-assistant:devfrom
Conversation
Will immediately scan for Bluetooth devices outside of the interval timer. Allows for less frequent scanning, with scanning on demand via automation.
| update_bluetooth(now, True) | ||
|
|
||
| update_bluetooth(dt_util.utcnow()) | ||
|
|
| request_rssi = config.get(CONF_REQUEST_RSSI, False) | ||
|
|
||
| def update_bluetooth(now): | ||
| def update_bluetooth(now, once = False): |
There was a problem hiding this comment.
unexpected spaces around keyword / parameter equals
| _LOGGER.exception("Error looking up Bluetooth device") | ||
| track_point_in_utc_time( | ||
| hass, update_bluetooth, dt_util.utcnow() + interval) | ||
| if not once: |
There was a problem hiding this comment.
I would suggest extract line 85-102 to a new function. And call that function from update_bluetooth and handle_update_bluetooth. The you can avoid the once parameter
|
|
||
| update_bluetooth(dt_util.utcnow()) | ||
|
|
||
| hass.services.register(DOMAIN, "bluetooth_update", handle_update_bluetooth) |
There was a problem hiding this comment.
Prefix the service name with the name of the platform, eg like this: 'bluetooth_tracker_update'. I intentionally stripped the name of the second bluetooth.
There was a problem hiding this comment.
Makes sense to me, I updated it to 'bluetooth_tracker_update' in a6d6f76
|
|
||
| update_bluetooth(dt_util.utcnow()) | ||
|
|
||
| hass.services.register(DOMAIN, "bluetooth_tracker_update", handle_update_bluetooth) |
There was a problem hiding this comment.
line too long (87 > 79 characters)
There was a problem hiding this comment.
Fun story: PyCharm for some weird totally non PEP 8 reason has a default gutter of 120, rather than 80. They fooled me!
| hass, update_bluetooth, dt_util.utcnow() + interval) | ||
|
|
||
| update_bluetooth(dt_util.utcnow()) | ||
| def handle_update_bluetooth(call): |
There was a problem hiding this comment.
Why do you need this function?
Why not call update_bluetooth_once directly?
There was a problem hiding this comment.
Certianly could, I just left it using the handle function per a previous comment you said:
I would suggest extract line 85-102 to a new function. And call that function from update_bluetooth and handle_update_bluetooth. The you can avoid the once parameter
I assumed you wanted it left using the handle_update_bluetooth function, to absorb the unused call parameter.
| request_rssi = config.get(CONF_REQUEST_RSSI, False) | ||
|
|
||
| def update_bluetooth(now): | ||
| def update_bluetooth(): |
There was a problem hiding this comment.
I thought the now when calling the function from track_point_in_utc_time ?
There was a problem hiding this comment.
Look at the changeset, track_point_in_utc_time is called with dt_util.utcnow() not with now, I assumed that the unused now was not being used due to the delay introduced by it being called at the end of the function which means that time would be in the past when it was called, which could cause it to just continuously run again after the interval + time it starts, rather than interval+ time it completed.
There was a problem hiding this comment.
This broke the code, argument even not used you still need have it
2018-09-12 16:28:11 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
TypeError: update_bluetooth() takes 0 positional arguments but 1 was given
|
@Danielhiversen any further comments? |
* Add device_tracker.bluetooth_update service Will immediately scan for Bluetooth devices outside of the interval timer. Allows for less frequent scanning, with scanning on demand via automation. * remove excess whitespace per bot comments * Refactored update_bluetooth to call new function update_bluetooth_once * Change service name to bluetooth_tracker_update to reflect platform name * Reformat for line length * Linting fix, pydoc, first line should end with a period * Fixed a method call, and removed some more unsused parameters
* Add device_tracker.bluetooth_update service Will immediately scan for Bluetooth devices outside of the interval timer. Allows for less frequent scanning, with scanning on demand via automation. * remove excess whitespace per bot comments * Refactored update_bluetooth to call new function update_bluetooth_once * Change service name to bluetooth_tracker_update to reflect platform name * Reformat for line length * Linting fix, pydoc, first line should end with a period * Fixed a method call, and removed some more unsused parameters
Will immediately scan for Bluetooth devices outside of the interval timer. Allows for less frequent scanning, with scanning on demand via automation.