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

Convert hui-call-service-row to TypeScript/LitElement #1894

Merged
merged 5 commits into from
Oct 30, 2018

Conversation

iantrich
Copy link
Member

No description provided.

@ghost ghost assigned iantrich Oct 28, 2018
@ghost ghost added the in progress label Oct 28, 2018
!config.name ||
!config.action_name ||
!config.service ||
!config.service_data
Copy link
Contributor

Choose a reason for hiding this comment

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

This is more of a question: Does Service Data need to be required? Isn't service data by default the entity_Id? Idk if that what is passed to this though

Copy link
Member Author

@iantrich iantrich Oct 28, 2018

Choose a reason for hiding this comment

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

The docs say it is required which is what I was going by 🤷‍♂️

Copy link
Member

@balloob balloob Oct 28, 2018

Choose a reason for hiding this comment

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

There is no entity_id in this config, so it can't default to entity ID. However, it's totally fine to have an empty service data. We should make it not required.

static get properties() {
return {
hass: {},
config: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be _config?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

@iantrich
Copy link
Member Author

Not sure why Travis is complaining?

@balloob
Copy link
Member

balloob commented Oct 28, 2018

Travis is complaining about the polymer linter, which apparently decided to throw errors 🤔 which is weird as we use yarn install and have a lock file.

</div>
<paper-button on-click="_callService">[[_config.action_name]]</paper-button>
<paper-button
@click="${() => callService(this._config, this.hass)}"
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing this, can you make it a private function so we don't have to create a new arrow function on each render.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is that just more overhead to create the arrow functions?

Copy link
Member

Choose a reason for hiding this comment

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

render is called many times, each time we define a function. That function, just being generated, won't be unique to the previous one, causing lit to update the click listener. (oldVal !== newVal). It also means that you create a function per instance of the element.

Now with a class method, the definition of the method just lives on the prototype chain. There is only 1 in memory even if you have 1000 instances. No updates are triggered when setting (oldVal === newVal). And as added bonus, if someone would want to inherit from this class, they could override the method. Overall a lot better 👍

iantrich added a commit to home-assistant/home-assistant.io that referenced this pull request Oct 28, 2018

public setConfig(config: Config) {
const entities = processConfigEntities(config.entities);
for (const entity of entities) {
Copy link
Member

Choose a reason for hiding this comment

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

We should drop this check. The createRowElement function will render an error card when a type is invalid.

Copy link
Member Author

@iantrich iantrich Oct 29, 2018

Choose a reason for hiding this comment

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

Not sure why git thinks I changed all of this? I plan to clean up entities-card config checks in a future PR though.

.hass="${this._hass}"
.entities="${this._configEntities!.map(
(conf) => conf.entity
)}"
Copy link
Member

Choose a reason for hiding this comment

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

add .filter(Boolean) to filter out any undefined which are returned when fetching entity from weblink or service call config.

}

this._config = config;
this._configEntities = entities;
Copy link
Member

Choose a reason for hiding this comment

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

We should call it _configRows, as not all are entities.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think prettier ran against this file and made it look like I touched everything. Fail on my part.

My only intended change was to remove the !entity.service_data check when entity.type === "call-service" as I moved that to being optional. The full check should be removed in a future PR

public setConfig(config: CallServiceConfig): void {
if (
!config ||
!config.icon ||
Copy link
Member

Choose a reason for hiding this comment

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

We should do a default icon.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have a suggestion? I was thinking play-circle-outline

play-circle-outline

Copy link
Member

Choose a reason for hiding this comment

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

what icon do we use for services in the dev tools?

!config ||
!config.icon ||
!config.name ||
!config.action_name ||
Copy link
Member

Choose a reason for hiding this comment

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

Let's do a default action_name, what about "Run" ?

* Made `service_data` optional and verified that `callService` does use `entity` if it is available in the passed config.
* Removed check in `entities-card` for `service-data` and will remove the full config check once other PRs have been applied to avoid merge conflicts
* Will create a docs PR to update the docs
* Removed entity config check in entities-card
* Made `icon` optional. Default now `remote`
* Made `action_name` optional. Default now 'Run'

return html`
${this.renderStyle()}
<ha-icon icon="${this._config.icon}"></ha-icon>
Copy link
Member

Choose a reason for hiding this comment

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

.icon

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Ok to merge when comment addressed.

@balloob
Copy link
Member

balloob commented Oct 30, 2018

Not sure why Polymer linter "woke up" and started to spit all over your PR

@balloob
Copy link
Member

balloob commented Oct 30, 2018

Figured it out, TypeScript was checking all type declarations of our node modules, making a mess. Fixed it in #1885 so will go ahead and merge this one.

@balloob balloob merged commit 38bfe8c into home-assistant:dev Oct 30, 2018
@ghost ghost removed the in progress label Oct 30, 2018
frenck pushed a commit to home-assistant/home-assistant.io that referenced this pull request Nov 11, 2018
* service-data now optional

home-assistant/frontend#1894

* additional fields made optional

`icon` and `action_name` will be optional as well

* 🚑 Fixes build
@iantrich iantrich deleted the ts-service-row branch November 16, 2018 19:19
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 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.

None yet

5 participants