Skip to content

Fix BLEConnection AttributeError on disconnect handler setup#4

Merged
rgregg merged 3 commits intomainfrom
copilot/fix-debian-ble-connection-error
Jan 17, 2026
Merged

Fix BLEConnection AttributeError on disconnect handler setup#4
rgregg merged 3 commits intomainfrom
copilot/fix-debian-ble-connection-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 16, 2026

The proxy crashes on BLE connection with 'BLEConnection' object has no attribute 'set_disconnect_handler'. The code attempted to call a non-existent method - meshcore's BLEConnection and SerialConnection only expose set_disconnect_callback().

Changes:

  • Removed fallback logic attempting set_disconnect_handler()
  • Direct call to set_disconnect_callback() for both connection types
  • Updated test mock to match actual meshcore API
# Before: tried non-existent method first
disconnect_setter = getattr(self._radio_connection, "set_disconnect_handler", None)
if callable(disconnect_setter):
    disconnect_setter(self._handle_radio_disconnect)
else:
    callback_setter = getattr(self._radio_connection, "set_disconnect_callback", None)
    # ... fallback logic

# After: use actual API directly
self._radio_connection.set_disconnect_callback(self._handle_radio_disconnect)
Original prompt

This section details on the original issue you should resolve

<issue_title>Error on Debian with BLE</issue_title>
<issue_description>ERROR:meshcore_proxy.proxy:Failed to connect to radio: 'BLEConnection' object has no attribute 'set_disconnect_handler'. Retrying in 5s...</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix BLE connection error on Debian platform Fix BLEConnection AttributeError on disconnect handler setup Jan 16, 2026
Copilot AI requested a review from rgregg January 16, 2026 19:45
@rgregg
Copy link
Copy Markdown
Owner

rgregg commented Jan 16, 2026

@copilot is this something different about linux vs. mac? It seems like the other code worked fine on a Mac. Do we need to special case this based on platform?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 16, 2026

@copilot is this something different about linux vs. mac? It seems like the other code worked fine on a Mac. Do we need to special case this based on platform?

No, this is not platform-specific. The meshcore library (v2.2.5) uses set_disconnect_callback() on both Mac and Linux - there's no platform-specific code in the library.

The original code had fallback logic that should have worked on both platforms:

disconnect_setter = getattr(connection, "set_disconnect_handler", None)
if callable(disconnect_setter):  # Would be False with real BLEConnection
    disconnect_setter(handler)
else:
    callback_setter = getattr(connection, "set_disconnect_callback", None)
    callback_setter(handler)  # Would execute with real BLEConnection

However, the test mock incorrectly used set_disconnect_handler() instead of set_disconnect_callback(), which hid the fact that the real meshcore API is different. Tests passed because they hit the first branch, but production code (on any platform) would use the second branch.

The fix removes the unnecessary fallback and uses the actual meshcore API directly. No platform-specific code needed. (c16b656)

@rgregg rgregg marked this pull request as ready for review January 17, 2026 03:35
Copilot AI review requested due to automatic review settings January 17, 2026 03:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug where the proxy crashes on BLE connection due to attempting to call a non-existent method. The code incorrectly tried set_disconnect_handler() first with a fallback to set_disconnect_callback(), but meshcore's BLEConnection and SerialConnection only expose set_disconnect_callback().

Changes:

  • Removed fallback logic attempting the non-existent set_disconnect_handler() method
  • Direct call to set_disconnect_callback() for both connection types
  • Updated test mock to match actual meshcore API

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/meshcore_proxy/proxy.py Simplified disconnect callback setup by directly calling the correct API method
tests/test_proxy.py Updated MockRadio to use set_disconnect_callback instead of set_disconnect_handler

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rgregg rgregg merged commit 1190507 into main Jan 17, 2026
13 checks passed
@rgregg rgregg deleted the copilot/fix-debian-ble-connection-error branch January 17, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error on Debian with BLE

3 participants