Set hass when creating card (#7187)

This commit is contained in:
Bram Kragten 2020-10-02 15:09:27 +02:00 committed by GitHub
parent cbdfaccdb2
commit 2ecf7bca97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -49,7 +49,6 @@ class HcLovelace extends LitElement {
.hass=${this.hass} .hass=${this.hass}
.lovelace=${lovelace} .lovelace=${lovelace}
.index=${index} .index=${index}
columns="2"
></hui-view> ></hui-view>
`; `;
} }
@ -67,7 +66,7 @@ class HcLovelace extends LitElement {
if (configBackground) { if (configBackground) {
(this.shadowRoot!.querySelector( (this.shadowRoot!.querySelector(
"hui-view, hui-panel-view" "hui-view"
) as HTMLElement)!.style.setProperty( ) as HTMLElement)!.style.setProperty(
"--lovelace-background", "--lovelace-background",
configBackground configBackground

View File

@ -164,14 +164,12 @@ export class HUIView extends UpdatingElement {
return; return;
} }
const elements: HUIView["_badges"] = [];
const badges = processConfigEntities(config.badges as any); const badges = processConfigEntities(config.badges as any);
badges.forEach((badge) => { this._badges = badges.map((badge) => {
const element = createBadgeElement(badge); const element = createBadgeElement(badge);
element.hass = this.hass; element.hass = this.hass;
elements.push(element); return element;
}); });
this._badges = elements;
} }
private _createCards(config: LovelaceViewConfig): void { private _createCards(config: LovelaceViewConfig): void {
@ -180,9 +178,11 @@ export class HUIView extends UpdatingElement {
return; return;
} }
this._cards = config.cards.map((cardConfig) => this._cards = config.cards.map((cardConfig) => {
this.createCardElement(cardConfig) const element = this.createCardElement(cardConfig);
); element.hass = this.hass;
return element;
});
} }
private _rebuildCard( private _rebuildCard(
@ -190,6 +190,7 @@ export class HUIView extends UpdatingElement {
config: LovelaceCardConfig config: LovelaceCardConfig
): void { ): void {
const newCardEl = this.createCardElement(config); const newCardEl = this.createCardElement(config);
newCardEl.hass = this.hass;
if (cardElToReplace.parentElement) { if (cardElToReplace.parentElement) {
cardElToReplace.parentElement!.replaceChild(newCardEl, cardElToReplace); cardElToReplace.parentElement!.replaceChild(newCardEl, cardElToReplace);
} }
@ -203,7 +204,13 @@ export class HUIView extends UpdatingElement {
config: LovelaceBadgeConfig config: LovelaceBadgeConfig
): void { ): void {
const newBadgeEl = this.createBadgeElement(config); const newBadgeEl = this.createBadgeElement(config);
badgeElToReplace.parentElement!.replaceChild(newBadgeEl, badgeElToReplace); newBadgeEl.hass = this.hass;
if (badgeElToReplace.parentElement) {
badgeElToReplace.parentElement!.replaceChild(
newBadgeEl,
badgeElToReplace
);
}
this._badges = this._cards!.map((curBadgeEl) => this._badges = this._cards!.map((curBadgeEl) =>
curBadgeEl === badgeElToReplace ? newBadgeEl : curBadgeEl curBadgeEl === badgeElToReplace ? newBadgeEl : curBadgeEl
); );