feat(exposes): add withDefault for composite feature defaults#12667
Closed
MaxRink wants to merge 1 commit into
Closed
feat(exposes): add withDefault for composite feature defaults#12667MaxRink wants to merge 1 commit into
MaxRink wants to merge 1 commit into
Conversation
Adds an optional per-feature `default` (via `withDefault`) so consumers (e.g. a Home Assistant composite editor card) can pre-fill fields of a new/empty atomic composite slot and build a complete payload. A composite must be written to the device as one complete object in a single message; individually writing fields breaks devices like the SONOFF valve (see Koenkk#12495/Koenkk#12510 reverted by Koenkk#12647). Seeds defaults on the SONOFF cyclic timed/quantitative irrigation composites.
Contributor
External review requiredThis PR modifies files that require review from their code owners before merging.
Once reviewed, add the |
Contributor
Author
|
Closing: the composite editor no longer needs converter-provided defaults. The Home Assistant card derives sensible field defaults directly from the expose schema (numeric → value_min, enum → first value, binary → value_off, text → ""), so this |
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 an optional per-feature
defaultvalue to exposes via a newwithDefault(value)builder onBase, and seeds defaults on the SONOFF cyclic timed/quantitative irrigation composites.Why
A
compositemust be written to the device as one complete object in a single message; its fields are not independently writable (this is the whole point ofcomposite— see #12495 and #12510 which were reverted by #12647 because the SONOFF valve needs the full config in one write and new/empty plan slots have no cached state to merge).A companion Home Assistant composite-editor card (and potentially other consumers) needs sensible per-field defaults so it can pre-fill a new/empty composite slot and build a complete payload. This adds that capability without changing any converter logic — only optional metadata.
Changes
src/lib/exposes.ts: optionalBase.default+withDefault(), preserved through clone/copy (only when set, so serialized exposes are unchanged when unused).src/devices/sonoff.ts:.withDefault(...)on the cyclic timed/quantitative irrigation composite features (values within declared ranges).test/utils.test.ts: tests for setting/cloning and non-serialization when unset.Companion work
Consumed by a Zigbee2MQTT change that discovers settable composites for Home Assistant and a custom Lovelace card that edits them (linked separately).