-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use entity component translations for update entity (#18608)
- Loading branch information
Showing
10 changed files
with
198 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
CSSResultGroup, | ||
LitElement, | ||
PropertyValues, | ||
css, | ||
html, | ||
nothing, | ||
} from "lit"; | ||
import { customElement, property, state } from "lit/decorators"; | ||
import { UpdateEntity, computeUpdateStateDisplay } from "../../../data/update"; | ||
import { HomeAssistant } from "../../../types"; | ||
import { EntitiesCardEntityConfig } from "../cards/types"; | ||
import { hasConfigOrEntityChanged } from "../common/has-changed"; | ||
import "../components/hui-generic-entity-row"; | ||
import { createEntityNotFoundWarning } from "../components/hui-warning"; | ||
import { LovelaceRow } from "./types"; | ||
|
||
@customElement("hui-update-entity-row") | ||
class HuiUpdateEntityRow extends LitElement implements LovelaceRow { | ||
@property({ attribute: false }) public hass?: HomeAssistant; | ||
|
||
@state() private _config?: EntitiesCardEntityConfig; | ||
|
||
public setConfig(config: EntitiesCardEntityConfig): void { | ||
if (!config) { | ||
throw new Error("Invalid configuration"); | ||
} | ||
this._config = config; | ||
} | ||
|
||
protected shouldUpdate(changedProps: PropertyValues): boolean { | ||
return hasConfigOrEntityChanged(this, changedProps); | ||
} | ||
|
||
protected render() { | ||
if (!this._config || !this.hass) { | ||
return nothing; | ||
} | ||
|
||
const stateObj = this.hass.states[this._config.entity] as | ||
| UpdateEntity | ||
| undefined; | ||
|
||
if (!stateObj) { | ||
return html` | ||
<hui-warning> | ||
${createEntityNotFoundWarning(this.hass, this._config.entity)} | ||
</hui-warning> | ||
`; | ||
} | ||
|
||
return html` | ||
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}> | ||
${computeUpdateStateDisplay(stateObj, this.hass)} | ||
</hui-generic-entity-row> | ||
`; | ||
} | ||
|
||
static get styles(): CSSResultGroup { | ||
return css` | ||
div { | ||
text-align: right; | ||
} | ||
.pointer { | ||
cursor: pointer; | ||
} | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"hui-update-entity-row": HuiUpdateEntityRow; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; | ||
import { customElement, property } from "lit/decorators"; | ||
import "../components/entity/state-info"; | ||
import { computeUpdateStateDisplay, UpdateEntity } from "../data/update"; | ||
import { haStyle } from "../resources/styles"; | ||
import type { HomeAssistant } from "../types"; | ||
|
||
@customElement("state-card-update") | ||
export class StateCardUpdate extends LitElement { | ||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
@property({ attribute: false }) public stateObj!: UpdateEntity; | ||
|
||
@property({ type: Boolean }) public inDialog = false; | ||
|
||
protected render(): TemplateResult { | ||
return html` | ||
<div class="horizontal justified layout"> | ||
<state-info | ||
.hass=${this.hass} | ||
.stateObj=${this.stateObj} | ||
.inDialog=${this.inDialog} | ||
> | ||
</state-info> | ||
<div class="state"> | ||
${computeUpdateStateDisplay(this.stateObj, this.hass)} | ||
</div> | ||
</div> | ||
`; | ||
} | ||
|
||
static get styles(): CSSResultGroup { | ||
return [ | ||
haStyle, | ||
css` | ||
state-info { | ||
flex: 0 1 fit-content; | ||
min-width: 120px; | ||
} | ||
.state { | ||
color: var(--primary-text-color); | ||
margin-inline-start: 16px; | ||
margin-inline-end: initial; | ||
text-align: var(--float-end, right); | ||
min-width: 50px; | ||
flex: 0 1 fit-content; | ||
word-break: break-word; | ||
display: flex; | ||
align-items: center; | ||
direction: ltr; | ||
justify-content: flex-end; | ||
} | ||
`, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters