mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Migrate esphome button platform to use _on_static_info_update (#95007)
This commit is contained in:
parent
8d2daaa694
commit
235f50a341
@ -1,7 +1,7 @@
|
|||||||
"""Support for ESPHome buttons."""
|
"""Support for ESPHome buttons."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from aioesphomeapi import ButtonInfo, EntityState
|
from aioesphomeapi import ButtonInfo, EntityInfo, EntityState
|
||||||
|
|
||||||
from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
|
from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -30,10 +30,13 @@ async def async_setup_entry(
|
|||||||
class EsphomeButton(EsphomeEntity[ButtonInfo, EntityState], ButtonEntity):
|
class EsphomeButton(EsphomeEntity[ButtonInfo, EntityState], ButtonEntity):
|
||||||
"""A button implementation for ESPHome."""
|
"""A button implementation for ESPHome."""
|
||||||
|
|
||||||
@property
|
@callback
|
||||||
def device_class(self) -> ButtonDeviceClass | None:
|
def _on_static_info_update(self, static_info: EntityInfo) -> None:
|
||||||
"""Return the class of this entity."""
|
"""Set attrs from static info."""
|
||||||
return try_parse_enum(ButtonDeviceClass, self._static_info.device_class)
|
super()._on_static_info_update(static_info)
|
||||||
|
self._attr_device_class = try_parse_enum(
|
||||||
|
ButtonDeviceClass, self._static_info.device_class
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _on_device_update(self) -> None:
|
def _on_device_update(self) -> None:
|
||||||
@ -44,4 +47,4 @@ class EsphomeButton(EsphomeEntity[ButtonInfo, EntityState], ButtonEntity):
|
|||||||
|
|
||||||
async def async_press(self) -> None:
|
async def async_press(self) -> None:
|
||||||
"""Press the button."""
|
"""Press the button."""
|
||||||
await self._client.button_command(self._static_info.key)
|
await self._client.button_command(self._key)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user