-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
!config.name || | ||
!config.action_name || | ||
!config.service || | ||
!config.service_data |
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 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
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.
The docs say it is required which is what I was going by 🤷♂️
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.
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: {}, |
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.
Should this be _config?
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.
Yes.
Not sure why Travis is complaining? |
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)}" |
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.
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.
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.
Is that just more overhead to create the arrow functions?
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.
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 👍
|
||
public setConfig(config: Config) { | ||
const entities = processConfigEntities(config.entities); | ||
for (const entity of entities) { |
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.
We should drop this check. The createRowElement
function will render an error card when a type is invalid.
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.
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 | ||
)}" |
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.
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; |
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.
We should call it _configRows
, as not all are entities.
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.
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 || |
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.
We should do a default icon.
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.
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.
what icon do we use for services in the dev tools?
!config || | ||
!config.icon || | ||
!config.name || | ||
!config.action_name || |
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.
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
522451d
to
4a31640
Compare
* 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> |
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.
.icon
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.
Ok to merge when comment addressed.
Not sure why Polymer linter "woke up" and started to spit all over your PR |
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. |
* service-data now optional home-assistant/frontend#1894 * additional fields made optional `icon` and `action_name` will be optional as well * 🚑 Fixes build
No description provided.