Home Assistant Unofficial Reference 2024.12.1
button.py
Go to the documentation of this file.
1 """Representation of a toggleButton."""
2 
3 from homeassistant.components.button import ButtonEntity
4 from homeassistant.config_entries import ConfigEntry
5 from homeassistant.core import HomeAssistant, callback
6 from homeassistant.helpers.dispatcher import async_dispatcher_connect
7 from homeassistant.helpers.entity_platform import AddEntitiesCallback
8 
9 from .const import DOMAIN, ZWaveMePlatform
10 from .entity import ZWaveMeEntity
11 
12 DEVICE_NAME = ZWaveMePlatform.BUTTON
13 
14 
16  hass: HomeAssistant,
17  config_entry: ConfigEntry,
18  async_add_entities: AddEntitiesCallback,
19 ) -> None:
20  """Set up the number platform."""
21 
22  @callback
23  def add_new_device(new_device):
24  controller = hass.data[DOMAIN][config_entry.entry_id]
25  button = ZWaveMeButton(controller, new_device)
26 
28  [
29  button,
30  ]
31  )
32 
33  config_entry.async_on_unload(
35  hass, f"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
36  )
37  )
38 
39 
41  """Representation of a ZWaveMe button."""
42 
43  def press(self) -> None:
44  """Turn the entity on."""
45  self.controllercontroller.zwave_api.send_command(self.devicedevice.id, "on")
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: button.py:19
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103