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

Return calibration points together with map #423

Closed
wants to merge 3 commits into from

Conversation

philek
Copy link
Contributor

@philek philek commented Feb 12, 2024

I would like to take a stab at adding the calibration points to support the Vacuum Map card from this issue:
DeebotUniverse/Deebot-4-Home-Assistant#321

First step is to calculate such points in the client library.

My Python experience is very limited, so let me know if you would like me to refactor it somehow.

@philek philek force-pushed the feature/calibration branch 2 times, most recently from 686e02e to 3d6884d Compare February 13, 2024 17:09
@philek philek force-pushed the feature/calibration branch from 3d6884d to 9e11681 Compare February 13, 2024 17:23
deebot_client/map.py Outdated Show resolved Hide resolved
deebot_client/map.py Outdated Show resolved Hide resolved
deebot_client/map.py Outdated Show resolved Hide resolved
deebot_client/map.py Outdated Show resolved Hide resolved
@@ -597,6 +628,10 @@ def get_svg_map(self) -> str | None:
),
)

# Build the SVG elements
svg_map = svg.SVG(width=manipulation.x.svg_max, height=manipulation.y.svg_max)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is these changed needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the SVG image has no size it makes it difficult (or impossible) for the Vacuum Map card to translate the vacuum coordinates back to the map after the image gets scaled again in the Home Assistant UI.
image

For example in my case the viewport size is 229x237, but Chrome reports the naturalWidth/naturalHeight as 145x150. I believe height is always 150 and width is proportional. Firefox returns 0 for both naturalWidth and naturalHeight. The viewport size is not readily available.
image

However, if we set the width and height explicitly for the SVG then its available as naturalWidth/naturalHeight and the coordinate mapping works correctly.
image

Copy link
Contributor

Choose a reason for hiding this comment

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

We should not set a width or height, as the front end should decide how big it should be drawn.
The problem with setting a width/height on an SVG is that the frontend will use it for showing. For that reason, we use the viewport.
More info about this topic can be found in home-assistant/core#98036 (comment)

We are calculating the calibration points against the viewport and it's the card's job to apply the difference between the viewport and the actual width/height which the card decided to display.

@PiotrMachowski How much work is it to calculate the position of the object according to the viewport if an SVG only has a viewport and no width/height?

Choose a reason for hiding this comment

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

@edenhaus I haven't tried using the map card with SVG yet, I'll have to check it out.

deebot_client/map.py Outdated Show resolved Hide resolved
self._last_image = str(svg_map)
points = tuple(
CalibrationPoint(point, manipulation)
for point in (Point(0, 0), Point(0, 100000), Point(100000, 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need the points at 100000? Can we not use the map width and height as points?
If yes we could remove your changes to _calc_unbounded_point and _calc_point

Copy link

codecov bot commented Feb 19, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (03075a4) 83.19% compared to head (a76299f) 83.21%.
Report is 10 commits behind head on dev.

Files Patch % Lines
deebot_client/map.py 75.75% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #423      +/-   ##
==========================================
+ Coverage   83.19%   83.21%   +0.02%     
==========================================
  Files          71       74       +3     
  Lines        2868     2997     +129     
  Branches      511      535      +24     
==========================================
+ Hits         2386     2494     +108     
- Misses        434      449      +15     
- Partials       48       54       +6     

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

@edenhaus
Copy link
Contributor

Replaced by #433

@edenhaus edenhaus closed this Feb 24, 2024
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