Convert hui-toggle-entity-row to TypeScript/LitElement#1939
Convert hui-toggle-entity-row to TypeScript/LitElement#1939balloob merged 4 commits intohome-assistant:devfrom
Conversation
| return html``; | ||
| } | ||
|
|
||
| const stateObj = this.hass.states[this._config.entity]; |
There was a problem hiding this comment.
Should we be checking if this exists? Or is this a case of to even call this element there has to be a state obj?
There was a problem hiding this comment.
We should check if stateObj is defined. Might want to consider updating the type of hass.states to indicate that we don't have a value for every key.
There was a problem hiding this comment.
Ooh, hui-generic-entity-row will render a yello block if the entity doesn't exist, we just need to make sure we don't crash on line 46.
| `; | ||
| } | ||
|
|
||
| private _computeState(stateObj: HassEntity) { |
| import "../entity-rows/hui-text-entity-row.js"; | ||
| import "../entity-rows/hui-timer-entity-row.js"; | ||
| import "../entity-rows/hui-toggle-entity-row.js"; | ||
| import "../entity-rows/hui-toggle-entity-row"; |
There was a problem hiding this comment.
We should just have a PR that rips out all .js from all imports throughout the whole repo.
There was a problem hiding this comment.
Just remember that you asked for this: #1941
I started small with only all of src 😄
| } | ||
|
|
||
| private _computeState(stateObj: HassEntity) { | ||
| return stateObj && computeStateDisplay(this.localize, stateObj); |
There was a problem hiding this comment.
No need to check for stateObj here, if it didn't exist, you would already have crashed on line 46 😉
There was a problem hiding this comment.
I think that you can just put computeStateDisplay directly in to the template above.
| } | ||
|
|
||
| protected render(): TemplateResult { | ||
| if (!this._config || !this.hass || !this.hass.states[this._config.entity]) { |
There was a problem hiding this comment.
This is not good. Right now we won't render anything if the entity doesn't exist.
The old behavior was that if the entity doesn't exist, we still render <hui-generic-entity-row> which would then go ahead and render a yellow warning that the entity didn't exist.
f8ef65a to
06d0930
Compare
No description provided.