1 """Support for ESPHome buttons."""
3 from __future__
import annotations
5 from functools
import partial
7 from aioesphomeapi
import ButtonInfo, EntityInfo, EntityState
15 convert_api_error_ha_error,
16 platform_async_setup_entry,
21 """A button implementation for ESPHome."""
25 """Set attrs from static info."""
28 ButtonDeviceClass, self.
_static_info_static_info.device_class
33 """Call when device updates or entry data changes.
35 The default behavior is only to write entity state when the
36 device is unavailable when the device state changes.
37 This method overrides the default behavior since buttons do
38 not have a state, so we will never get a state update for a
39 button. As such, we need to write the state on every device
40 update to ensure the button goes available and unavailable
41 as the device becomes available or unavailable.
46 @convert_api_error_ha_error
48 """Press the button."""
52 async_setup_entry = partial(
53 platform_async_setup_entry,
55 entity_type=EsphomeButton,
56 state_type=EntityState,
None _on_entry_data_changed(self)
None async_write_ha_state(self)