mirror of
https://github.com/home-assistant/core.git
synced 2026-07-05 05:35:29 +01:00
bde3b6e59f
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""Button platform for the Helty Flow integration."""
|
|
|
|
from pyhelty import HeltyError
|
|
|
|
from homeassistant.components.button import ButtonEntity
|
|
from homeassistant.const import EntityCategory
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import HomeAssistantError
|
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import HeltyConfigEntry, HeltyDataUpdateCoordinator
|
|
from .entity import HeltyEntity
|
|
|
|
PARALLEL_UPDATES = 0
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: HeltyConfigEntry,
|
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
|
) -> None:
|
|
"""Set up the Helty buttons."""
|
|
async_add_entities([HeltyResetFilterButton(entry.runtime_data)])
|
|
|
|
|
|
class HeltyResetFilterButton(HeltyEntity, ButtonEntity):
|
|
"""Resets the filter-life counter after the filter has been replaced."""
|
|
|
|
_attr_entity_category = EntityCategory.CONFIG
|
|
_attr_translation_key = "reset_filter"
|
|
|
|
def __init__(self, coordinator: HeltyDataUpdateCoordinator) -> None:
|
|
"""Initialize the button."""
|
|
super().__init__(coordinator)
|
|
self._attr_unique_id = f"{self._device_id}_reset_filter"
|
|
|
|
async def async_press(self) -> None:
|
|
"""Reset the filter-life counter."""
|
|
try:
|
|
await self.coordinator.client.async_reset_filter()
|
|
except HeltyError as err:
|
|
raise HomeAssistantError(
|
|
translation_domain=DOMAIN,
|
|
translation_key="reset_filter_failed",
|
|
) from err
|
|
await self.coordinator.async_request_refresh()
|