Repository navigation
Show an unknown cover position as unknown, not -155 - #1049
zigpy-review-bot wants to merge 2 commits into
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
left a comment
There was a problem hiding this comment.
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
Nonefromis_closedas an unknown state (CoverEntity.state).
Summary
Severity: medium (the audit's estimate)
A window covering that doesn't know its position reports
CurrentPositionLiftPercentage/CurrentPositionTiltPercentageas 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 with100 - valueto 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 returnsNonefor a missing value or one outside 0–100.current_cover_positionandcurrent_cover_tilt_positionuse it.async_set_cover_position/async_set_cover_tilt_position: no longerassertthat 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
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 withassert -155 is Noneand passes with the fix.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_statechange 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