Change matrix component to use matrix-nio instead of matrix_client (#72797)
This commit is contained in:
parent
f48e8623da
commit
4d3b978398
16 changed files with 879 additions and 243 deletions
|
@ -1,6 +1,8 @@
|
|||
"""Support for Matrix notifications."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.notify import (
|
||||
|
@ -14,6 +16,7 @@ from homeassistant.core import HomeAssistant
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import RoomID
|
||||
from .const import DOMAIN, SERVICE_SEND_MESSAGE
|
||||
|
||||
CONF_DEFAULT_ROOM = "default_room"
|
||||
|
@ -33,16 +36,14 @@ def get_service(
|
|||
class MatrixNotificationService(BaseNotificationService):
|
||||
"""Send notifications to a Matrix room."""
|
||||
|
||||
def __init__(self, default_room):
|
||||
def __init__(self, default_room: RoomID) -> None:
|
||||
"""Set up the Matrix notification service."""
|
||||
self._default_room = default_room
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
def send_message(self, message: str = "", **kwargs: Any) -> None:
|
||||
"""Send the message to the Matrix server."""
|
||||
target_rooms = kwargs.get(ATTR_TARGET) or [self._default_room]
|
||||
target_rooms: list[RoomID] = kwargs.get(ATTR_TARGET) or [self._default_room]
|
||||
service_data = {ATTR_TARGET: target_rooms, ATTR_MESSAGE: message}
|
||||
if (data := kwargs.get(ATTR_DATA)) is not None:
|
||||
service_data[ATTR_DATA] = data
|
||||
return self.hass.services.call(
|
||||
DOMAIN, SERVICE_SEND_MESSAGE, service_data=service_data
|
||||
)
|
||||
self.hass.services.call(DOMAIN, SERVICE_SEND_MESSAGE, service_data=service_data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue