Home Assistant Unofficial Reference 2024.12.1
button.py
Go to the documentation of this file.
1 """ONVIF Buttons."""
2 
3 from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
4 from homeassistant.config_entries import ConfigEntry
5 from homeassistant.const import EntityCategory
6 from homeassistant.core import HomeAssistant
7 from homeassistant.helpers.entity_platform import AddEntitiesCallback
8 
9 from .const import DOMAIN
10 from .device import ONVIFDevice
11 from .entity import ONVIFBaseEntity
12 
13 
15  hass: HomeAssistant,
16  config_entry: ConfigEntry,
17  async_add_entities: AddEntitiesCallback,
18 ) -> None:
19  """Set up ONVIF button based on a config entry."""
20  device = hass.data[DOMAIN][config_entry.unique_id]
22 
23 
25  """Defines a ONVIF reboot button."""
26 
27  _attr_device_class = ButtonDeviceClass.RESTART
28  _attr_entity_category = EntityCategory.CONFIG
29 
30  def __init__(self, device: ONVIFDevice) -> None:
31  """Initialize the button entity."""
32  super().__init__(device)
33  self._attr_name_attr_name = f"{self.device.name} Reboot"
34  self._attr_unique_id_attr_unique_id = f"{self.mac_or_serial}_reboot"
35 
36  async def async_press(self) -> None:
37  """Send out a SystemReboot command."""
38  device_mgmt = await self.device.device.create_devicemgmt_service()
39  await device_mgmt.SystemReboot()
40 
41 
43  """Defines a ONVIF SetSystemDateAndTime button."""
44 
45  _attr_entity_category = EntityCategory.CONFIG
46 
47  def __init__(self, device: ONVIFDevice) -> None:
48  """Initialize the button entity."""
49  super().__init__(device)
50  self._attr_name_attr_name = f"{self.device.name} Set System Date and Time"
51  self._attr_unique_id_attr_unique_id = f"{self.mac_or_serial}_setsystemdatetime"
52 
53  async def async_press(self) -> None:
54  """Send out a SetSystemDateAndTime command."""
55  await self.device.async_manually_set_date_and_time()
None __init__(self, ONVIFDevice device)
Definition: button.py:30
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: button.py:18