"""Button platform for groqd — provides a 'Clear session memory' button.""" from __future__ import annotations from homeassistant.components.button import ButtonEntity from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers import device_registry as dr from . import GroqdConfigEntry from .const import DOMAIN, LOGGER async def async_setup_entry( hass: HomeAssistant, config_entry: GroqdConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up groqd button entities.""" async_add_entities([GroqdClearMemoryButton(config_entry)]) class GroqdClearMemoryButton(ButtonEntity): """Button that wipes all persisted conversation history for this entry.""" _attr_has_entity_name = True _attr_translation_key = "clear_memory" def __init__(self, entry: GroqdConfigEntry) -> None: self._entry = entry self._attr_unique_id = f"{entry.entry_id}_clear_memory" self._attr_device_info = dr.DeviceInfo( identifiers={(DOMAIN, entry.entry_id)}, ) async def async_press(self) -> None: """Handle button press — delegate to the conversation agent.""" agent = self._entry.runtime_data.conversation_agent if agent is not None: await agent.async_clear_memory() LOGGER.info("groqd: clear memory button pressed for entry %s", self._entry.entry_id) else: LOGGER.warning("groqd: clear memory pressed but conversation agent not ready")