Add default_control option to cover card - #1940
Open
PeterLinuxOSS wants to merge 3 commits into
Open
Conversation
Let users choose which enabled control the cover card shows when it is loaded, instead of always starting with the first one of the fixed list (buttons, position, tilt position). The active control is still preserved across rerenders when it stays enabled, and an unavailable default_control falls back to the first enabled control.
The picker listed all three controls regardless of which ones the card actually shows, so a cover card without a tilt control still offered tilt position as its default. It is hidden entirely until at least two controls are enabled, since there is nothing to choose from before that. A configured default_control that is no longer enabled now shows as the placeholder, matching what the card does with it.
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.
Description
Adds a new optional
default_controloption to the cover card, so the control shown when the card is loaded can be chosen instead of always being the first one of the fixed list.Allowed values are
buttons_control,position_controlandtilt_position_control, validated withenums()in the config struct.What it does not change:
default_controlonly picks the initial onedefault_controlthe behaviour is unchanged, the first enabled control is useddefault_controlpointing at a control that is not enabled falls back to the first enabled one instead of erroringThe selection logic moved to a small pure
computeActiveControl()helper incover-card/utils.tsso the three cases (keep current / configured default / first enabled) read in one place.The option is available in the visual editor as a dropdown right under the three existing toggles, following the same pattern as
display_modein the number card: anautoplaceholder is shown when the option is unset and removed from the config when saved, so existing configs are not rewritten.The picker only lists controls the card actually shows, and stays hidden until at least two are enabled — a cover card with no tilt control should not offer tilt position as its default, and a card with one control has nothing to choose from. For the same reason a
default_controlthat is no longer enabled displays as the placeholder: that is what the card does with it, so showing the stored value instead would be misleading.Translations are
en.jsonplussk.jsonas my own language, in a separate commit. The remaining languages are left to Weblate. Every locale falls back to English for a missing key, so nothing shows a raw key in the meantime.Related Issue
This PR fixes or closes issue: fixes #1186
Related but not fixed here: #877 asks for the tilt control to be shown next to the position one rather than behind the switch button, which needs a layout change rather than a default.
default_controlonly makes the wanted control reachable without tapping through the others first.Motivation and Context
With several controls enabled the card always starts on the buttons control. For venetian blinds the tilt slider is usually the one you reach for, and getting to it needs two taps on the switch button every time the dashboard is loaded.
Issue #1186 asks for the position control specifically, and a comment there already suggests this exact shape — "a
control_defaultvariable expectingbuttonorpositionortilt". A single option covers the position request and the tilt case at once, without adding one boolean per control.The same comment also floats full ordering via per-control priorities. That is left out on purpose: it is a bigger change, and picking the initial control is what both the issue title and the tilt case actually need.
How Has This Been Tested
Built from this branch and served in place of the HACS 5.2.2 build on a live Home Assistant instance, on a dashboard of venetian blind cards (
supported_features: 191) that all have the three controls enabled.In the browser:
Tilt positionwritesdefault_control: tilt_position_controlto the YAMLControl buttonsandPosition; on a card with one or no control enabled it is not rendered at alldefault_control, still load on the buttons controlcomputeActiveControl()was exercised directly over the relevant combinations of enabled controls × configured default × currently active control: no default (each subset of enabled controls), configured default enabled, configured default not enabled, no control enabled at all, and a control picked by hand surviving a rerender.npx tsc --noEmit,npm run buildandprettier --checkon the changed files are clean.Types of changes
Checklist