Repository navigation
Take the thermostat preset from the attribute cache on startup - #1043
Draft
zigpy-review-bot wants to merge 1 commit into
Draft
zigpy-review-bot wants to merge 1 commit into
zigpy-review-bot wants to merge 1 commit into
Conversation
The Moes, Beca and ZONNSMART thermostat entities only learned their preset from an operation_preset attribute event and started at "none". After a restart, zigpy restores operation_preset from its database before the entity is built, but no event fires, so the entity showed "none" until the device reported the attribute again. While in away, the target temperature was read from and written to the occupied setpoint, and selecting "none" wrote nothing, so the device stayed in its preset. Map operation_preset values to presets in one table per class, used both for attribute events and to set the initial preset from the cache.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1043 +/- ##
==========================================
+ Coverage 97.48% 97.49% +0.01%
==========================================
Files 61 61
Lines 10870 10835 -35
==========================================
- Hits 10597 10564 -33
+ Misses 273 271 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
zigpy-review-bot
left a comment
Collaborator
Author
There was a problem hiding this comment.
No findings in this PR's own code. One open item concerns how it fits with two other open PRs. (This is a COMMENT on the bot's own PR; the would-be verdict is ready.)
Open items
- The quirks-side replacement has the same startup gap. #996 removes
MoesThermostatandZONNSMARTThermostatin favour of the quirk entities from zigpy/zha-device-handlers#5624. That PR'sOperationPresetThermostatsets_presetonly inhandle_attribute_updated(from_value_presets), so once #996 lands, these TRVs will shownoneafter a restart again. zigpy/zha-device-handlers#5624 needs the same startup read. It subclasses ZHA'sThermostat, so it could name its table_operation_presetsand inherit the read added here, once the quirks require a ZHA release that has it. Otherwise it can read the cache in its own__init__. That follow-up belongs to zigpy/zha-device-handlers#5624, not to this PR. - Overlap with #906. That PR deletes
BecaThermostatbecause its presets don't work on the_TZE200_b6wax7g0TRV, and this PR changes that class. Whichever merges second drops or rebases the Beca part. Which way Beca goes is the maintainers' call.
The tables carry the same values as the event mapping they replace, so this needs no device test beyond what that mapping already assumed. Taking the PR out of draft is a maintainer's call.
Verified (7 checks)
- The three tables match the removed
ifchains value for value (on ZONNSMART, 2 and 3 both map to holiday and 4 to frost protect). On events, a value outside a table leaves the preset unchanged, as before. At startup it givesnone. - zigpy 2.4.1's
appdbrestores the attribute cache with_attr_cache.set_value(...)directly and fires no event, which is the cause the body names. Cluster.get("operation_preset")returnsNonefor an uncached or unsupported attribute, so the preset then starts atnone. The quirks typeoperation_presetas anenum8, whose members hash as their int value (checked against the installed zha-quirks 2.4.1), so the int-keyed tables match both the restored value and event values.- No other
Thermostatsubclass overrideshandle_attribute_updated. The away reset in_handle_attribute_updatedstill runs after the table update, as before. test_preset_from_attribute_cachefails for all three thermostats with origin/dev's climate module (the preset readsnone) and passes at the head.- At 864b39b:
tests/test_climate.py92 passed, full suite 1785 passed, mypy clean, nopyproject.tomlchange. CI is green. - Copilot CLI second opinion (static, adversarial brief): no findings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Severity: medium (the audit's estimate)
After a restart, the Moes, Beca and ZONNSMART thermostat entities show the preset
nonewhatever preset the TRV is in, until the TRV reportsoperation_presetagain. The preset was only taken from attribute events, and zigpy's restore of the attribute cache on startup fires none. While the entity wrongly saysnone, selectingnonewrites nothing (the TRV stays in boost or away), and in away the target temperature is read from and written to the occupied setpoint instead of the unoccupied one.This takes the initial preset from the cached
operation_presetwhen the entity is created.Changes
Thermostatgets an_operation_presetstable (operation_presetvalue to preset), empty by default. When it isn't empty and the cluster has anoperation_presetattribute,__init__sets the preset from the cached value;handle_attribute_updatedsets it fromoperation_presetevents.MoesThermostat,BecaThermostatandZONNSMARTThermostatdefine their table with the same values as before and drop their ownhandle_attribute_updatedoverrides, which held the same mapping asifchains. Values outside the table keep the current preset, as before.Testing
test_preset_from_attribute_cache(Moes, Beca and ZONNSMART) cachesoperation_presetbefore the entity is built, checks the preset, and checks that selectingnonewrites the device'snonevalue. It fails at dev 2da1a5b (the preset readsnonefor all three) and passes with the fix.test_preset_without_operation_preset_attribute: a thermostat that matchesMoesThermostatby manufacturer but has no quirk (nooperation_preset) still gets its climate entity, with the presetnone.tests/test_climate.py: 92 passed. Full suite: 1785 passed. pre-commit (codespell, ruff, ruff format, mypy) passed.Opened by the scheduled code audit; not requested by a maintainer.
Fixes #1042