-
Notifications
You must be signed in to change notification settings - Fork 79
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
fix: pass Bluetooth device info to BleakScanner #238
Conversation
842c6e5
to
8b3385d
Compare
Python 3.7 pipeline does not want to pass, see https://github.com/ttu/ruuvitag-sensor/actions/runs/7906642579/job/21581949199?pr=238. |
Python 3.7 & black causing problems again... Maybe it is time to drop the support for 3.7 in the next major release. ❯ black --version
black, 24.2.0 (compiled: yes)
Python (CPython) 3.11.5
❯ black .
reformatted /Users/ttu/src/github/ruuvitag-sensor/ruuvitag_sensor/ruuvi.py
All done! ✨ 🍰 ✨
1 file reformatted, 42 files left unchanged. ❯ black --version
black, 23.3.0 (compiled: no)
Python (CPython) 3.7.17
❯ black .
All done! ✨ 🍰 ✨
43 files left unchanged. I tried to add to ´pyproject.toml`, but didn't help
I will try to check some proper solution for this or if can't come up with anything I will just disable black for py3.7. |
Black has dropped support for py37 a while ago. Black is now locked to last supported version in #240 |
bb47c62
to
c38c677
Compare
Thanks Tomi! |
c38c677
to
8b955c1
Compare
I agree with dropping Python 3.7 as it is has already dropped from official Python support. Also all major distributions, including Debian, have long since shipped with a version newer than 3.7. |
Locally I got some mymy errors. No idea why I got those errors locally, but on CI everything passed fine.
I added some typing to from typing import AsyncGenerator, List, Literal, Tuple
from bleak import BleakScanner
from bleak.backends.scanner import AdvertisementData, AdvertisementDataCallback, BLEDevice
from ruuvitag_sensor.adapters import BleCommunicationAsync
from ruuvitag_sensor.adapters.utils import rssi_to_hex
from ruuvitag_sensor.ruuvi_types import MacAndRawData, RawData
MAC_REGEX = "[0-9a-f]{2}([:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$"
def _get_scanner(detection_callback: AdvertisementDataCallback, bt_device: str = ""):
# NOTE: On Linux - bleak.exc.BleakError: passive scanning mode requires bluez or_patterns
# NOTE: On macOS - bleak.exc.BleakError: macOS does not support passive scanning
scanning_mode: Literal["active", "passive"] = "passive" if sys.platform.startswith("win") else "active"
if "bleak_dev" in os.environ.get("RUUVI_BLE_ADAPTER", "").lower():
# pylint: disable=import-outside-toplevel
from ruuvitag_sensor.adapters.development.dev_bleak_scanner import DevBleakScanner
return DevBleakScanner(detection_callback, scanning_mode)
additional_arguments = {"adapter": bt_device} if bt_device else {}
return BleakScanner(detection_callback=detection_callback, scanning_mode=scanning_mode, kwargs=additional_arguments)
|
This is quite interesting as now I get the same mypy errors with the code that is in this PR. I cannot understand why this error did not appear to me earlier nor why it is not seen in CI. Unfortunately the code (
but here we have a problem with what to pass as default value which would work on all platforms as Bluetooth device names most likely are not the same on all platforms. |
Yes, you are correct, I didn't think this through as we do not want to pass argument named kwargs, but adapter etc. From the |
8b955c1
to
cdcdd03
Compare
Changed back to the original code but now Pylint on Python 3.7 is not happy. |
bcfee11
to
8247a7d
Compare
I got Pylint to pass on 3.7 by removing the |
Sorry for delay, busy school vacation week. I still go few mypy errors locally. Again no idea why those don't appear during CI. Maybe you could add ❯ mypy ./ruuvitag_sensor
ruuvitag_sensor/adapters/development/dev_bleak_scanner.py:30: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
ruuvitag_sensor/adapters/development/dev_bleak_scanner.py:31: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
ruuvitag_sensor/adapters/bleak_ble.py:30: error: Argument "scanning_mode" to "BleakScanner" has incompatible type "str"; expected "Literal['active', 'passive']" [arg-type]
ruuvitag_sensor/adapters/bleak_ble.py:32: error: Argument "scanning_mode" to "BleakScanner" has incompatible type "str"; expected "Literal['active', 'passive']" [arg-type]
Found 2 errors in 1 file (checked 18 source files) |
This enables the use of non-default Bluetooth device use with the Bleak communication back-end.
8247a7d
to
3588b6b
Compare
Comments added. |
This enables the use of non-default Bluetooth device use with the Bleak communication back-end.
Fixes issue #237.