mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Esphome/button (#60522)
This commit is contained in:
parent
e5718ccac4
commit
622d9606a5
@ -286,6 +286,7 @@ omit =
|
||||
homeassistant/components/eq3btsmart/climate.py
|
||||
homeassistant/components/esphome/__init__.py
|
||||
homeassistant/components/esphome/binary_sensor.py
|
||||
homeassistant/components/esphome/button.py
|
||||
homeassistant/components/esphome/camera.py
|
||||
homeassistant/components/esphome/climate.py
|
||||
homeassistant/components/esphome/cover.py
|
||||
|
44
homeassistant/components/esphome/button.py
Normal file
44
homeassistant/components/esphome/button.py
Normal file
@ -0,0 +1,44 @@
|
||||
"""Support for ESPHome buttons."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from aioesphomeapi import ButtonInfo
|
||||
from aioesphomeapi.model import EntityState
|
||||
|
||||
from homeassistant.components.button import ButtonEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import EsphomeEntity, platform_async_setup_entry
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up ESPHome buttons based on a config entry."""
|
||||
await platform_async_setup_entry(
|
||||
hass,
|
||||
entry,
|
||||
async_add_entities,
|
||||
component_key="button",
|
||||
info_type=ButtonInfo,
|
||||
entity_type=EsphomeButton,
|
||||
state_type=EntityState,
|
||||
)
|
||||
|
||||
|
||||
class EsphomeButton(EsphomeEntity[ButtonInfo, EntityState], ButtonEntity):
|
||||
"""A button implementation for ESPHome."""
|
||||
|
||||
@callback
|
||||
def _on_device_update(self) -> None:
|
||||
"""Update the entity state when device info has changed."""
|
||||
# This override the EsphomeEntity method as the button entity
|
||||
# never gets a state update.
|
||||
self._on_state_update()
|
||||
|
||||
async def async_press(self, **kwargs: Any) -> None:
|
||||
"""Press the button."""
|
||||
await self._client.button_command(self._static_info.key)
|
@ -26,6 +26,7 @@ from aioesphomeapi import (
|
||||
TextSensorInfo,
|
||||
UserService,
|
||||
)
|
||||
from aioesphomeapi.model import ButtonInfo
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
@ -37,6 +38,7 @@ SAVE_DELAY = 120
|
||||
# Mapping from ESPHome info type to HA platform
|
||||
INFO_TYPE_TO_PLATFORM: dict[type[EntityInfo], str] = {
|
||||
BinarySensorInfo: "binary_sensor",
|
||||
ButtonInfo: "button",
|
||||
CameraInfo: "camera",
|
||||
ClimateInfo: "climate",
|
||||
CoverInfo: "cover",
|
||||
|
@ -3,7 +3,7 @@
|
||||
"name": "ESPHome",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/esphome",
|
||||
"requirements": ["aioesphomeapi==10.2.0"],
|
||||
"requirements": ["aioesphomeapi==10.3.0"],
|
||||
"zeroconf": ["_esphomelib._tcp.local."],
|
||||
"codeowners": ["@OttoWinter", "@jesserockz"],
|
||||
"after_dependencies": ["zeroconf", "tag"],
|
||||
|
@ -161,7 +161,7 @@ aioeagle==1.1.0
|
||||
aioemonitor==1.0.5
|
||||
|
||||
# homeassistant.components.esphome
|
||||
aioesphomeapi==10.2.0
|
||||
aioesphomeapi==10.3.0
|
||||
|
||||
# homeassistant.components.flo
|
||||
aioflo==0.4.1
|
||||
|
@ -112,7 +112,7 @@ aioeagle==1.1.0
|
||||
aioemonitor==1.0.5
|
||||
|
||||
# homeassistant.components.esphome
|
||||
aioesphomeapi==10.2.0
|
||||
aioesphomeapi==10.3.0
|
||||
|
||||
# homeassistant.components.flo
|
||||
aioflo==0.4.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user