fix: Better handle multiple simultaneous requests for diagnostics (#1852)
- Closes #1851 [skip ci]
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
import { HomeAssistant } from '@dermotduffy/custom-card-helpers';
|
import { HomeAssistant } from '@dermotduffy/custom-card-helpers';
|
||||||
import { CSSResultGroup, LitElement, TemplateResult, unsafeCSS } from 'lit';
|
import { CSSResultGroup, html, LitElement, TemplateResult, unsafeCSS } from 'lit';
|
||||||
import { customElement, property, state } from 'lit/decorators.js';
|
import { customElement, property } from 'lit/decorators.js';
|
||||||
|
import { until } from 'lit/directives/until.js';
|
||||||
import { RawFrigateCardConfig } from '../config/types';
|
import { RawFrigateCardConfig } from '../config/types';
|
||||||
import { localize } from '../localize/localize';
|
import { localize } from '../localize/localize';
|
||||||
import basicBlockStyle from '../scss/basic-block.scss';
|
import basicBlockStyle from '../scss/basic-block.scss';
|
||||||
import { Diagnostics, getDiagnostics } from '../utils/diagnostics';
|
import { getDiagnostics } from '../utils/diagnostics';
|
||||||
import { renderMessage } from './message';
|
|
||||||
import { DeviceRegistryManager } from '../utils/ha/registry/device';
|
import { DeviceRegistryManager } from '../utils/ha/registry/device';
|
||||||
|
import { renderMessage } from './message';
|
||||||
|
|
||||||
@customElement('frigate-card-diagnostics')
|
@customElement('frigate-card-diagnostics')
|
||||||
export class FrigateCardDiagnostics extends LitElement {
|
export class FrigateCardDiagnostics extends LitElement {
|
||||||
@property({ attribute: false })
|
// Not a reactive property to avoid multiple diagnostics fetches.
|
||||||
public hass?: HomeAssistant;
|
public hass?: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
@@ -19,33 +20,31 @@ export class FrigateCardDiagnostics extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public rawConfig?: RawFrigateCardConfig;
|
public rawConfig?: RawFrigateCardConfig;
|
||||||
|
|
||||||
@state()
|
protected async _renderDiagnostics(): Promise<TemplateResult> {
|
||||||
protected _diagnostics: Diagnostics | null = null;
|
const diagnostics = await getDiagnostics(
|
||||||
|
|
||||||
protected async _fetchDiagnostics(): Promise<void> {
|
|
||||||
this._diagnostics = await getDiagnostics(
|
|
||||||
this.hass,
|
this.hass,
|
||||||
this.deviceRegistryManager,
|
this.deviceRegistryManager,
|
||||||
this.rawConfig,
|
this.rawConfig,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
protected shouldUpdate(): boolean {
|
|
||||||
if (!this._diagnostics) {
|
|
||||||
this._fetchDiagnostics().then(() => this.requestUpdate());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render(): TemplateResult | void {
|
|
||||||
return renderMessage({
|
return renderMessage({
|
||||||
message: localize('error.diagnostics'),
|
message: localize('error.diagnostics'),
|
||||||
icon: 'mdi:cogs',
|
icon: 'mdi:cogs',
|
||||||
context: this._diagnostics,
|
context: diagnostics,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected render(): TemplateResult | void {
|
||||||
|
return html`${until(
|
||||||
|
this._renderDiagnostics(),
|
||||||
|
renderMessage({
|
||||||
|
message: localize('error.fetching_diagnostics'),
|
||||||
|
dotdotdot: true,
|
||||||
|
icon: 'mdi:cogs',
|
||||||
|
}),
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return unsafeCSS(basicBlockStyle);
|
return unsafeCSS(basicBlockStyle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,10 @@ export class FrigateCardMessage extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const messageTemplate = html`
|
const messageTemplate = html`
|
||||||
${this._controller.getMessageString(this.message)}.
|
${this._controller.getMessageString(this.message)}
|
||||||
${this._controller.shouldShowTroubleshootingURL(this.message)
|
${this._controller.shouldShowTroubleshootingURL(this.message)
|
||||||
? html`<a href="${this._controller.getTroubleshootingURL(this.message)}"
|
? html`.
|
||||||
|
<a href="${this._controller.getTroubleshootingURL(this.message)}"
|
||||||
>${localize('error.troubleshooting')}</a
|
>${localize('error.troubleshooting')}</a
|
||||||
>`
|
>`
|
||||||
: ''}
|
: ''}
|
||||||
|
|||||||
@@ -626,6 +626,7 @@
|
|||||||
"failed_response": "No s'ha pogut rebre la resposta de Home Assistant per a la sol·licitud",
|
"failed_response": "No s'ha pogut rebre la resposta de Home Assistant per a la sol·licitud",
|
||||||
"failed_retain": "No s'ha pogut retenir l'esdeveniment",
|
"failed_retain": "No s'ha pogut retenir l'esdeveniment",
|
||||||
"failed_sign": "No s'ha pogut signar l'URL de Home Assistant",
|
"failed_sign": "No s'ha pogut signar l'URL de Home Assistant",
|
||||||
|
"fetching_diagnostics": "",
|
||||||
"image_load_error": "No s'ha pogut carregar la imatge",
|
"image_load_error": "No s'ha pogut carregar la imatge",
|
||||||
"invalid_configuration": "Configuració no vàlida",
|
"invalid_configuration": "Configuració no vàlida",
|
||||||
"invalid_configuration_no_hint": "No hi ha cap indicació d'ubicació disponible (tipus dolent o faltant?)",
|
"invalid_configuration_no_hint": "No hi ha cap indicació d'ubicació disponible (tipus dolent o faltant?)",
|
||||||
@@ -646,6 +647,7 @@
|
|||||||
"no_supported_camera": "",
|
"no_supported_camera": "",
|
||||||
"no_supported_cameras": "",
|
"no_supported_cameras": "",
|
||||||
"reconnecting": "Reconnectant",
|
"reconnecting": "Reconnectant",
|
||||||
|
"stream_not_loading": "",
|
||||||
"too_many_automations": "Hi ha massa trucades d'automatització imbricades, comproveu la vostra configuració per veure si hi ha bucles",
|
"too_many_automations": "Hi ha massa trucades d'automatització imbricades, comproveu la vostra configuració per veure si hi ha bucles",
|
||||||
"troubleshooting": "Comproveu la resolució de problemes",
|
"troubleshooting": "Comproveu la resolució de problemes",
|
||||||
"unknown": "Error desconegut",
|
"unknown": "Error desconegut",
|
||||||
|
|||||||
@@ -626,6 +626,7 @@
|
|||||||
"failed_response": "Failed to receive response from Home Assistant for request",
|
"failed_response": "Failed to receive response from Home Assistant for request",
|
||||||
"failed_retain": "Could not retain event",
|
"failed_retain": "Could not retain event",
|
||||||
"failed_sign": "Could not sign Home Assistant URL",
|
"failed_sign": "Could not sign Home Assistant URL",
|
||||||
|
"fetching_diagnostics": "Fetching diagnostics",
|
||||||
"image_load_error": "The image could not be loaded",
|
"image_load_error": "The image could not be loaded",
|
||||||
"invalid_configuration": "Invalid configuration",
|
"invalid_configuration": "Invalid configuration",
|
||||||
"invalid_configuration_no_hint": "No location hint available (bad or missing type?)",
|
"invalid_configuration_no_hint": "No location hint available (bad or missing type?)",
|
||||||
|
|||||||
@@ -626,6 +626,7 @@
|
|||||||
"failed_response": "Échec de la réponse de Home Assistant à la demande",
|
"failed_response": "Échec de la réponse de Home Assistant à la demande",
|
||||||
"failed_retain": "Impossible de conserver l'événement",
|
"failed_retain": "Impossible de conserver l'événement",
|
||||||
"failed_sign": "Impossible de signer l'URL de Home Assistant",
|
"failed_sign": "Impossible de signer l'URL de Home Assistant",
|
||||||
|
"fetching_diagnostics": "",
|
||||||
"image_load_error": "L'image n'a pas pu être chargée",
|
"image_load_error": "L'image n'a pas pu être chargée",
|
||||||
"invalid_configuration": "Configuration invalide",
|
"invalid_configuration": "Configuration invalide",
|
||||||
"invalid_configuration_no_hint": "Aucune indication de localisation disponible (type incorrect ou manquant ?)",
|
"invalid_configuration_no_hint": "Aucune indication de localisation disponible (type incorrect ou manquant ?)",
|
||||||
@@ -646,6 +647,7 @@
|
|||||||
"no_supported_camera": "La caméra sélectionnée ne prend pas en charge cette vue",
|
"no_supported_camera": "La caméra sélectionnée ne prend pas en charge cette vue",
|
||||||
"no_supported_cameras": "Aucune caméra ne prend en charge cette vue",
|
"no_supported_cameras": "Aucune caméra ne prend en charge cette vue",
|
||||||
"reconnecting": "Reconnexion",
|
"reconnecting": "Reconnexion",
|
||||||
|
"stream_not_loading": "",
|
||||||
"too_many_automations": "Trop d'appels d'automatisation imbriqués, veuillez vérifier votre configuration pour les boucles",
|
"too_many_automations": "Trop d'appels d'automatisation imbriqués, veuillez vérifier votre configuration pour les boucles",
|
||||||
"troubleshooting": "Vérifier le dépannage",
|
"troubleshooting": "Vérifier le dépannage",
|
||||||
"unknown": "Erreur inconnue",
|
"unknown": "Erreur inconnue",
|
||||||
|
|||||||
@@ -626,6 +626,7 @@
|
|||||||
"failed_response": "Impossibile ricevere risposta da Home Assistant per la richiesta",
|
"failed_response": "Impossibile ricevere risposta da Home Assistant per la richiesta",
|
||||||
"failed_retain": "Impossibile conservare l'evento",
|
"failed_retain": "Impossibile conservare l'evento",
|
||||||
"failed_sign": "Impossibile firmare l'URL ad Home Assistant",
|
"failed_sign": "Impossibile firmare l'URL ad Home Assistant",
|
||||||
|
"fetching_diagnostics": "",
|
||||||
"image_load_error": "L'immagine non può essere caricata",
|
"image_load_error": "L'immagine non può essere caricata",
|
||||||
"invalid_configuration": "Configurazione non valida",
|
"invalid_configuration": "Configurazione non valida",
|
||||||
"invalid_configuration_no_hint": "Nessun suggerimento di posizione disponibile (tipo difettoso o mancante?)",
|
"invalid_configuration_no_hint": "Nessun suggerimento di posizione disponibile (tipo difettoso o mancante?)",
|
||||||
@@ -646,6 +647,7 @@
|
|||||||
"no_supported_camera": "",
|
"no_supported_camera": "",
|
||||||
"no_supported_cameras": "",
|
"no_supported_cameras": "",
|
||||||
"reconnecting": "Riconnessione",
|
"reconnecting": "Riconnessione",
|
||||||
|
"stream_not_loading": "",
|
||||||
"too_many_automations": "",
|
"too_many_automations": "",
|
||||||
"troubleshooting": "Controllare la risoluzione dei problemi",
|
"troubleshooting": "Controllare la risoluzione dei problemi",
|
||||||
"unknown": "Errore sconosciuto",
|
"unknown": "Errore sconosciuto",
|
||||||
|
|||||||
@@ -626,6 +626,7 @@
|
|||||||
"failed_response": "Falha ao receber resposta do Home Assistant para solicitação",
|
"failed_response": "Falha ao receber resposta do Home Assistant para solicitação",
|
||||||
"failed_retain": "Não foi possível reter o evento",
|
"failed_retain": "Não foi possível reter o evento",
|
||||||
"failed_sign": "Não foi possível assinar a URL do Home Assistant",
|
"failed_sign": "Não foi possível assinar a URL do Home Assistant",
|
||||||
|
"fetching_diagnostics": "",
|
||||||
"image_load_error": "A imagem não pôde ser carregada",
|
"image_load_error": "A imagem não pôde ser carregada",
|
||||||
"invalid_configuration": "Configuração inválida",
|
"invalid_configuration": "Configuração inválida",
|
||||||
"invalid_configuration_no_hint": "Nenhuma dica de local disponível (tipo incorreto ou ausente?)",
|
"invalid_configuration_no_hint": "Nenhuma dica de local disponível (tipo incorreto ou ausente?)",
|
||||||
@@ -646,6 +647,7 @@
|
|||||||
"no_supported_camera": "",
|
"no_supported_camera": "",
|
||||||
"no_supported_cameras": "",
|
"no_supported_cameras": "",
|
||||||
"reconnecting": "Reconectando",
|
"reconnecting": "Reconectando",
|
||||||
|
"stream_not_loading": "",
|
||||||
"too_many_automations": "",
|
"too_many_automations": "",
|
||||||
"troubleshooting": "Verifique a solução de problemas",
|
"troubleshooting": "Verifique a solução de problemas",
|
||||||
"unknown": "Erro desconhecido",
|
"unknown": "Erro desconhecido",
|
||||||
|
|||||||
@@ -626,6 +626,7 @@
|
|||||||
"failed_response": "Falha ao receber resposta do Home Assistant para solicitação",
|
"failed_response": "Falha ao receber resposta do Home Assistant para solicitação",
|
||||||
"failed_retain": "Não foi possível reter o evento",
|
"failed_retain": "Não foi possível reter o evento",
|
||||||
"failed_sign": "Não foi possível assinar a URL do Home Assistant",
|
"failed_sign": "Não foi possível assinar a URL do Home Assistant",
|
||||||
|
"fetching_diagnostics": "",
|
||||||
"image_load_error": "A imagem não pôde ser carregada",
|
"image_load_error": "A imagem não pôde ser carregada",
|
||||||
"invalid_configuration": "Configuração inválida",
|
"invalid_configuration": "Configuração inválida",
|
||||||
"invalid_configuration_no_hint": "Nenhuma dica de local disponível (tipo incorreto ou ausente?)",
|
"invalid_configuration_no_hint": "Nenhuma dica de local disponível (tipo incorreto ou ausente?)",
|
||||||
@@ -646,6 +647,7 @@
|
|||||||
"no_supported_camera": "",
|
"no_supported_camera": "",
|
||||||
"no_supported_cameras": "",
|
"no_supported_cameras": "",
|
||||||
"reconnecting": "A voltar a ligar",
|
"reconnecting": "A voltar a ligar",
|
||||||
|
"stream_not_loading": "",
|
||||||
"too_many_automations": "",
|
"too_many_automations": "",
|
||||||
"troubleshooting": "Verifique a solução de problemas",
|
"troubleshooting": "Verifique a solução de problemas",
|
||||||
"unknown": "Erro desconhecido",
|
"unknown": "Erro desconhecido",
|
||||||
|
|||||||
Reference in New Issue
Block a user