Esphome/button (#60522)

This commit is contained in:
Jesse Hills 2021-11-29 21:57:37 +13:00 committed by GitHub
parent e5718ccac4
commit 622d9606a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 3 deletions

View File

@ -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

View 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)

View File

@ -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",

View File

@ -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"],

View File

@ -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

View File

@ -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