35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""Reboot button of a ninlight lamp. A factory reset is deliberately not offered."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
|
|
from homeassistant.const import EntityCategory
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|
|
|
from .coordinator import NinlightConfigEntry, NinlightCoordinator
|
|
from .entity import NinlightEntity
|
|
|
|
PARALLEL_UPDATES = 0
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: NinlightConfigEntry,
|
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
|
) -> None:
|
|
async_add_entities([NinlightRebootButton(entry.runtime_data)])
|
|
|
|
|
|
class NinlightRebootButton(NinlightEntity, ButtonEntity):
|
|
"""Restart the lamp."""
|
|
|
|
_attr_device_class = ButtonDeviceClass.RESTART
|
|
_attr_entity_category = EntityCategory.CONFIG
|
|
|
|
def __init__(self, coordinator: NinlightCoordinator) -> None:
|
|
super().__init__(coordinator, "reboot")
|
|
|
|
async def async_press(self) -> None:
|
|
await self.coordinator.async_call(lambda client: client.reboot())
|