mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Fix alerts refresh on device page (#25748)
* Fix alerts refresh on device page * don't reset actions periodically * reset stuff only on deviceId change
This commit is contained in:
parent
21af10fd28
commit
af6911e848
@ -127,16 +127,15 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
|
|
||||||
@state() private _related?: RelatedResult;
|
@state() private _related?: RelatedResult;
|
||||||
|
|
||||||
// If a number, it's the request ID so we make sure we don't show older info
|
@state() private _diagnosticDownloadLinks: DeviceAction[] = [];
|
||||||
@state() private _diagnosticDownloadLinks?: number | DeviceAction[];
|
|
||||||
|
|
||||||
@state() private _deleteButtons?: DeviceAction[];
|
@state() private _deleteButtons: DeviceAction[] = [];
|
||||||
|
|
||||||
@state() private _deviceActions?: DeviceAction[];
|
@state() private _deviceActions: DeviceAction[] = [];
|
||||||
|
|
||||||
@state() private _deviceAlerts?: DeviceAlert[];
|
@state() private _deviceAlerts: DeviceAlert[] = [];
|
||||||
|
|
||||||
private _deviceAlertsTimeout?: number;
|
private _deviceAlertsActionsTimeout?: number;
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
@consume({ context: fullEntitiesContext, subscribe: true })
|
@consume({ context: fullEntitiesContext, subscribe: true })
|
||||||
@ -255,42 +254,19 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
public willUpdate(changedProps) {
|
public willUpdate(changedProps) {
|
||||||
super.willUpdate(changedProps);
|
super.willUpdate(changedProps);
|
||||||
|
|
||||||
if (
|
if (changedProps.has("deviceId") || changedProps.has("entries")) {
|
||||||
changedProps.has("deviceId") ||
|
this._deviceActions = [];
|
||||||
changedProps.has("devices") ||
|
this._deviceAlerts = [];
|
||||||
changedProps.has("entries")
|
this._deleteButtons = [];
|
||||||
) {
|
this._diagnosticDownloadLinks = [];
|
||||||
this._diagnosticDownloadLinks = undefined;
|
this._fetchData();
|
||||||
this._deleteButtons = undefined;
|
|
||||||
this._deviceActions = undefined;
|
|
||||||
this._deviceAlerts = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
(this._diagnosticDownloadLinks &&
|
|
||||||
this._deleteButtons &&
|
|
||||||
this._deviceActions &&
|
|
||||||
this._deviceAlerts) ||
|
|
||||||
!this.deviceId ||
|
|
||||||
!this.entries
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._diagnosticDownloadLinks = Math.random();
|
|
||||||
this._deleteButtons = []; // To prevent re-rendering if no delete buttons
|
|
||||||
this._deviceActions = [];
|
|
||||||
this._deviceAlerts = [];
|
|
||||||
this._getDiagnosticButtons(this._diagnosticDownloadLinks);
|
|
||||||
this._getDeleteActions();
|
|
||||||
this._getDeviceActions();
|
|
||||||
clearTimeout(this._deviceAlertsTimeout);
|
|
||||||
this._getDeviceAlerts();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected firstUpdated(changedProps) {
|
protected firstUpdated(changedProps) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
loadDeviceRegistryDetailDialog();
|
loadDeviceRegistryDetailDialog();
|
||||||
|
this._fetchData();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProps) {
|
protected updated(changedProps) {
|
||||||
@ -302,7 +278,7 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
|
|
||||||
public disconnectedCallback() {
|
public disconnectedCallback() {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
clearTimeout(this._deviceAlertsTimeout);
|
clearTimeout(this._deviceAlertsActionsTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
@ -909,7 +885,18 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
</hass-subpage>`;
|
</hass-subpage>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getDiagnosticButtons(requestId: number): Promise<void> {
|
private _fetchData() {
|
||||||
|
if (this.deviceId && this.entries.length) {
|
||||||
|
this._getDiagnosticButtons();
|
||||||
|
this._getDeleteActions();
|
||||||
|
clearTimeout(this._deviceAlertsActionsTimeout);
|
||||||
|
this._getDeviceActions();
|
||||||
|
this._getDeviceAlerts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _getDiagnosticButtons(): Promise<void> {
|
||||||
|
const deviceId = this.deviceId;
|
||||||
if (!isComponentLoaded(this.hass, "diagnostics")) {
|
if (!isComponentLoaded(this.hass, "diagnostics")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -951,7 +938,8 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
|
|
||||||
links = links.filter(Boolean);
|
links = links.filter(Boolean);
|
||||||
|
|
||||||
if (this._diagnosticDownloadLinks !== requestId) {
|
if (this.deviceId !== deviceId) {
|
||||||
|
// abort if the device has changed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (links.length > 0) {
|
if (links.length > 0) {
|
||||||
@ -1176,12 +1164,12 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
deviceAlerts.push(...alerts);
|
deviceAlerts.push(...alerts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._deviceAlerts = deviceAlerts;
|
||||||
if (deviceAlerts.length) {
|
if (deviceAlerts.length) {
|
||||||
this._deviceAlerts = deviceAlerts;
|
this._deviceAlertsActionsTimeout = window.setTimeout(() => {
|
||||||
this._deviceAlertsTimeout = window.setTimeout(
|
this._getDeviceAlerts();
|
||||||
() => this._getDeviceAlerts(),
|
this._getDeviceActions();
|
||||||
DEVICE_ALERTS_INTERVAL
|
}, DEVICE_ALERTS_INTERVAL);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user