core/homeassistant/components/velbus/button.py

45 lines
1.2 KiB
Python
Raw Normal View History

2022-06-28 16:41:29 +00:00
"""Support for Velbus Buttons."""
2022-06-28 16:41:29 +00:00
from __future__ import annotations
from velbusaio.channels import (
Button as VelbusaioButton,
ButtonCounter as VelbusaioButtonCounter,
)
from homeassistant.components.button import ButtonEntity
from homeassistant.const import EntityCategory
2022-06-28 16:41:29 +00:00
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2022-06-28 16:41:29 +00:00
2024-12-12 19:48:01 +00:00
from . import VelbusConfigEntry
from .entity import VelbusEntity, api_call
2022-06-28 16:41:29 +00:00
PARALLEL_UPDATES = 0
2022-06-28 16:41:29 +00:00
async def async_setup_entry(
hass: HomeAssistant,
2024-12-12 19:48:01 +00:00
entry: VelbusConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
2022-06-28 16:41:29 +00:00
) -> None:
"""Set up Velbus switch based on config_entry."""
await entry.runtime_data.scan_task
2024-12-12 19:48:01 +00:00
async_add_entities(
VelbusButton(channel)
for channel in entry.runtime_data.controller.get_all_button()
)
2022-06-28 16:41:29 +00:00
class VelbusButton(VelbusEntity, ButtonEntity):
"""Representation of a Velbus Binary Sensor."""
_channel: VelbusaioButton | VelbusaioButtonCounter
_attr_entity_registry_enabled_default = False
_attr_entity_category = EntityCategory.CONFIG
@api_call
2022-06-28 16:41:29 +00:00
async def async_press(self) -> None:
"""Handle the button press."""
await self._channel.press()