"""BleBox button entities implementation.""" import blebox_uniapi.button from homeassistant.components.button import ButtonEntity from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from . import BleBoxConfigEntry from .coordinator import BleBoxCoordinator from .entity import BleBoxEntity from .util import blebox_command PARALLEL_UPDATES = 1 async def async_setup_entry( hass: HomeAssistant, config_entry: BleBoxConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up a BleBox button entry.""" coordinator = config_entry.runtime_data entities = [ BleBoxButtonEntity(coordinator, feature) for feature in coordinator.box.features.get("buttons", []) ] async_add_entities(entities) class BleBoxButtonEntity(BleBoxEntity[blebox_uniapi.button.Button], ButtonEntity): """Representation of BleBox buttons.""" def __init__( self, coordinator: BleBoxCoordinator, feature: blebox_uniapi.button.Button ) -> None: """Initialize a BleBox button feature.""" super().__init__(coordinator, feature) self._attr_icon = self.get_icon() def get_icon(self) -> str | None: """Return icon for endpoint.""" if "up" in self._feature.query_string: return "mdi:arrow-up-circle" if "down" in self._feature.query_string: return "mdi:arrow-down-circle" if "fav" in self._feature.query_string: return "mdi:heart-circle" if "open" in self._feature.query_string: return "mdi:arrow-up-circle" if "close" in self._feature.query_string: return "mdi:arrow-down-circle" return None @blebox_command async def async_press(self) -> None: """Handle the button press.""" await self._feature.set()