Return None for Velux cover position when unknown#168566
Conversation
When the KLF200 reports an unknown raw position (0xF7FF), pyvlx's Position.position_percent returns 124, which was then inverted by the Velux cover entity to -24 via ``100 - position_percent``. Guard the cover position, closed state and blind tilt position with ``Position.known`` so the entity reports ``unknown`` instead of an invalid negative percentage.
|
Hey there @Julius2342, @pawlizio, @wollew, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR fixes Velux cover/blind entities to report unknown (None) positions/states when the underlying pyvlx Position/orientation is unknown, preventing invalid (negative) percentages from propagating into Home Assistant.
Changes:
- Guard
current_cover_positionandis_closedbehindPosition.knownfor Velux covers (including dual roller shutter parts). - Guard blind
current_cover_tilt_positionbehindorientation.known. - Add tests and update test fixtures to include
knownon mocked position/orientation objects.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| homeassistant/components/velux/cover.py | Returns None for cover position/closed/tilt when pyvlx reports unknown, avoiding invalid percentages. |
| tests/components/velux/conftest.py | Extends mocked position/orientation objects with a known attribute to support the new logic. |
| tests/components/velux/test_cover.py | Adds regression tests asserting unknown state/attributes when position or tilt is unknown. |
wollew
left a comment
There was a problem hiding this comment.
Thanks for the PR, this totally makes sense.
| @property | ||
| def current_cover_position(self) -> int: | ||
| """Return the current position of the cover.""" | ||
| def _active_position(self) -> Position: |
There was a problem hiding this comment.
I think something like _part_position would be a better name for this, _active to me sounds like something that is only valid then the cover is moving.
- Rename _active_position to _part_position (suggested by @wollew); "active" implied the cover was moving, which isn't the intent. - Parametrize the dual roller shutter unknown-position test so each part is flipped to unknown independently, verifying the other two parts keep their known position.
Proposed change
When the KLF200 gateway reports an unknown raw position (
0xF7FF),pyvlx's
Position.position_percentreturns124. The Velux coverentity then inverted this via
100 - position_percent, producing-24ascurrent_position— an invalid percentage that breakstemplate covers, dashboards and downstream automations.
This PR guards the cover position, closed state and blind tilt
position with
Position.known/orientation.known, so the entityreports
unknowninstead of a nonsensical negative percentage. Thefix covers:
VeluxCover(windows, awnings, gates, garage doors, roller shutters)VeluxDualRollerShutter(upper / lower / dual parts, via a new_active_positionhelper)VeluxBlind(tilt position)Reproducible on real hardware: a Velux KLF200 with a garage door and a
courtyard gate occasionally emits unknown-position states mid-movement,
resulting in
current_position=-24in Home Assistant.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: