Skip to content

Add per-map rotation support with select entity and calibrated overlays#37

Merged
Lash-L merged 7 commits intoLash-L:mainfrom
TheHangMan97:main
Apr 17, 2026
Merged

Add per-map rotation support with select entity and calibrated overlays#37
Lash-L merged 7 commits intoLash-L:mainfrom
TheHangMan97:main

Conversation

@TheHangMan97
Copy link
Copy Markdown
Contributor

Overview

This PR adds per-map rotation support to the Roborock Custom Map integration.

Instead of handling rotation in the frontend, this implementation introduces a
dedicated Select entity per map that allows users to rotate the map image
directly within Home Assistant.

What’s new

  • Per-map rotation via Select entity (0°, 90°, 180°, 270°)
  • Live updates (no reload required)
  • Rotation persisted across restarts
  • Image rotation handled in executor (non-blocking)
  • Calibration points rotated together with the image
  • Rooms/zones remain correctly aligned after rotation
  • English and German translations included

Why this approach

Frontend-only rotation (CSS/card-mod) rotates only the rendered pixels and
does not adjust calibration or interaction coordinates.

This implementation rotates:

  • the image bytes
  • the calibration map coordinates

so overlays and interactions (rooms, zones, taps) stay aligned.

Technical details

  • Rotation stored in hass.data per map_flag
  • Select entity uses RestoreEntity for persistence
  • Dispatcher signal triggers image cache bust on rotation change
  • PNG dimensions extracted directly from header for efficient calibration adjustment
  • Image processing offloaded via async_add_executor_job

Backwards compatibility

  • Default behavior unchanged (no rotation = 0°)
  • Existing entities unaffected
  • Rotation is optional and disabled by default

Tested with

  • Xiaomi Vacuum Map Card
  • Multiple maps (per floor)
  • Calibration overlays
  • Room and zone interactions

Introduce rotation configuration constants for map image handling.
Adds rotation options (0, 90, 180, 270) and dispatcher signal name.
Add SelectEntity to control map rotation per map_flag.
Rotation value is persisted via RestoreEntity and stored in hass.data.
Dispatcher signal notifies image entities when rotation changes.
Register SELECT platform and initialize rotation storage in hass.data.
Add proper unload cleanup and reload behavior.
Implement backend image rotation using Pillow.
Rotation is applied in async_add_executor_job to avoid blocking the event loop.
Includes defensive validation and fallback handling.
Add English and German translations for map rotation select entity.
Includes user-friendly labels for rotation options.
Add documentation for the per-map rotation select entity.

Explains:
- How to rotate maps (0/90/180/270)
- Where to find the rotation select entity
- That calibration points are rotated as well
- That no reload is required

Also clarifies usage with Xiaomi Vacuum Map Card.
@Lash-L
Copy link
Copy Markdown
Owner

Lash-L commented Mar 19, 2026

Sorry for the delay! I will give this a try and review (hopefully) tomorrow

hansherlighed added a commit to hansherlighed/RoborockCustomMap that referenced this pull request Apr 7, 2026
@Lash-L Lash-L requested review from Lash-L and Copilot April 17, 2026 00:26
@Lash-L
Copy link
Copy Markdown
Owner

Lash-L commented Apr 17, 2026

Sorry.... Tomorrow != One month later. Looking at this right now. code looks fine from what i can see, i'll see if copilot finds anything. Testing out on my instance now.

Copy link
Copy Markdown
Contributor

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 adds per-map rotation support to the Roborock Custom Map integration by introducing a per-map Select entity that controls image rotation and applies the same rotation to calibration points so map overlays/interactions remain aligned.

Changes:

  • Add a Select entity per map to choose rotation (0/90/180/270) and persist it across restarts.
  • Rotate map PNG bytes in an executor thread and rotate calibration “map” points accordingly.
  • Add English/German translations and document usage in the README.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
custom_components/roborock_custom_map/translations/en.json Adds Select entity name/state translations for rotation.
custom_components/roborock_custom_map/translations/de.json Adds German translations for the rotation Select entity.
custom_components/roborock_custom_map/select.py Introduces per-map rotation Select entity with restore support and dispatcher signaling.
custom_components/roborock_custom_map/image.py Applies rotation to served PNG bytes and rotates calibration points to match.
custom_components/roborock_custom_map/const.py Adds constants for rotation options and dispatcher signal name.
custom_components/roborock_custom_map/init.py Registers SELECT platform and stores per-entry rotation state in hass.data.
README.md Documents new map rotation feature and how to use it.

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

Comment thread custom_components/roborock_custom_map/select.py
Comment thread custom_components/roborock_custom_map/select.py
Comment thread custom_components/roborock_custom_map/image.py
Comment thread custom_components/roborock_custom_map/image.py
Comment thread custom_components/roborock_custom_map/__init__.py Outdated
Comment thread README.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Lash-L Lash-L merged commit 0531b6d into Lash-L:main Apr 17, 2026
1 of 2 checks passed
@Lash-L
Copy link
Copy Markdown
Owner

Lash-L commented Apr 17, 2026

Thankss @TheHangMan97! So sorry for the delay, but this is very much appreciated!

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