Add button entity (#1114)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Franck Nijhof 2021-11-04 16:53:40 +01:00 committed by GitHub
parent 36227ec01b
commit 6f087f84ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,40 @@
---
title: Button Entity
sidebar_label: Button
---
A button entity is an entity that can fire an event / trigger an action towards a device or service but remains stateless from the Home Assistant perspective.
It can be compared to a real live momentary switch, push-button, or some other form of a stateless switch. It is, however, not suitable for implementing actual physical buttons; the sole purpose of a button entity is to provide a virtual button inside Home Assistant.
A switch button entity is derived from the [`homeassistant.components.button.ButtonEntity`](https://github.com/home-assistant/core/blob/dev/homeassistant/components/button/__init__.py),
and can be helpful for controlling device features like (but not limited to):
- Upgrading firmware
- Reboot/Restart a device
- Brew a cup of coffee
- Reset something (like a counter, filter usage)
If you want to represent something that can be turned on and off (and thus have an actual state), you should use a `switch` entity instead. If you want to integrate a real, physical, stateless button device in Home Assistant, you can do so by firing custom events. The entity button entity isn't suitable for these cases.
## Properties
As this integration is stateless, it doesn't provide any specific properties for itself.
Other properties that are common to all entities such as `icon`, `name` etc are still applicable.
## Methods
### Press
The press method can be used to trigger an action towards a device or service.
It is called by Home Assistant when the user presses the button or the
service to press the button has been called.
```python
class MyButton(ButtonEntity):
# Implement one of these methods.
def press(self) -> None:
"""Handle the button press."""
```