Skip to content

Return None for Velux cover position when unknown#168566

Merged
joostlek merged 3 commits into
home-assistant:devfrom
mnaggatz:fix/velux-unknown-position
Apr 24, 2026
Merged

Return None for Velux cover position when unknown#168566
joostlek merged 3 commits into
home-assistant:devfrom
mnaggatz:fix/velux-unknown-position

Conversation

@mnaggatz
Copy link
Copy Markdown
Contributor

@mnaggatz mnaggatz commented Apr 19, 2026

Proposed change

When the KLF200 gateway reports an unknown raw position (0xF7FF),
pyvlx's Position.position_percent returns 124. The Velux cover
entity then inverted this via 100 - position_percent, producing
-24 as current_position — an invalid percentage that breaks
template covers, dashboards and downstream automations.

This PR guards the cover position, closed state and blind tilt
position with Position.known / orientation.known, so the entity
reports unknown instead of a nonsensical negative percentage. The
fix covers:

  • VeluxCover (windows, awnings, gates, garage doors, roller shutters)
  • VeluxDualRollerShutter (upper / lower / dual parts, via a new
    _active_position helper)
  • 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=-24 in Home Assistant.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

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.
Copilot AI review requested due to automatic review settings April 19, 2026 19:46
@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @Julius2342, @pawlizio, @wollew, mind taking a look at this pull request as it has been labeled with an integration (velux) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of velux can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign velux Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

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 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_position and is_closed behind Position.known for Velux covers (including dual roller shutter parts).
  • Guard blind current_cover_tilt_position behind orientation.known.
  • Add tests and update test fixtures to include known on 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.

Copy link
Copy Markdown
Contributor

@wollew wollew left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, this totally makes sense.

Comment thread homeassistant/components/velux/cover.py Outdated
@property
def current_cover_position(self) -> int:
"""Return the current position of the cover."""
def _active_position(self) -> Position:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@joostlek joostlek marked this pull request as draft April 20, 2026 10:48
- 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.
@mnaggatz mnaggatz marked this pull request as ready for review April 21, 2026 19:31
Copilot AI review requested due to automatic review settings April 21, 2026 19:31
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Contributor

@wollew wollew left a comment

Choose a reason for hiding this comment

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

LGTM now.

@joostlek joostlek merged commit c9d8257 into home-assistant:dev Apr 24, 2026
36 of 37 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants