Home Assistant Unofficial Reference 2024.12.1
button.py
Go to the documentation of this file.
1 """Button integration microBees."""
2 
3 from typing import Any
4 
5 from homeassistant.components.button import ButtonEntity
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.entity_platform import AddEntitiesCallback
9 
10 from .const import DOMAIN
11 from .coordinator import MicroBeesUpdateCoordinator
12 from .entity import MicroBeesActuatorEntity
13 
14 BUTTON_TRANSLATIONS = {51: "button_gate", 91: "button_panic"}
15 
16 
18  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
19 ) -> None:
20  """Set up the microBees button platform."""
21  coordinator: MicroBeesUpdateCoordinator = hass.data[DOMAIN][
22  entry.entry_id
23  ].coordinator
25  MBButton(coordinator, bee_id, button.id)
26  for bee_id, bee in coordinator.data.bees.items()
27  if bee.productID in BUTTON_TRANSLATIONS
28  for button in bee.actuators
29  )
30 
31 
33  """Representation of a microBees button."""
34 
35  def __init__(
36  self,
37  coordinator: MicroBeesUpdateCoordinator,
38  bee_id: int,
39  actuator_id: int,
40  ) -> None:
41  """Initialize the microBees button."""
42  super().__init__(coordinator, bee_id, actuator_id)
43  self._attr_translation_key_attr_translation_key = BUTTON_TRANSLATIONS.get(self.beebee.productID)
44 
45  @property
46  def name(self) -> str:
47  """Name of the switch."""
48  return self.actuatoractuator.name
49 
50  async def async_press(self, **kwargs: Any) -> None:
51  """Turn on the button."""
52  await self.coordinator.microbees.sendCommand(
53  self.actuatoractuator.id, self.actuatoractuator.configuration.actuator_timing * 1000
54  )
None __init__(self, MicroBeesUpdateCoordinator coordinator, int bee_id, int actuator_id)
Definition: button.py:40
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: button.py:19