Periodically refresh alerts on the device page (#25385)

* Periodically refresh alerts on the device page

* Update src/panels/config/devices/ha-config-device-page.ts

Co-authored-by: Bram Kragten <mail@bramkragten.nl>

* revert type change

* Apply suggestions from code review

Co-authored-by: Bram Kragten <mail@bramkragten.nl>

---------

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Petar Petrov 2025-05-14 12:28:56 +03:00 committed by GitHub
parent d0e55719d1
commit 4b270eb444
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -107,6 +107,8 @@ export interface DeviceAlert {
text: string; text: string;
} }
const DEVICE_ALERTS_INTERVAL = 30000;
@customElement("ha-config-device-page") @customElement("ha-config-device-page")
export class HaConfigDevicePage extends LitElement { export class HaConfigDevicePage extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@ -134,6 +136,8 @@ export class HaConfigDevicePage extends LitElement {
@state() private _deviceAlerts?: DeviceAlert[]; @state() private _deviceAlerts?: DeviceAlert[];
private _deviceAlertsTimeout?: number;
@state() @state()
@consume({ context: fullEntitiesContext, subscribe: true }) @consume({ context: fullEntitiesContext, subscribe: true })
_entityReg!: EntityRegistryEntry[]; _entityReg!: EntityRegistryEntry[];
@ -280,6 +284,7 @@ export class HaConfigDevicePage extends LitElement {
this._getDiagnosticButtons(this._diagnosticDownloadLinks); this._getDiagnosticButtons(this._diagnosticDownloadLinks);
this._getDeleteActions(); this._getDeleteActions();
this._getDeviceActions(); this._getDeviceActions();
clearTimeout(this._deviceAlertsTimeout);
this._getDeviceAlerts(); this._getDeviceAlerts();
} }
@ -295,6 +300,11 @@ export class HaConfigDevicePage extends LitElement {
} }
} }
public disconnectedCallback() {
super.disconnectedCallback();
clearTimeout(this._deviceAlertsTimeout);
}
protected render() { protected render() {
if (!this.hass || !this.deviceId) { if (!this.hass || !this.deviceId) {
return nothing; return nothing;
@ -1153,6 +1163,10 @@ export class HaConfigDevicePage extends LitElement {
if (deviceAlerts.length) { if (deviceAlerts.length) {
this._deviceAlerts = deviceAlerts; this._deviceAlerts = deviceAlerts;
this._deviceAlertsTimeout = window.setTimeout(
() => this._getDeviceAlerts(),
DEVICE_ALERTS_INTERVAL
);
} }
} }