1 """Button entities for the Motionblinds Bluetooth integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable, Coroutine
6 from dataclasses
import dataclass
10 from motionblindsble.device
import MotionDevice
18 from .const
import ATTR_CONNECT, ATTR_DISCONNECT, ATTR_FAVORITE, CONF_MAC_CODE, DOMAIN
19 from .entity
import MotionblindsBLEEntity
21 _LOGGER = logging.getLogger(__name__)
26 @dataclass(frozen=True, kw_only=True)
28 """Entity description of a button entity with command attribute."""
30 command: Callable[[MotionDevice], Coroutine[Any, Any,
None]]
33 BUTTON_TYPES: list[MotionblindsBLEButtonEntityDescription] = [
36 translation_key=ATTR_CONNECT,
37 entity_category=EntityCategory.CONFIG,
38 command=
lambda device: device.connect(),
42 translation_key=ATTR_DISCONNECT,
43 entity_category=EntityCategory.CONFIG,
44 command=
lambda device: device.disconnect(),
48 translation_key=ATTR_FAVORITE,
49 entity_category=EntityCategory.CONFIG,
50 command=
lambda device: device.favorite(),
56 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
58 """Set up button entities based on a config entry."""
60 device: MotionDevice = hass.data[DOMAIN][entry.entry_id]
67 unique_id_suffix=entity_description.key,
69 for entity_description
in BUTTON_TYPES
74 """Representation of a button entity."""
76 entity_description: MotionblindsBLEButtonEntityDescription
79 """Log button entity information."""
81 "(%s) Setting up %s button entity",
82 self.
entryentry.data[CONF_MAC_CODE],
87 """Handle the button press."""