mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
![Dave T](/assets/img/avatar_default.png)
* Fix missing refactors of EntityCategory.XXX * Fix entity_category refactor for homewizard
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""ONVIF Buttons."""
|
|
|
|
from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity import EntityCategory
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .base import ONVIFBaseEntity
|
|
from .const import DOMAIN
|
|
from .device import ONVIFDevice
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
config_entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up ONVIF button based on a config entry."""
|
|
device = hass.data[DOMAIN][config_entry.unique_id]
|
|
async_add_entities([RebootButton(device)])
|
|
|
|
|
|
class RebootButton(ONVIFBaseEntity, ButtonEntity):
|
|
"""Defines a ONVIF reboot button."""
|
|
|
|
_attr_device_class = ButtonDeviceClass.RESTART
|
|
_attr_entity_category = EntityCategory.CONFIG
|
|
|
|
def __init__(self, device: ONVIFDevice) -> None:
|
|
"""Initialize the button entity."""
|
|
super().__init__(device)
|
|
self._attr_name = f"{self.device.name} Reboot"
|
|
self._attr_unique_id = (
|
|
f"{self.device.info.mac or self.device.info.serial_number}_reboot"
|
|
)
|
|
|
|
async def async_press(self) -> None:
|
|
"""Send out a SystemReboot command."""
|
|
device_mgmt = self.device.device.create_devicemgmt_service()
|
|
await device_mgmt.SystemReboot()
|