Home Assistant Unofficial Reference 2024.12.1
button.py
Go to the documentation of this file.
1 """Fully Kiosk Browser button."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Callable
6 from dataclasses import dataclass
7 from typing import Any
8 
9 from fullykiosk import FullyKiosk
10 
12  ButtonDeviceClass,
13  ButtonEntity,
14  ButtonEntityDescription,
15 )
16 from homeassistant.const import EntityCategory
17 from homeassistant.core import HomeAssistant
18 from homeassistant.helpers.entity_platform import AddEntitiesCallback
19 
20 from . import FullyKioskConfigEntry
21 from .coordinator import FullyKioskDataUpdateCoordinator
22 from .entity import FullyKioskEntity
23 
24 
25 @dataclass(frozen=True, kw_only=True)
27  """Fully Kiosk Browser button description."""
28 
29  press_action: Callable[[FullyKiosk], Any]
30 
31 
32 BUTTONS: tuple[FullyButtonEntityDescription, ...] = (
34  key="restartApp",
35  translation_key="restart_browser",
36  device_class=ButtonDeviceClass.RESTART,
37  entity_category=EntityCategory.CONFIG,
38  press_action=lambda fully: fully.restartApp(),
39  ),
41  key="rebootDevice",
42  translation_key="restart_device",
43  device_class=ButtonDeviceClass.RESTART,
44  entity_category=EntityCategory.CONFIG,
45  press_action=lambda fully: fully.rebootDevice(),
46  ),
48  key="toForeground",
49  translation_key="to_foreground",
50  entity_category=EntityCategory.CONFIG,
51  press_action=lambda fully: fully.toForeground(),
52  ),
54  key="toBackground",
55  translation_key="to_background",
56  entity_category=EntityCategory.CONFIG,
57  press_action=lambda fully: fully.toBackground(),
58  ),
60  key="loadStartUrl",
61  translation_key="load_start_url",
62  entity_category=EntityCategory.CONFIG,
63  press_action=lambda fully: fully.loadStartUrl(),
64  ),
65 )
66 
67 
69  hass: HomeAssistant,
70  config_entry: FullyKioskConfigEntry,
71  async_add_entities: AddEntitiesCallback,
72 ) -> None:
73  """Set up the Fully Kiosk Browser button entities."""
74  coordinator = config_entry.runtime_data
75 
77  FullyButtonEntity(coordinator, description) for description in BUTTONS
78  )
79 
80 
82  """Representation of a Fully Kiosk Browser button."""
83 
84  entity_description: FullyButtonEntityDescription
85 
86  def __init__(
87  self,
88  coordinator: FullyKioskDataUpdateCoordinator,
89  description: FullyButtonEntityDescription,
90  ) -> None:
91  """Initialize the button."""
92  super().__init__(coordinator)
93  self.entity_descriptionentity_description = description
94  self._attr_unique_id_attr_unique_id = f"{coordinator.data['deviceID']}-{description.key}"
95 
96  async def async_press(self) -> None:
97  """Set the value of the entity."""
98  await self.entity_descriptionentity_description.press_action(self.coordinator.fully)
99  await self.coordinator.async_refresh()
None __init__(self, FullyKioskDataUpdateCoordinator coordinator, FullyButtonEntityDescription description)
Definition: button.py:90
None async_setup_entry(HomeAssistant hass, FullyKioskConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: button.py:72