mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Add button for yale_smart_alarm (#70813)
This commit is contained in:
parent
fbbfdeae39
commit
84f38578e9
@ -1447,6 +1447,7 @@ omit =
|
|||||||
homeassistant/components/yale_smart_alarm/__init__.py
|
homeassistant/components/yale_smart_alarm/__init__.py
|
||||||
homeassistant/components/yale_smart_alarm/alarm_control_panel.py
|
homeassistant/components/yale_smart_alarm/alarm_control_panel.py
|
||||||
homeassistant/components/yale_smart_alarm/binary_sensor.py
|
homeassistant/components/yale_smart_alarm/binary_sensor.py
|
||||||
|
homeassistant/components/yale_smart_alarm/button.py
|
||||||
homeassistant/components/yale_smart_alarm/const.py
|
homeassistant/components/yale_smart_alarm/const.py
|
||||||
homeassistant/components/yale_smart_alarm/coordinator.py
|
homeassistant/components/yale_smart_alarm/coordinator.py
|
||||||
homeassistant/components/yale_smart_alarm/diagnostics.py
|
homeassistant/components/yale_smart_alarm/diagnostics.py
|
||||||
|
60
homeassistant/components/yale_smart_alarm/button.py
Normal file
60
homeassistant/components/yale_smart_alarm/button.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
"""Support for Yale Smart Alarm button."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_NAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from .const import COORDINATOR, DOMAIN
|
||||||
|
from .coordinator import YaleDataUpdateCoordinator
|
||||||
|
from .entity import YaleAlarmEntity
|
||||||
|
|
||||||
|
BUTTON_TYPES = (
|
||||||
|
ButtonEntityDescription(key="panic", name="Panic Button", icon="mdi:alarm-light"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up the button from a config entry."""
|
||||||
|
|
||||||
|
coordinator: YaleDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
||||||
|
COORDINATOR
|
||||||
|
]
|
||||||
|
|
||||||
|
async_add_entities(
|
||||||
|
[YalePanicButton(coordinator, description) for description in BUTTON_TYPES]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class YalePanicButton(YaleAlarmEntity, ButtonEntity):
|
||||||
|
"""A Panic button for Yale Smart Alarm."""
|
||||||
|
|
||||||
|
entity_description: ButtonEntityDescription
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: YaleDataUpdateCoordinator,
|
||||||
|
description: ButtonEntityDescription,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the plug switch."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
self.entity_description = description
|
||||||
|
self._attr_name = f"{coordinator.entry.data[CONF_NAME]} {description.name}"
|
||||||
|
self._attr_unique_id = f"yale_smart_alarm-{description.key}"
|
||||||
|
|
||||||
|
async def async_press(self, **kwargs: Any) -> None:
|
||||||
|
"""Press the button."""
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert self.coordinator.yale, "Connection to API is missing"
|
||||||
|
|
||||||
|
await self.hass.async_add_executor_job(
|
||||||
|
self.coordinator.yale.trigger_panic_button
|
||||||
|
)
|
@ -34,7 +34,12 @@ LOGGER = logging.getLogger(__package__)
|
|||||||
ATTR_ONLINE = "online"
|
ATTR_ONLINE = "online"
|
||||||
ATTR_STATUS = "status"
|
ATTR_STATUS = "status"
|
||||||
|
|
||||||
PLATFORMS = [Platform.ALARM_CONTROL_PANEL, Platform.BINARY_SENSOR, Platform.LOCK]
|
PLATFORMS = [
|
||||||
|
Platform.ALARM_CONTROL_PANEL,
|
||||||
|
Platform.BINARY_SENSOR,
|
||||||
|
Platform.BUTTON,
|
||||||
|
Platform.LOCK,
|
||||||
|
]
|
||||||
|
|
||||||
STATE_MAP = {
|
STATE_MAP = {
|
||||||
YALE_STATE_DISARM: STATE_ALARM_DISARMED,
|
YALE_STATE_DISARM: STATE_ALARM_DISARMED,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user