From c39fdcda6e48a536b26dd9c9dc8d658530c18321 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 6 Jun 2023 13:42:45 +0200 Subject: [PATCH] Fix 403 on state-badge connect (#16795) --- src/components/entity/state-badge.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/components/entity/state-badge.ts b/src/components/entity/state-badge.ts index e855bfdd57..4fbfcaf853 100644 --- a/src/components/entity/state-badge.ts +++ b/src/components/entity/state-badge.ts @@ -38,6 +38,31 @@ export class StateBadge extends LitElement { @state() private _iconStyle: { [name: string]: string | undefined } = {}; + connectedCallback(): void { + super.connectedCallback(); + if ( + this.hasUpdated && + this.overrideImage === undefined && + (this.stateObj?.attributes.entity_picture || + this.stateObj?.attributes.entity_picture_local) + ) { + // Update image on connect, so we get new auth token + this.requestUpdate("stateObj"); + } + } + + disconnectedCallback() { + super.disconnectedCallback(); + if ( + this.overrideImage === undefined && + (this.stateObj?.attributes.entity_picture || + this.stateObj?.attributes.entity_picture_local) + ) { + // Clear image on disconnect so we don't fetch with old auth when we reconnect + this.style.backgroundImage = ""; + } + } + private get _stateColor() { const domain = this.stateObj ? computeStateDomain(this.stateObj)