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

Add bluetooth integration #74653

Merged
merged 84 commits into from
Jul 8, 2022
Merged

Add bluetooth integration #74653

merged 84 commits into from
Jul 8, 2022

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jul 7, 2022

Proposed change

Bluetooth discovery and scanner callback registration MVP

Note that CPU may be a bit high until we have BluezTestBot/bluez#1132 and home-assistant/plugin-audio#85 is resolved

Jul 24 22:33:49 homeassistant ghcr.io/home-assistant/aarch64-hassio-audio:2022.05.0/hassio_audio[461]: D: [pulseaudio] bluez5-util.c: Properties changed in device /org/bluez/hci0/dev_27_D9_1A_6A_D9_03

For developers

Register callbacks with

from homeassistant.components import bluetooth    

@callback
def _subscriber(service_info: BluetoothServiceInfo, change: BluetoothChange) -> None:
    """Subscribe to bluetooth changes."""
    _LOGGER.warning("Got a change from service_info: %s", service_info)

bluetooth.async_register_callback(hass, _subscriber, None)

See home-assistant/developers.home-assistant#1389 for more

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

homeassistant/components/bluetooth/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/bluetooth/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/bluetooth/models.py Outdated Show resolved Hide resolved
homeassistant/components/bluetooth/models.py Outdated Show resolved Hide resolved
homeassistant/components/bluetooth/models.py Outdated Show resolved Hide resolved
homeassistant/components/bluetooth/models.py Outdated Show resolved Hide resolved
homeassistant/components/bluetooth/models.py Outdated Show resolved Hide resolved
@bdraco
Copy link
Member Author

bdraco commented Jul 8, 2022

---------- coverage: platform linux, python 3.9.10-final-0 -----------
Name                                             Stmts   Miss  Cover   Missing
------------------------------------------------------------------------------
homeassistant/components/bluetooth/__init__.py     146      0   100%
homeassistant/components/bluetooth/const.py          1      0   100%
homeassistant/components/bluetooth/models.py        72      0   100%
homeassistant/components/bluetooth/usage.py          7      0   100%
------------------------------------------------------------------------------
TOTAL                                              226      0   100%

@bdraco
Copy link
Member Author

bdraco commented Jul 8, 2022

I guess we need some docs now

@bdraco
Copy link
Member Author

bdraco commented Jul 8, 2022

I need to add some loader tests as well

@bdraco bdraco marked this pull request as ready for review July 8, 2022 23:14
@bdraco bdraco requested review from Danielhiversen and a team as code owners July 8, 2022 23:14
@bdraco bdraco merged commit a697672 into home-assistant:dev Jul 8, 2022
@bdraco bdraco deleted the bt branch July 8, 2022 23:55
@elupus
Copy link
Contributor

elupus commented Jul 9, 2022

Fjäråskupan currently need to get duplicate data in announces. Its used to keep track of availability. Didnt look like that was enabled here?

@elupus
Copy link
Contributor

elupus commented Jul 9, 2022

scanner = BleakScanner(filters={"DuplicateData": True})

@bdraco
Copy link
Member Author

bdraco commented Jul 9, 2022

Fjäråskupan currently need to get duplicate data in announces. Its used to keep track of availability. Didnt look like that was enabled here?

Is there a way around that? We really don't want to enable that on the main scanner as it will significantly increase the number of messages we need to process.

We are avoiding allowing multiple scanners because of
hbldh/bleak#500

@elupus
Copy link
Contributor

elupus commented Jul 9, 2022

Well, we need to keep track of if the device is still available. We dont want to poll it, since it crashes easily.

I dont think bleak exposes lost devices while scanning. It probably could with bluez backend, not sure with others.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 10, 2022
@frenck frenck added the noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed has-tests integration: bluetooth new-integration noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants