1 """Support for Matrix notifications."""
3 from __future__
import annotations
7 import voluptuous
as vol
13 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
14 BaseNotificationService,
21 from .const
import DOMAIN, SERVICE_SEND_MESSAGE
23 CONF_DEFAULT_ROOM =
"default_room"
25 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
26 {vol.Required(CONF_DEFAULT_ROOM): cv.string}
33 discovery_info: DiscoveryInfoType |
None =
None,
34 ) -> MatrixNotificationService:
35 """Get the Matrix notification service."""
40 """Send notifications to a Matrix room."""
42 def __init__(self, default_room: RoomID) ->
None:
43 """Set up the Matrix notification service."""
47 """Send the message to the Matrix server."""
48 target_rooms: list[RoomID] = kwargs.get(ATTR_TARGET)
or [self.
_default_room_default_room]
49 service_data = {ATTR_TARGET: target_rooms, ATTR_MESSAGE: message}
50 if (data := kwargs.get(ATTR_DATA))
is not None:
51 service_data[ATTR_DATA] = data
52 self.hass.services.call(DOMAIN, SERVICE_SEND_MESSAGE, service_data=service_data)
None __init__(self, RoomID default_room)
None send_message(self, str message="", **Any kwargs)
MatrixNotificationService get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)