Skip to content

refactor: Port image upload pipelines to py-opendisplay client#36

Open
stuart-c-ai wants to merge 5 commits into
OpenDisplay:mainfrom
stuart-c:migrate-image-uploads
Open

refactor: Port image upload pipelines to py-opendisplay client#36
stuart-c-ai wants to merge 5 commits into
OpenDisplay:mainfrom
stuart-c:migrate-image-uploads

Conversation

@stuart-c-ai
Copy link
Copy Markdown

Stacked PR Dependency

Important

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

Please ensure that PR #35: refactor: Migrate BLE device connection and operations to py-opendisplay is merged before this PR is reviewed or merged.


Description & Goal

The goal of this stage is to port the image upload pipelines in upload.py to the official py-opendisplay==7.3.0 client library. It replaces custom image encoding, dithering, zlib compression, and our legacy local BLEImageUploader class with the library's native OpenDisplayDevice.upload_image() capabilities.

By porting the upload logic to the library, we delegate the complex MTU-bound packet splitting, direct-write protocol sequence, compression checks, and color plane mapping directly to the client library. This dramatically reduces the complexity of our local custom component while guaranteeing exact compatibility with all display modes.


What was Done & Why

1. Direct Library Upload Delegation

  • File: custom_components/opendisplay/upload.py
  • What: Rewrote upload_to_ble_block and upload_to_ble_direct to instantiate OpenDisplayDevice, perform an initial conn.interrogate(), and call conn.upload_image() to transmit the payload.
  • Why: The library handles all low-level direct-write protocols, start packets, and end confirmations natively.

2. Dithering & Refresh Mode Mapping

  • File: custom_components/opendisplay/upload.py
  • What: Mapped local integer-based dithering parameters (0, 1, 2) to opendisplay.DitherMode and local refresh type configurations to opendisplay.RefreshMode.
  • Why: Ensures display modes and dithering algorithms are correctly parsed and mapped to the standard library enums before upload.

3. Cleanup of Obsolete Helper Instantiations

  • File: custom_components/opendisplay/upload.py
  • What: Eliminated the instantiation of the local BLEImageUploader class, obsolete metadata wrappers (BLEDeviceMetadata), and unnecessary BLE helper imports.
  • Why: The library natively manages device dimension verification, color plane conversion (including monochrome, dual-plane BWR/BWY, 2BPP BWRY/grayscale, or 4BPP 6-color), and serpentine layout corrections, making custom upload wrappers obsolete.

4. Home Assistant Tag Preview Maintenance

  • File: custom_components/opendisplay/upload.py
  • What: Retained the asynchronous dispatcher notification SIGNAL_TAG_IMAGE_UPDATE to broadcast the dithered processed image (returned by conn.upload_image()) back to Home Assistant's tag image preview.
  • Why: Ensures users still receive immediate visual confirmation of the uploaded dithered image on their dashboard tag preview.

@Misiu
Copy link
Copy Markdown
Contributor

Misiu commented May 25, 2026

What about the support for deep sleep devices?
I tried adding support for upload queue to HA Core integration - home-assistant/core@dev...Misiu:home-assistant:deep_sleep
I think it would be wise to add it also to custom integration, because then we could finally use ESP32-based devices with a battery.

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.

3 participants