diff --git a/homeassistant/components/fritz/button.py b/homeassistant/components/fritz/button.py index 2ec1b2dba33..3ca54de9577 100644 --- a/homeassistant/components/fritz/button.py +++ b/homeassistant/components/fritz/button.py @@ -58,6 +58,13 @@ BUTTONS: Final = [ entity_category=ENTITY_CATEGORY_CONFIG, press_action=lambda avm_device: avm_device.async_trigger_reconnect(), ), + FritzButtonDescription( + key="cleanup", + name="Cleanup", + icon="mdi:broom", + entity_category=ENTITY_CATEGORY_CONFIG, + press_action=lambda avm_device: avm_device.async_trigger_cleanup(), + ), ] diff --git a/homeassistant/components/fritz/common.py b/homeassistant/components/fritz/common.py index d70118c9c43..fdab1739ec9 100644 --- a/homeassistant/components/fritz/common.py +++ b/homeassistant/components/fritz/common.py @@ -385,13 +385,20 @@ class FritzBoxTools(update_coordinator.DataUpdateCoordinator): """Trigger device reconnect.""" await self.hass.async_add_executor_job(self.connection.reconnect) - async def async_trigger_cleanup(self, config_entry: ConfigEntry) -> None: + async def async_trigger_cleanup( + self, config_entry: ConfigEntry | None = None + ) -> None: """Trigger device trackers cleanup.""" device_hosts_list = await self.hass.async_add_executor_job( self.fritz_hosts.get_hosts_info ) entity_reg: er.EntityRegistry = er.async_get(self.hass) + if config_entry is None: + if self.config_entry is None: + return + config_entry = self.config_entry + ha_entity_reg_list: list[er.RegistryEntry] = er.async_entries_for_config_entry( entity_reg, config_entry.entry_id ) @@ -471,6 +478,9 @@ class FritzBoxTools(update_coordinator.DataUpdateCoordinator): return if service_call.service == SERVICE_CLEANUP: + _LOGGER.warning( + 'Service "fritz.cleanup" is deprecated, please use the corresponding button entity instead' + ) await self.async_trigger_cleanup(config_entry) return