Skip to content

Add default_control option to cover card - #1940

Open
PeterLinuxOSS wants to merge 3 commits into
piitaya:mainfrom
PeterLinuxOSS:feat/cover-card-default-control
Open

Add default_control option to cover card#1940
PeterLinuxOSS wants to merge 3 commits into
piitaya:mainfrom
PeterLinuxOSS:feat/cover-card-default-control

Conversation

@PeterLinuxOSS

@PeterLinuxOSS PeterLinuxOSS commented Aug 30, 2026

Copy link
Copy Markdown

Description

Adds a new optional default_control option 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.

type: custom:mushroom-cover-card
entity: cover.blinds
show_buttons_control: true
show_position_control: true
show_tilt_position_control: true
default_control: tilt_position_control

Allowed values are buttons_control, position_control and tilt_position_control, validated with enums() in the config struct.

What it does not change:

  • the order used by the control switch button stays exactly the same, default_control only picks the initial one
  • without default_control the behaviour is unchanged, the first enabled control is used
  • a default_control pointing at a control that is not enabled falls back to the first enabled one instead of erroring
  • the active control is still preserved across rerenders while it stays enabled

The selection logic moved to a small pure computeActiveControl() helper in cover-card/utils.ts so 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_mode in the number card: an auto placeholder 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_control that 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.json plus sk.json as 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_control only 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_default variable expecting button or position or tilt". 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:

  • editor shows the new dropdown with the localized labels under the three existing toggles; picking Tilt position writes default_control: tilt_position_control to the YAML
  • on a cover card whose tilt control is off, the picker lists only Control buttons and Position; on a card with one or no control enabled it is not rendered at all
  • that card then loads on the tilt slider instead of the buttons, and the switch button still cycles buttons → position → tilt
  • the other cards on the same dashboard, which have no default_control, still load on the buttons control

computeActiveControl() 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 build and prettier --check on the changed files are clean.

Types of changes

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 🌎 Translation (addition or update a translation)
  • ⚙️ Tech (code style improvement, performance improvement or dependencies bump)
  • 📚 Documentation (fix or addition in the documentation)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have tested the change locally.
  • I followed the steps if I add a new language .

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Cover card, ability to show position control by default

1 participant