Skip to content

refactor: Migrate BLE device connection and operations to py-opendisplay#35

Open
stuart-c-ai wants to merge 4 commits into
OpenDisplay:mainfrom
stuart-c:migrate-ble-connection
Open

refactor: Migrate BLE device connection and operations to py-opendisplay#35
stuart-c-ai wants to merge 4 commits into
OpenDisplay:mainfrom
stuart-c:migrate-ble-connection

Conversation

@stuart-c-ai
Copy link
Copy Markdown

Stacked PR Dependency

Important

This Pull Request represents Stage 2 of our sequential migration to the new py-opendisplay BLE library. It depends on and includes the changes from Stage 1.

Please ensure that PR #34: refactor: Deprecate ATC (OpenEPaperLink) protocol and simplify entity structure is merged before this PR is reviewed or merged.


Description & Goal

The goal of this stage is to port BLE device connection management and core operational commands to the official py-opendisplay==7.3.0 client library. It replaces our legacy local BLEConnection class and its custom exception handling routines with the library's native OpenDisplayDevice interface and exceptions.

By migrating the connection logic in this isolated stage, we ensure that connection establishment and device commands are fully validated before refactoring the more complex image upload pipelines in subsequent stages.


What was Done & Why

1. Exception Handling Modernization

  • Files: config_flow.py, button.py, services.py, upload.py
  • What: Replaced local custom BLE exceptions (BLEConnectionError, BLETimeoutError, and BLEProtocolError) with their standard py-opendisplay equivalents imported from opendisplay.exceptions:
    • BLEConnectionError
    • BLETimeoutError
    • ProtocolError
  • Why: To align exception mapping with the standard behavior of the client library, ensuring that all component layers handle operational or transmission errors predictably.

2. Connection Block Refactoring

  • Files: config_flow.py, button.py, services.py
  • What: Replaced custom async with BLEConnection(...) context blocks with the library's native async with OpenDisplayDevice(mac_address=...) contexts.
  • Why: Delegates connection lifecycle, BLE transport setup, MTU negotiation, and session tracking directly to the library client.

3. Device Interrogation & Configuration Refresh

  • Files: config_flow.py, button.py
  • What: Integrated conn.interrogate() and conn.read_firmware_version() into the setup and configuration refresh flows. This queries capabilities and system settings directly from the display and parses them into standard model fields.
  • Why: Replaces custom TLV parsing commands with standard library calls, maximizing parsing stability and firmware version accuracy.

4. Core Operational Commands Porting

  • Files: services.py, button.py
  • What: Swapped out custom direct-write bytes for native library commands:
    • LED activation uses conn.activate_led()
    • Tag rebooting uses conn.reboot()
  • Why: Eliminates manual byte construction for device actions, improving readability and maintainability of the service and button entities.

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.

2 participants