-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Update Hold/Tap Actions to Objects #2182
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
Changes from 3 commits
d7ce047
9151f9b
bb2672b
ab19765
5382335
efbda47
a4e3957
f62ec0b
e4d525c
d9b0179
3a9c5b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,20 +3,31 @@ import { LovelaceElementConfig } from "../elements/types"; | |
| import { fireEvent } from "../../../common/dom/fire_event"; | ||
| import { navigate } from "../../../common/navigate"; | ||
| import { toggleEntity } from "../../../../src/panels/lovelace/common/entity/toggle-entity"; | ||
| import { LovelaceCardConfig } from "../../../data/lovelace"; | ||
| import { LovelaceCardConfig, ActionConfig } from "../../../data/lovelace"; | ||
| import { EntityConfig } from "../entity-rows/types"; | ||
|
|
||
| export interface ConfigEntity extends EntityConfig { | ||
| tap_action?: ActionConfig; | ||
| hold_action?: ActionConfig; | ||
| navigation_path?: string; | ||
| } | ||
|
|
||
| export const handleClick = ( | ||
| node: HTMLElement, | ||
| hass: HomeAssistant, | ||
| config: LovelaceElementConfig | LovelaceCardConfig, | ||
| config: LovelaceElementConfig | LovelaceCardConfig | ConfigEntity, | ||
| hold: boolean | ||
| ): void => { | ||
| let action = config.tap_action || "more-info"; | ||
|
|
||
| let actionConfig; | ||
| if (hold && config.hold_action) { | ||
| action = config.hold_action; | ||
| actionConfig = config.hold_action; | ||
| } else if (!hold && config.tap_action) { | ||
| actionConfig = config.tap_action; | ||
| } | ||
|
|
||
| const action = | ||
| actionConfig && actionConfig.action ? actionConfig.action : "more-info"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not all the types handled by
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats why it has the check for action field
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But you can still define an action type for the elements beyond "more-info". That is lost here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should just align the elements now as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh you are saying the elements of picture elements
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine to have multiple handleClick methods to handle different supported actions for different places in the code |
||
|
|
||
| if (action === "none") { | ||
| return; | ||
| } | ||
|
|
@@ -34,14 +45,15 @@ export const handleClick = ( | |
| toggleEntity(hass, config.entity!); | ||
| break; | ||
| case "call-service": { | ||
| if (config.service) { | ||
| const [domain, service] = config.service.split(".", 2); | ||
| const serviceData = { | ||
| entity_id: config.entity, | ||
| ...config.service_data, | ||
| }; | ||
| hass.callService(domain, service, serviceData); | ||
| if (!actionConfig.service) { | ||
| return; | ||
| } | ||
| const [domain, service] = actionConfig.service.split(".", 2); | ||
| const serviceData = { | ||
| entity_id: config.entity, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has caused issues for some services that don't want the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it doesnt want it, the service should ignore it... I think that should be a service fix
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most services don't work that way. Probably by design.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we should stop trying to be smart and adding the entity automatically.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can still automatically populate service data for |
||
| ...actionConfig.service_data, | ||
| }; | ||
| hass.callService(domain, service, serviceData); | ||
| } | ||
| } | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the wrong approach. We should have a separate interface for each action and then have
ActionConfigbe a union interface:ActionConfig = CallServiceActionConfig & MoreInfoActionConfig