@@ -185,14 +185,8 @@ def update(
185185 if automatic_backups_configured is not UNDEFINED :
186186 self .data .automatic_backups_configured = automatic_backups_configured
187187 if create_backup is not UNDEFINED :
188- if (new_agent_ids := create_backup .get ("agent_ids" , [])) and (
189- discarded_agent_ids := set (self .data .create_backup .agent_ids )
190- - set (new_agent_ids )
191- ):
192- for agent_id in discarded_agent_ids :
193- delete_automatic_backup_agents_unavailable_issue (
194- self ._hass , agent_id
195- )
188+ if new_agent_ids := create_backup .get ("agent_ids" ):
189+ check_unavailable_agents (self ._hass , self ._manager , new_agent_ids )
196190 self .data .create_backup = replace (self .data .create_backup , ** create_backup )
197191 if retention is not UNDEFINED :
198192 new_retention = RetentionConfig (** retention )
@@ -576,6 +570,35 @@ def _delete_filter(
576570 )
577571
578572
573+ @callback
574+ def check_unavailable_agents (
575+ hass : HomeAssistant , manager : BackupManager , new_agent_ids : list [str ] | None = None
576+ ) -> None :
577+ """Check for unavailable agents."""
578+ if missing_agent_ids := set (manager .config .data .create_backup .agent_ids ) - set (
579+ manager .backup_agents
580+ ):
581+ LOGGER .debug (
582+ "Agents %s are configured for automatic backup but are not loaded" ,
583+ missing_agent_ids ,
584+ )
585+ for agent_id in missing_agent_ids :
586+ create_automatic_backup_agents_unavailable_issue (hass , agent_id )
587+
588+ # Remove any issues for agents that are now loaded
589+ for agent_id in manager .backup_agents :
590+ delete_automatic_backup_agents_unavailable_issue (hass , agent_id )
591+
592+ if new_agent_ids is None :
593+ return
594+
595+ # Remove issues for agents that are no longer configured
596+ for agent_id in set (manager .config .data .create_backup .agent_ids ) - set (
597+ new_agent_ids
598+ ):
599+ delete_automatic_backup_agents_unavailable_issue (hass , agent_id )
600+
601+
579602@callback
580603def create_automatic_backup_agents_unavailable_issue (
581604 hass : HomeAssistant , agent_id : str
0 commit comments