|
1 | | -"""Demo notification service.""" |
| 1 | +"""Demo notification entity.""" |
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | | -from typing import Any |
6 | | - |
7 | | -from homeassistant.components.notify import BaseNotificationService |
| 5 | +from homeassistant.components.notify import DOMAIN, NotifyEntity |
| 6 | +from homeassistant.config_entries import ConfigEntry |
8 | 7 | from homeassistant.core import HomeAssistant |
9 | | -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType |
| 8 | +from homeassistant.helpers.device_registry import DeviceInfo |
| 9 | +from homeassistant.helpers.entity_platform import AddEntitiesCallback |
10 | 10 |
|
11 | 11 | EVENT_NOTIFY = "notify" |
12 | 12 |
|
13 | 13 |
|
14 | | -def get_service( |
| 14 | +async def async_setup_entry( |
15 | 15 | hass: HomeAssistant, |
16 | | - config: ConfigType, |
17 | | - discovery_info: DiscoveryInfoType | None = None, |
18 | | -) -> BaseNotificationService: |
19 | | - """Get the demo notification service.""" |
20 | | - return DemoNotificationService(hass) |
21 | | - |
22 | | - |
23 | | -class DemoNotificationService(BaseNotificationService): |
24 | | - """Implement demo notification service.""" |
25 | | - |
26 | | - def __init__(self, hass: HomeAssistant) -> None: |
27 | | - """Initialize the service.""" |
28 | | - self.hass = hass |
29 | | - |
30 | | - @property |
31 | | - def targets(self) -> dict[str, str]: |
32 | | - """Return a dictionary of registered targets.""" |
33 | | - return {"test target name": "test target id"} |
34 | | - |
35 | | - def send_message(self, message: str = "", **kwargs: Any) -> None: |
| 16 | + config_entry: ConfigEntry, |
| 17 | + async_add_entities: AddEntitiesCallback, |
| 18 | +) -> None: |
| 19 | + """Set up the demo entity platform.""" |
| 20 | + async_add_entities([DemoNotifyEntity(unique_id="notify", device_name="Notifier")]) |
| 21 | + |
| 22 | + |
| 23 | +class DemoNotifyEntity(NotifyEntity): |
| 24 | + """Implement demo notification platform.""" |
| 25 | + |
| 26 | + _attr_has_entity_name = True |
| 27 | + _attr_name = None |
| 28 | + |
| 29 | + def __init__( |
| 30 | + self, |
| 31 | + unique_id: str, |
| 32 | + device_name: str, |
| 33 | + ) -> None: |
| 34 | + """Initialize the Demo button entity.""" |
| 35 | + self._attr_unique_id = unique_id |
| 36 | + self._attr_device_info = DeviceInfo( |
| 37 | + identifiers={(DOMAIN, unique_id)}, |
| 38 | + name=device_name, |
| 39 | + ) |
| 40 | + |
| 41 | + async def async_send_message(self, message: str) -> None: |
36 | 42 | """Send a message to a user.""" |
37 | | - kwargs["message"] = message |
38 | | - self.hass.bus.fire(EVENT_NOTIFY, kwargs) |
| 43 | + event_notitifcation = {"message": message} |
| 44 | + self.hass.bus.async_fire(EVENT_NOTIFY, event_notitifcation) |
0 commit comments