Repository navigation
Add a text platform for ZCL string attributes - #1023
Draft
zigpy-review-bot wants to merge 6 commits into
Draft
zigpy-review-bot wants to merge 6 commits into
zigpy-review-bot wants to merge 6 commits into
Conversation
Add `Platform.TEXT` and `EntityPlatform.TEXT`, a `BaseText` entity with a `TextState` (value, mode, length limits and pattern), and a `TextConfigurationEntity` that shows and writes a ZCL string attribute. Attributes typed as raw bytes are decoded from and encoded to UTF-8. No default entities use it yet; it is meant for quirks.
HA refuses a text state outside the length limits or pattern, so show such a device value, and the ZCL invalid string, as unknown. Raise the password-mode write error outside the except block so the original error, which holds the value, is not attached to it.
zigpy rebuilds received values with the attribute type, which drops the `invalid` flag, so the check only ever saw values set directly.
HA allows 255 characters, while a ZCL string holds 254 bytes at most, and zigpy raises a ValueError for longer values that HA shows as an unknown error. Turn it into a ZHAException (without the zigpy message in password mode). Default the length limit to the attribute type's own limit, such as `LimitedCharString(16)`, when none is given.
This was referenced Nov 16, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1023 +/- ##
==========================================
+ Coverage 97.48% 97.51% +0.02%
==========================================
Files 61 63 +2
Lines 10870 10988 +118
==========================================
+ Hits 10597 10715 +118
Misses 273 273 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Adds a
textentity platform, so a quirk can expose a writable string attribute as a Home Assistanttextentity instead of users writing it withzha.set_zigbee_cluster_attribute. Tracked in zigpy/backlog#85. This covers ZCL attributes only; values that aren't attributes are left to the separate device-values work.Changes
Platform.TEXTandEntityPlatform.TEXT(the latter is what quirk metadata uses).zha/application/platforms/text:BaseTextwith aTextStatecarrying the value, themode(text/password),native_min/native_maxand an optionalpattern, mirroring HA'sTextEntity;TextConfigurationEntity, a config entity backed by a ZCL string attribute. It shows the cached value, updates on reads, reports and writes, and writes the attribute when HA sets a new value. Attributes typed as raw bytes (LVBytesand the like, as some manufacturer clusters use for labels) are decoded from and encoded to UTF-8. Without an explicitmax_length(or a subclass's own limit), the limit is the attribute type's own (LimitedCharString(16)gives 16) or HA's 255. A device value that HA would refuse as a state (outside the length limits or not matching the pattern) is shown as unknown. A value the attribute type can't hold (a ZCL string holds at most 254 bytes) raises aZHAExceptioninstead of zigpy'sValueError, which HA would show as an unknown error. Inpasswordmode a failed write raises without the value in the error.Testing
tests/test_platform_text.pycovers the state, the options, updates from reports and writes, raw-byte attributes, values outside the limits, values too long for the attribute type, the support check and failed writes (100% line and branch coverage of the new module). The full suite passes locally, and pre-commit (ruff, mypy, codespell) is clean.Related
.text()builder method in Add text entities for string attributes to quirks v2 zha-device-handlers#5724, withtuya_textfor Tuya string datapoints stacked on it in Addtuya_textfor Tuya string datapoints zha-device-handlers#5725.textplatform: TheJulianJES/corezigpy-bot/zha-text-platform(no PR yet). It needs a zha release with this change first.Open items
LimitedCharString) count characters, so a non-ASCII value withinnative_maxcan still be too long for the device. zigpy sends it anyway (it only refuses more than 254 bytes, which the entity reports as a write error), and the device rejects or truncates it.zigbee.db, included in ZHA diagnostics and written to zigpy's and ZHA's debug logs.passwordmode only masks the input in the UI. Whether such attributes should be exposed at all is left open in [ZHA] Text entity support for quirks backlog#85.