1 """Button platform for the SABnzbd component."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
7 from pysabnzbd
import SabnzbdApiException
14 from .
import SabnzbdConfigEntry
15 from .const
import DOMAIN
16 from .coordinator
import SabnzbdUpdateCoordinator
17 from .entity
import SabnzbdEntity
20 @dataclass(kw_only=True, frozen=True)
22 """Describes SABnzbd button entity."""
24 press_fn: Callable[[SabnzbdUpdateCoordinator], Any]
27 BUTTON_DESCRIPTIONS: tuple[SabnzbdButtonEntityDescription, ...] = (
30 translation_key=
"pause",
31 press_fn=
lambda coordinator: coordinator.sab_api.pause_queue(),
35 translation_key=
"resume",
36 press_fn=
lambda coordinator: coordinator.sab_api.resume_queue(),
43 entry: SabnzbdConfigEntry,
44 async_add_entities: AddEntitiesCallback,
46 """Set up buttons from a config entry."""
47 coordinator = entry.runtime_data
50 SabnzbdButton(coordinator, description)
for description
in BUTTON_DESCRIPTIONS
55 """Representation of a SABnzbd button."""
57 entity_description: SabnzbdButtonEntityDescription
60 """Handle the button press."""
63 except SabnzbdApiException
as e:
65 translation_domain=DOMAIN,
66 translation_key=
"service_call_exception",
None async_request_refresh(self)