Fix 403 on state-badge connect (#16795)

This commit is contained in:
Bram Kragten 2023-06-06 13:42:45 +02:00 committed by GitHub
parent fd1381ab3b
commit c39fdcda6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)