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 WebSocket API to subscribe to connection allocations #136215

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jan 22, 2025

frontend home-assistant/frontend#23899

Proposed change

Add Bluetooth WebSocket API to subscribe to connection allocations

Frontend testing

$0.hass.connection.subscribeMessage(function(msg) { console.log(msg); }, {"type":"bluetooth/subscribe_connection_allocations"});

Optionally a bluetooth adapter source can be specified (mac address of the adapter -- this is always the unique id of the config entry)

$0.hass.connection.subscribeMessage(function(msg) { console.log(msg); }, {"type":"bluetooth/subscribe_connection_allocations", source:"AA:BB:CC:DD:EE:FF"});

API Samples

After calling bluetooth/subscribe_connection_allocations

{'id': 43, 'result': None, 'success': True, 'type': 'result'}

Next all the current allocations are sent:

[{"id":43,"type":"result","success":true,"result":null},{"id":43,"type":"event","event":[{"source":"A0:A3:B3:8C:6D:BC","slots":3,"free":3,"allocated":[]},{"source":"B0:B2:1C:7C:62:58","slots":3,"free":3,"allocated":[]},{"source":"08:3A:8D:B3:75:A4","slots":3,"free":3,"allocated":[]},{"source":"24:4C:AB:03:63:A0","slots":3,"free":3,"allocated":[]},{"source":"24:4C:AB:03:0B:6C","slots":3,"free":3,"allocated":[]},{"source":"00:1A:7D:DA:71:14","slots":5,"free":5,"allocated":[]}]}]

As connections change, a new event is sent.

{"id":43,"type":"event","event":[{"source":"B0:B2:1C:7C:62:58","slots":3,"free":2,"allocated":["AA:BB:CC:DD:EE:FF"]]}]}

Note that not all adapters will return the allocated list yet.

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format 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.

To help with the load of incoming pull requests:

@bdraco
Copy link
Member Author

bdraco commented Jan 22, 2025

habluetooth API seems to be ok now.

Need to write some tests and do some functional testing

@bdraco
Copy link
Member Author

bdraco commented Jan 22, 2025

esphome is too frequent at the callbacks. We need to filter dupes
fixed in #136277

@bdraco bdraco marked this pull request as ready for review January 22, 2025 21:59
@bdraco bdraco marked this pull request as draft January 24, 2025 20:55
@bdraco
Copy link
Member Author

bdraco commented Jan 25, 2025

after thinking about it a bit its pretty easy to get the source address with const configEntries = await getConfigEntries(this.hass, { domain: "bluetooth", }); in the frontend and everything is going to come back with the source so better to leave it as source as the param

@bdraco bdraco marked this pull request as ready for review January 25, 2025 02:52
@bdraco bdraco marked this pull request as draft January 26, 2025 19:43
@bdraco
Copy link
Member Author

bdraco commented Jan 26, 2025

so we are going to need the config entry id since we can't get the unique id via an api right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant