Add button and deprecate service for Fritz cleanup (#63692)

* Revert "Improve availability for Shelly Valve"

This reverts commit d8cbd81b456820153522e6d86bbd00c4a4a31129.

* Add cleanup button

* Wrong commit

* Add service deprecation warning
pull/63708/head
Simone Chemelli 2022-01-08 23:38:28 +01:00 committed by GitHub
parent ec508130d2
commit e3c793718c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -58,6 +58,13 @@ BUTTONS: Final = [
entity_category=ENTITY_CATEGORY_CONFIG, entity_category=ENTITY_CATEGORY_CONFIG,
press_action=lambda avm_device: avm_device.async_trigger_reconnect(), 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(),
),
] ]

View File

@ -385,13 +385,20 @@ class FritzBoxTools(update_coordinator.DataUpdateCoordinator):
"""Trigger device reconnect.""" """Trigger device reconnect."""
await self.hass.async_add_executor_job(self.connection.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.""" """Trigger device trackers cleanup."""
device_hosts_list = await self.hass.async_add_executor_job( device_hosts_list = await self.hass.async_add_executor_job(
self.fritz_hosts.get_hosts_info self.fritz_hosts.get_hosts_info
) )
entity_reg: er.EntityRegistry = er.async_get(self.hass) 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( ha_entity_reg_list: list[er.RegistryEntry] = er.async_entries_for_config_entry(
entity_reg, config_entry.entry_id entity_reg, config_entry.entry_id
) )
@ -471,6 +478,9 @@ class FritzBoxTools(update_coordinator.DataUpdateCoordinator):
return return
if service_call.service == SERVICE_CLEANUP: 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) await self.async_trigger_cleanup(config_entry)
return return