Set entity-button defaults#2897
Conversation
tap_action: toggle hold_action: more-info
| return { | ||
| tap_action: { action: "more-info" }, | ||
| hold_action: { action: "none" }, | ||
| tap_action: { action: "toggle" }, |
There was a problem hiding this comment.
We should make sure the entity can be toggled.
There was a problem hiding this comment.
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" }, |
There was a problem hiding this comment.
Okay, I should have put my comment here 😆
There was a problem hiding this comment.
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,
};There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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