Home Assistant Unofficial Reference 2024.12.1
notify.py
Go to the documentation of this file.
1 """Demo platform that offers a fake notify entity."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.components import persistent_notification
6 from homeassistant.components.notify import NotifyEntity, NotifyEntityFeature
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.device_registry import DeviceInfo
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from . import DOMAIN
13 
14 
16  hass: HomeAssistant,
17  config_entry: ConfigEntry,
18  async_add_entities: AddEntitiesCallback,
19 ) -> None:
20  """Set up the demo notify entity platform."""
22  [
23  DemoNotify(
24  unique_id="just_notify_me",
25  device_name="MyBox",
26  entity_name="Personal notifier",
27  ),
28  DemoNotify(
29  unique_id="just_notify_me_title",
30  device_name="MyBox",
31  entity_name="Personal notifier with title",
32  supported_features=NotifyEntityFeature.TITLE,
33  ),
34  ]
35  )
36 
37 
39  """Representation of a demo notify entity."""
40 
41  _attr_has_entity_name = True
42  _attr_should_poll = False
43 
44  def __init__(
45  self,
46  unique_id: str,
47  device_name: str,
48  entity_name: str | None,
49  supported_features: NotifyEntityFeature = NotifyEntityFeature(0),
50  ) -> None:
51  """Initialize the Demo button entity."""
52  self._attr_unique_id_attr_unique_id = unique_id
53  self._attr_supported_features_attr_supported_features = supported_features
54  self._attr_device_info_attr_device_info = DeviceInfo(
55  identifiers={(DOMAIN, unique_id)},
56  name=device_name,
57  )
58  self._attr_name_attr_name = entity_name
59 
60  async def async_send_message(self, message: str, title: str | None = None) -> None:
61  """Send out a persistent notification."""
62  persistent_notification.async_create(
63  self.hasshass, message, title or "Demo notification"
64  )
None async_send_message(self, str message, str|None title=None)
Definition: notify.py:60
None __init__(self, str unique_id, str device_name, str|None entity_name, NotifyEntityFeature supported_features=NotifyEntityFeature(0))
Definition: notify.py:50
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: notify.py:19