Skip to content

Set entity-button defaults#2897

Merged
balloob merged 3 commits into
home-assistant:devfrom
iantrich:button-actions
Mar 15, 2019
Merged

Set entity-button defaults#2897
balloob merged 3 commits into
home-assistant:devfrom
iantrich:button-actions

Conversation

@iantrich
Copy link
Copy Markdown
Member

@iantrich iantrich commented Mar 9, 2019

tap_action: toggle
hold_action: more-info

I think this makes a lot more sense as defaults for this card

Partial fix for home-assistant/ui-schema#234

tap_action: toggle
hold_action: more-info
return {
tap_action: { action: "more-info" },
hold_action: { action: "none" },
tap_action: { action: "toggle" },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure the entity can be toggled.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I won't know that at the time I create a stub config. Perhaps it could be a feature of the UI editor though? Not present toggle as an option if entity is not toggleable and make inactive until an entity is selected?

this._config = { theme: "default", ...config };
this._config = {
theme: "default",
tap_action: { action: "toggle" },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I should have put my comment here 😆

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this?

this._config = {
      theme: "default",
      tap_action: {
        action: DOMAINS_TOGGLE.has(config.entity.split(".", 1)[0])
          ? "toggle"
          : "more-info",
      },
      hold_action: { action: "more-info" },
      ...config,
    };

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is my linter drunk...?

Type '{ entity: string; name?: string | undefined; icon?: string | undefined; theme: string; tap_action: ToggleActionConfig | CallServiceActionConfig | NavigateActionConfig | MoreInfoActionConfig | NoActionConfig | { ...; }; hold_action: ToggleActionConfig | ... 4 more ... | { ...; }; index?: number | undefined; view_inde...' is not assignable to type 'Config'.
  Types of property 'tap_action' are incompatible.
    Type 'ToggleActionConfig | CallServiceActionConfig | NavigateActionConfig | MoreInfoActionConfig | NoActionConfig | { action: "toggle" | "more-info"; }' is not assignable to type 'ToggleActionConfig | CallServiceActionConfig | NavigateActionConfig | MoreInfoActionConfig | NoActionConfig | undefined'.
      Type '{ action: "toggle" | "more-info"; }' is not assignable to type 'ToggleActionConfig | CallServiceActionConfig | NavigateActionConfig | MoreInfoActionConfig | NoActionConfig | undefined'.
        Type '{ action: "toggle" | "more-info"; }' is not assignable to type 'NoActionConfig'.
          Types of property 'action' are incompatible.
            Type '"toggle" | "more-info"' is not assignable to type '"none"'.
              Type '"toggle"' is not assignable to type '"none"'.ts(2322)
(property) HuiEntityButtonCard._config?: Config | undefined

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this is a bug in typescript. It is trying to map action: "toggle" | "more-info" and trying to find a single type that matches it, instead of realizing that we're referencing ToggleActionConfig and MoreInfoActionConfig.

You will need to pull it out into an if statement. Probably good too, because we wouldn't want hold_action to be more-info if tap is more-info.

Also, use computeDomain.

@ghost ghost added the in progress label Mar 13, 2019
@balloob balloob merged commit 2aec877 into home-assistant:dev Mar 15, 2019
@ghost ghost removed the in progress label Mar 15, 2019
@balloob balloob mentioned this pull request Mar 15, 2019
@iantrich iantrich deleted the button-actions branch October 30, 2019 03:18
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants