2021-11-23 00:26:37 +00:00
|
|
|
"""Support for Nanoleaf buttons."""
|
|
|
|
|
2023-07-23 02:59:56 +00:00
|
|
|
from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
|
2023-02-09 19:15:37 +00:00
|
|
|
from homeassistant.const import EntityCategory
|
2021-11-23 00:26:37 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
|
2024-06-20 09:08:01 +00:00
|
|
|
from . import NanoleafConfigEntry
|
|
|
|
from .coordinator import NanoleafCoordinator
|
2021-11-23 00:26:37 +00:00
|
|
|
from .entity import NanoleafEntity
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
2024-06-20 09:08:01 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: NanoleafConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
2021-11-23 00:26:37 +00:00
|
|
|
) -> None:
|
|
|
|
"""Set up the Nanoleaf button."""
|
2024-06-20 09:08:01 +00:00
|
|
|
async_add_entities([NanoleafIdentifyButton(entry.runtime_data)])
|
2021-11-23 00:26:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NanoleafIdentifyButton(NanoleafEntity, ButtonEntity):
|
|
|
|
"""Representation of a Nanoleaf identify button."""
|
|
|
|
|
2023-07-23 02:59:56 +00:00
|
|
|
_attr_entity_category = EntityCategory.CONFIG
|
|
|
|
_attr_device_class = ButtonDeviceClass.IDENTIFY
|
|
|
|
|
2024-06-18 17:50:07 +00:00
|
|
|
def __init__(self, coordinator: NanoleafCoordinator) -> None:
|
2021-11-23 00:26:37 +00:00
|
|
|
"""Initialize the Nanoleaf button."""
|
2024-06-18 17:50:07 +00:00
|
|
|
super().__init__(coordinator)
|
|
|
|
self._attr_unique_id = f"{self._nanoleaf.serial_no}_identify"
|
2021-11-23 00:26:37 +00:00
|
|
|
|
|
|
|
async def async_press(self) -> None:
|
|
|
|
"""Identify the Nanoleaf."""
|
|
|
|
await self._nanoleaf.identify()
|