Skip to content

Update Hold/Tap Actions to Objects#2182

Merged
balloob merged 11 commits intodevfrom
action-update-config
Dec 5, 2018
Merged

Update Hold/Tap Actions to Objects#2182
balloob merged 11 commits intodevfrom
action-update-config

Conversation

@zsarnett
Copy link
Copy Markdown
Contributor

@zsarnett zsarnett commented Dec 5, 2018

    tap_action:
      action: call-service
      service: light.turn_off
      service_data:
        entity_id: light.office
    hold_action:
      action: call-service
      service: light.toggle
      service_data:
        entity_id: light.office

@ghost ghost assigned zsarnett Dec 5, 2018
@ghost ghost added the in progress label Dec 5, 2018
@zsarnett zsarnett requested a review from iantrich December 5, 2018 01:33
@zsarnett zsarnett changed the title Entity-Button: Update Hold/Tap Actions to Objects Update Hold/Tap Actions to Objects Dec 5, 2018
@zsarnett
Copy link
Copy Markdown
Contributor Author

zsarnett commented Dec 5, 2018

UI Editor will need updated after this is merged

}
const [domain, service] = actionConfig.service.split(".", 2);
const serviceData = {
entity_id: config.entity,
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.

This has caused issues for some services that don't want the entity_id. I can't recall them off the top of my head, but should require that the service_data be explicitly stated instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

@thomasloven thomasloven Dec 5, 2018

Choose a reason for hiding this comment

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

Most services don't work that way. Probably by design.

Invalid service data for light.turn_on: extra keys not allowed @ data['unknown_key']. Got 'someting'

Invalid service data for system_log.write: extra keys not allowed @ data['entity_id']. Got 'light.my_lamp'

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.

Yeah we should stop trying to be smart and adding the entity automatically.

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 can still automatically populate service data for toggle, but not for normal services.

@iantrich
Copy link
Copy Markdown
Member

iantrich commented Dec 5, 2018

Travis threw an error here:
https://github.com/home-assistant/home-assistant-polymer/pull/2182/files#diff-2e86734b42da11910dbfae0763c5d602R77
Need to look inside the ActionConfigs now

Will also need to look at .action in the comparison

}

const action =
actionConfig && actionConfig.action ? actionConfig.action : "more-info";
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.

Not all the types handled by config have an action field. I don't think any elements are likely working right now with this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thats why it has the check for action field

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.

But you can still define an action type for the elements beyond "more-info". That is lost here.

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.

Perhaps we should just align the elements now as well? icon, image, state-icon and state-label

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh you are saying the elements of picture elements
Yea I havent gotten there yet. Next commit. Looking at that now

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.

It's fine to have multiple handleClick methods to handle different supported actions for different places in the code

hass: HomeAssistant,
config: LovelaceElementConfig | LovelaceCardConfig,
config:
| LovelaceElementConfig
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.

duplicate

@thomasloven
Copy link
Copy Markdown
Contributor

This doesn't allow for the "simple" configuration scheme tap_action: toggle, or did I miss something?

@zsarnett
Copy link
Copy Markdown
Contributor Author

zsarnett commented Dec 5, 2018

Correct. I though we decided against that. So that it was better configurable via the editor

@thomasloven
Copy link
Copy Markdown
Contributor

Rereading the discussion it seems that way... but it was not what I thought I agreed to.

It looks much nicer in a text config, and is similar to the entity list, but as you say it'd have to be converted by the editor on first edit...

@balloob
Copy link
Copy Markdown
Member

balloob commented Dec 5, 2018

I did think we would support the short-form too, when possible. However, given that editors are going to rewrite it and that by not defaulting service-data, action: service becomes semi-useless (but at least not unexpected behavior), we should probably just drop it.

I expect that within reasonable time, 95% of our users won't need to write YAML, especially since custom cards can also add config UI.

[key: string]: any;
}

export interface ActionConfig {
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.

This is the wrong approach. We should have a separate interface for each action and then have ActionConfig be a union interface: ActionConfig = CallServiceActionConfig & MoreInfoActionConfig

@ghost ghost assigned balloob Dec 5, 2018
import { HomeAssistant } from "../../../types";
import { ActionConfig } from "../../../data/lovelace";

export interface LovelaceElementConfig {
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.

In a future PR we need to get rid of this catch all element config. We need to define a type per element, then have 1 type that joins them

@balloob balloob merged commit de3a467 into dev Dec 5, 2018
@delete-merged-branch delete-merged-branch bot deleted the action-update-config branch December 5, 2018 13:27
@ghost ghost removed the in progress label Dec 5, 2018
@balloob balloob mentioned this pull request Dec 5, 2018
@iantrich
Copy link
Copy Markdown
Member

iantrich commented Dec 7, 2018

fixes #2180

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.

5 participants