Home Assistant Unofficial Reference 2024.12.1
notify.py
Go to the documentation of this file.
1 """Demo notification entity."""
2 
3 from __future__ import annotations
4 
6  DOMAIN as NOTIFY_DOMAIN,
7  NotifyEntity,
8  NotifyEntityFeature,
9 )
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.device_registry import DeviceInfo
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 
15 EVENT_NOTIFY = "notify"
16 
17 
19  hass: HomeAssistant,
20  config_entry: ConfigEntry,
21  async_add_entities: AddEntitiesCallback,
22 ) -> None:
23  """Set up the demo entity platform."""
24  async_add_entities([DemoNotifyEntity(unique_id="notify", device_name="Notifier")])
25 
26 
28  """Implement demo notification platform."""
29 
30  _attr_has_entity_name = True
31  _attr_name = None
32 
33  def __init__(
34  self,
35  unique_id: str,
36  device_name: str,
37  ) -> None:
38  """Initialize the Demo button entity."""
39  self._attr_unique_id_attr_unique_id = unique_id
40  self._attr_supported_features_attr_supported_features = NotifyEntityFeature.TITLE
41  self._attr_device_info_attr_device_info = DeviceInfo(
42  identifiers={(NOTIFY_DOMAIN, unique_id)},
43  name=device_name,
44  )
45 
46  async def async_send_message(self, message: str, title: str | None = None) -> None:
47  """Send a message to a user."""
48  event_notification = {"message": message}
49  if title is not None:
50  event_notification["title"] = title
51  self.hasshass.bus.async_fire(EVENT_NOTIFY, event_notification)
None async_send_message(self, str message, str|None title=None)
Definition: notify.py:46
None __init__(self, str unique_id, str device_name)
Definition: notify.py:37
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: notify.py:22