Skip to content

Show an unknown cover position as unknown, not -155 - #1049

Open
zigpy-review-bot wants to merge 2 commits into
devfrom
zigpy-bot/audit/show-unknown-cover-position-as-unknown
Open

zigpy-review-bot wants to merge 2 commits into
devfrom
zigpy-bot/audit/show-unknown-cover-position-as-unknown

Conversation

@zigpy-review-bot

@zigpy-review-bot zigpy-review-bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Severity: medium (the audit's estimate)

A window covering that doesn't know its position reports CurrentPositionLiftPercentage / CurrentPositionTiltPercentage as 0xFF, the attributes' default (ZCL R8 Table 7-40, range 0–100); Zigbee2MQTT notes that the ubisys J1 reports 255 when it doesn't know its lift or tilt position. ZHA converted that with 100 - value to a position of -155 % and showed the cover as closed. This treats a percentage outside 0–100 as an unknown position.

Changes

  • Cover._zcl_percentage_to_ha_position: converts a ZCL percentage to the HA scale and returns None for a missing value or one outside 0–100. current_cover_position and current_cover_tilt_position use it.
  • async_set_cover_position / async_set_cover_tilt_position: no longer assert that the current position is known. The command is sent either way, and the opening/closing state is set only when the current position is known (the direction can't be derived otherwise).
  • _determine_cover_state: an axis whose position is unknown keeps a running transition (target and timer) until its timer runs out, instead of dropping it on the next state recompute. Without this, a tilt report on a lift-and-tilt cover cleared the lift target of a set-position command sent while the lift position was unknown, and the first known lift position showed a static state instead of the direction towards the target. A known, non-moving state still clears the transition as before, and so does a recompute that still finds the position unknown with no timer running (a command that raised leaves a target without one).

Testing

  • New test_cover_unknown_position: a lift-and-tilt cover joined with both percentages at 0xFF shows both positions and its state as unknown, shows a later real position, goes back to unknown on another 0xFF report, and still sends Go To Lift / Tilt Percentage with an unknown position. It fails at dev with assert -155 is None and passes with the fix.
  • New test_cover_unknown_position_keeps_transition: with the lift position unknown, a set-position command keeps its target across a tilt report, the first known lift position shows opening, the target position shows open, without a report the transition ends with its timer, and the target of a command that raised is dropped on the next report that leaves the lift position unknown. It fails without the _determine_cover_state change and passes with it.
  • tests/test_cover.py: 24 passed. Full suite: 1783 passed. pre-commit (codespell, ruff, ruff format, mypy) passes on the changed files.

Opened by the scheduled code audit; not requested by a maintainer.

Fixes #1048

CurrentPositionLiftPercentage and CurrentPositionTiltPercentage are
0-100, with 0xFF as their default (ZCL R8 Table 7-40): a cover that
doesn't know its position reports 255 (Zigbee2MQTT notes this for the
ubisys J1). ZHA converted that to 100 - 255 = -155 and showed the
cover as closed at -155 %.

Treat a percentage outside 0-100 as an unknown position (None), and
let set position / set tilt position send their command when the
current position is unknown instead of failing an assert.
@zigpy-review-bot zigpy-review-bot added bot: code audit Found by the bot's scheduled code audit bot: unrequested PR PR: opened by the bot's issue triage, not requested by a maintainer bugfix This PR fixes a bug bot-watch: fix zigpy-review-bot follows this thread and also pushes fixes (review + fix) labels Nov 21, 2026
@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (2da1a5b) to head (ff8a5af).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1049   +/-   ##
=======================================
  Coverage   97.48%   97.48%           
=======================================
  Files          61       61           
  Lines       10870    10871    +1     
=======================================
+ Hits        10597    10598    +1     
  Misses        273      273           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

A set-position command sent while the lift (or tilt) position is
unknown leaves that axis's state at None. Any later recompute, such as
a tilt report on a lift-and-tilt cover, treated that None as "not
moving" and cleared the transition target and timer, so the first
known position report showed a static state instead of the direction
towards the target.

Keep a running transition on an axis whose state is unknown until its
timer runs out. A known non-moving state still clears it, and so does
any recompute when no timer runs (a command that raised leaves a target
without one).

@zigpy-review-bot zigpy-review-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Second look at this PR: one gap found and fixed in ff8a5af, nothing else open. A set-position command sent while the lift position is unknown lost its target when a tilt report arrived (on a lift-and-tilt cover) before the first lift report, so the cover then showed open instead of opening. An axis with an unknown position now keeps a running transition until its timer runs out; a target left without a timer (the command raised) is still dropped on the next update that leaves the position unknown. A new test covers both.

The PR body was updated to match.

Verified (5 checks)
  • The scenario was reproduced at a754647 (target and timer cleared by the tilt report, then a static open on the first lift report); the new test fails there and passes with the fix, and its raised-command part fails if an unknown axis keeps a target with no timer running.
  • tests/test_cover.py: 24 passed; full suite: 1783 passed; pre-commit (codespell, ruff, ruff format, mypy) passes on the changed files.
  • Probed further cases: an 0xFF report in the middle of a known transition, set position from an unknown position followed by intermediate reports, open with an unknown position, and a command on an axis the cover doesn't have. None raises, an unknown position stays unknown, a real report recovers the state, and every kept transition ends with its timer.
  • ZCL R8 Table 7-40 (range 0–100, default 0xFF) and the Zigbee2MQTT ubisys J1 note in the body checked against the spec and the converter source.
  • Home Assistant shows a None from is_closed as an unknown state (CoverEntity.state).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: code audit Found by the bot's scheduled code audit bot: unrequested PR PR: opened by the bot's issue triage, not requested by a maintainer bot-watch: fix zigpy-review-bot follows this thread and also pushes fixes (review + fix) bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Covers that don't know their position show -155 % and closed

1 participant