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

Include Bluetooth connection slot allocations in connections free message #1038

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jan 27, 2025

Breaking change

The signature for the on_bluetooth_connections_free_update callback for subscribe_bluetooth_connections_free has changed from Callable[[int, int], None] to Callable[[int, int, list[int]], None] which now includes a list of addresses allocated for connections.

ESPHome esphome/esphome#8148
bleak-esphome Bluetooth-Devices/bleak-esphome#74
aioesphomeapi #1038

@bdraco bdraco added major waiting-for-esphome Indicates the PR is waiting for the esphome main repo code approval labels Jan 27, 2025
Copy link

codspeed-hq bot commented Jan 27, 2025

CodSpeed Performance Report

Merging #1038 will not alter performance

Comparing allocated (756eeba) with main (13c71fc)

Summary

✅ 2 untouched benchmarks

Copy link

codecov bot commented Jan 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (13c71fc) to head (756eeba).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1038   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         2681      2681           
=========================================
  Hits          2681      2681           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bdraco
Copy link
Member Author

bdraco commented Jan 27, 2025

Looks like it works as expected

2025-01-27 10:54:21.841 DEBUG (MainThread) [bleak_esphome.backend.device] poolhouse81proxy [24:4C:AB:06:49:9C]: BLE connection limits: used=0 free=3 limit=3 allocated=[]
2025-01-27 10:54:21.977 DEBUG (MainThread) [aioesphomeapi.connection] poolhouse81proxy @ 192.168.107.3: Got message of type BluetoothLERawAdvertisementsResponse: advertisements {
  address: 9049263188209
  rssi: -73
--
allocated: 268695158259384

2025-01-27 10:54:25.777 DEBUG (MainThread) [bleak_esphome.backend.device] poolhouse81proxy [24:4C:AB:06:49:9C]: BLE connection limits: used=1 free=2 limit=3 allocated=[268695158259384]
2025-01-27 10:54:26.833 DEBUG (MainThread) [aioesphomeapi.connection] poolhouse81proxy @ 192.168.107.3: Got message of type BluetoothLERawAdvertisementsResponse: advertisements {
  address: 93488828207994
  rssi: -75
--
allocated: 268695158259384

2025-01-27 10:54:26.857 DEBUG (MainThread) [bleak_esphome.backend.device] poolhouse81proxy [24:4C:AB:06:49:9C]: BLE connection limits: used=1 free=2 limit=3 allocated=[268695158259384]
2025-01-27 10:54:26.861 DEBUG (MainThread) [aioesphomeapi.connection] poolhouse81proxy @ 192.168.107.3: Got message of type BluetoothLERawAdvertisementsResponse: advertisements {
  address: 275030875981126
  rssi: -76
--
2025-01-27 10:54:27.445 DEBUG (MainThread) [bleak_esphome.backend.device] poolhouse81proxy [24:4C:AB:06:49:9C]: BLE connection limits: used=0 free=3 limit=3 allocated=[]
2025-01-27 10:54:27.459 WARNING (MainThread) [homeassistant.bootstrap] Timings: {
  "air_quality": {
    "null": {
--
allocated: 194519040712068

2025-01-27 10:54:56.602 DEBUG (MainThread) [bleak_esphome.backend.device] poolhouse81proxy [24:4C:AB:06:49:9C]: BLE connection limits: used=1 free=2 limit=3 allocated=[194519040712068]
2025-01-27 10:54:56.615 DEBUG (MainThread) [aioesphomeapi.connection] poolhouse81proxy @ 192.168.107.3: Got message of type BluetoothLERawAdvertisementsResponse: advertisements {
  address: 244579075710878
  rssi: -50
--
allocated: 194519040712068

2025-01-27 10:55:04.733 DEBUG (MainThread) [bleak_esphome.backend.device] poolhouse81proxy [24:4C:AB:06:49:9C]: BLE connection limits: used=1 free=2 limit=3 allocated=[194519040712068]
2025-01-27 10:55:04.737 DEBUG (MainThread) [aioesphomeapi.connection] poolhouse81proxy @ 192.168.107.3: Got message of type BluetoothLERawAdvertisementsResponse: advertisements {
  address: 9049263188209
  rssi: -77

@bdraco bdraco marked this pull request as ready for review January 27, 2025 20:57
Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

Walkthrough

This pull request introduces an enhancement to the Bluetooth connection management in the aioesphomeapi library. A new field allocated is added to the BluetoothConnectionsFreeResponse message in the protocol buffer definition. Correspondingly, the client-side code is updated to support this new field, including modifications to method signatures in client.py and client_callbacks.py, and updates to the associated test case to validate the new functionality.

Changes

File Change Summary
aioesphomeapi/api.proto Added repeated uint64 allocated = 3; to BluetoothConnectionsFreeResponse message
aioesphomeapi/client.py Updated subscribe_bluetooth_connections_free method signature to accept a callback with three arguments (two integers and a list of integers)
aioesphomeapi/client_callbacks.py Modified on_bluetooth_connections_free_response to pass list(msg.allocated) to the callback
tests/test_client.py Updated test function on_bluetooth_connections_free to accept an additional allocated parameter and modified test response to include allocated connections

Sequence Diagram

sequenceDiagram
    participant Client
    participant APIClient
    participant ESPHomeDevice
    
    Client->>APIClient: subscribe_bluetooth_connections_free()
    APIClient->>ESPHomeDevice: Request Bluetooth Connections Status
    ESPHomeDevice-->>APIClient: BluetoothConnectionsFreeResponse
    APIClient->>Client: Callback with free, limit, and allocated connections
Loading

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13c71fc and 756eeba.

📒 Files selected for processing (4)
  • aioesphomeapi/api.proto (1 hunks)
  • aioesphomeapi/client.py (1 hunks)
  • aioesphomeapi/client_callbacks.py (1 hunks)
  • tests/test_client.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
aioesphomeapi/api.proto (1)

Pattern **: - Do not generate or add any sequence diagrams

aioesphomeapi/client_callbacks.py (1)

Pattern **: - Do not generate or add any sequence diagrams

aioesphomeapi/client.py (1)

Pattern **: - Do not generate or add any sequence diagrams

tests/test_client.py (1)

Pattern **: - Do not generate or add any sequence diagrams

🪛 GitHub Actions: CI
tests/test_client.py

[warning] Unraisable Exception in AsyncEngine._async_setup during test_request_while_handshaking

🔇 Additional comments (4)
aioesphomeapi/client_callbacks.py (1)

74-77: LGTM! Clean implementation of the Bluetooth connections free response handler.

The function correctly forwards all fields from the message to the callback, including the new allocated list.

aioesphomeapi/client.py (1)

Line range hint 524-529: LGTM! Clean implementation of the Bluetooth connections free subscription.

The function correctly sets up the subscription with the updated callback type that includes the allocated connections list.

tests/test_client.py (1)

1861-1873: LGTM! Comprehensive test coverage for Bluetooth connections free subscription.

The test correctly verifies that the allocated connections list is passed through from the response to the callback.

🧰 Tools
🪛 GitHub Actions: CI

[warning] Unraisable Exception in AsyncEngine._async_setup during test_request_while_handshaking

aioesphomeapi/api.proto (1)

1407-1407: LGTM! Clean addition of allocated connections field.

The new repeated uint64 field is appropriately defined and maintains backwards compatibility.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@bdraco bdraco removed the waiting-for-esphome Indicates the PR is waiting for the esphome main repo code approval label Jan 28, 2025
@bdraco bdraco merged commit a775831 into main Jan 28, 2025
18 checks passed
@bdraco bdraco deleted the allocated branch January 28, 2025 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant