Home Assistant Unofficial Reference 2024.12.1
button.py
Go to the documentation of this file.
1 """Support for WLED button."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
6 from homeassistant.const import EntityCategory
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.entity_platform import AddEntitiesCallback
9 
10 from . import WLEDConfigEntry
11 from .coordinator import WLEDDataUpdateCoordinator
12 from .entity import WLEDEntity
13 from .helpers import wled_exception_handler
14 
15 
17  hass: HomeAssistant,
18  entry: WLEDConfigEntry,
19  async_add_entities: AddEntitiesCallback,
20 ) -> None:
21  """Set up WLED button based on a config entry."""
22  async_add_entities([WLEDRestartButton(entry.runtime_data)])
23 
24 
26  """Defines a WLED restart button."""
27 
28  _attr_device_class = ButtonDeviceClass.RESTART
29  _attr_entity_category = EntityCategory.CONFIG
30 
31  def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
32  """Initialize the button entity."""
33  super().__init__(coordinator=coordinator)
34  self._attr_unique_id_attr_unique_id = f"{coordinator.data.info.mac_address}_restart"
35 
36  @wled_exception_handler
37  async def async_press(self) -> None:
38  """Send out a restart command."""
39  await self.coordinator.wled.reset()
None __init__(self, WLEDDataUpdateCoordinator coordinator)
Definition: button.py:31
None async_setup_entry(HomeAssistant hass, WLEDConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: button.py:20