Home Assistant Unofficial Reference 2024.12.1
notify.py
Go to the documentation of this file.
1 """Support for Tibber notifications."""
2 
3 from __future__ import annotations
4 
5 from tibber import Tibber
6 
8  ATTR_TITLE_DEFAULT,
9  NotifyEntity,
10  NotifyEntityFeature,
11 )
12 from homeassistant.config_entries import ConfigEntry
13 from homeassistant.core import HomeAssistant
14 from homeassistant.exceptions import HomeAssistantError
15 from homeassistant.helpers.entity_platform import AddEntitiesCallback
16 
17 from . import DOMAIN as TIBBER_DOMAIN
18 
19 
21  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
22 ) -> None:
23  """Set up the Tibber notification entity."""
25 
26 
28  """Implement the notification entity service for Tibber."""
29 
30  _attr_supported_features = NotifyEntityFeature.TITLE
31  _attr_name = TIBBER_DOMAIN
32  _attr_icon = "mdi:message-flash"
33 
34  def __init__(self, unique_id: str) -> None:
35  """Initialize Tibber notify entity."""
36  self._attr_unique_id_attr_unique_id = unique_id
37 
38  async def async_send_message(self, message: str, title: str | None = None) -> None:
39  """Send a message to Tibber devices."""
40  tibber_connection: Tibber = self.hasshass.data[TIBBER_DOMAIN]
41  try:
42  await tibber_connection.send_notification(
43  title or ATTR_TITLE_DEFAULT, message
44  )
45  except TimeoutError as exc:
46  raise HomeAssistantError(
47  translation_domain=TIBBER_DOMAIN, translation_key="send_message_timeout"
48  ) from exc
None async_send_message(self, str message, str|None title=None)
Definition: notify.py:38
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: notify.py:22