Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow variables to have default values #1

Closed
flyboy013 opened this issue Jun 6, 2019 · 4 comments · Fixed by #2
Closed

Allow variables to have default values #1

flyboy013 opened this issue Jun 6, 2019 · 4 comments · Fixed by #2
Labels

Comments

@flyboy013
Copy link

Enhancement Request.

I have 30+ button cards in my HA instance and I am now using the decluttering-card to provide a consistent behavior and style for all the buttons on all the views. This has worked great in that it allows me to update this one card to change the behavior (ie. tap_action) or style (ie. label color) across the entire site!

I have found that there are occasions where I need a few cards to be slightly different than what was defined in the decluttering-card. I don't want to create another variable and have the color specified in the variable section of every instance of the card, as it defeats the purpose of making a single change to update the style for all the cards. I could also duplicate the decluttering-card and specify the one item that's different, but again, it defeats the purpose of decluttering-card.

It would be nice if I could specify a variable in the decluttering-card, but have a default value if I don't specify it when using the card. For instance, I may want the labels on all my cards to be blue, but I need a few of them to be red for whatever reason. I would like to specify the blue style color in the decluttering-card, but allow the variable to be overridden with the color red for the specific button instantiation.

A decluttering-card configuration may look like this:

decluttering_templates:
  my_first_template:     # This is the name of a template
    type: custom:button-card
    name: '[[name]]'
    icon: 'mdi:[[icon]]'
    styles:
      label:
        - color:  '[[label_color]]'' | blue
@RomRider
Copy link
Collaborator

RomRider commented Jun 7, 2019

I'm experimenting with this, it's easier to manage than inlined default values. What do you think?

input_select_menu_item:
  default:
    - spin: false
  card:
    type: custom:button-card
    template: menu_header
    entity: '[[entity]]'
    name: '[[item]]'
    icon: '[[icon]]'
    tap_action:
      action: call-service
      service: input_select.select_option
      service_data:
        entity_id: '[[entity]]'
        option: '[[item]]'
    state:
      - value: '[[item]]'
        color: white
        name: ▾ [[item]] ▾
        spin: '[[spin]]'
      - operator: default
        color: var(--paper-card-background-color)

@flyboy013
Copy link
Author

I like it. It actually makes it very clear that default values exists and thus specifying them in the card instantiation is optional.

@RomRider RomRider mentioned this issue Jun 8, 2019
Merged
@flyboy013
Copy link
Author

Works great. Thank you.

@github-actions
Copy link

github-actions bot commented Apr 2, 2023

🎉 This issue has been resolved in version 1.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants