mirror of
https://github.com/home-assistant/core.git
synced 2025-05-02 21:19:16 +00:00

* Remove dependencies and requirements * Revert "Remove dependencies and requirements" This reverts commit fe7171b4cd30889bad5adc9a4fd60059d05ba5a7. * Remove dependencies and requirements * Revert "Remove dependencies and requirements" This reverts commit 391355ee2cc53cbe6954f940062b18ae34b05621. * Remove dependencies and requirements * Fix flake8 complaints * Fix more flake8 complaints * Revert non-component removals
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
"""Support for Matrix notifications."""
|
|
import logging
|
|
|
|
import voluptuous as vol
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
from homeassistant.components.notify import (ATTR_TARGET, PLATFORM_SCHEMA,
|
|
BaseNotificationService,
|
|
ATTR_MESSAGE)
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
CONF_DEFAULT_ROOM = 'default_room'
|
|
|
|
DOMAIN = 'matrix'
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
vol.Required(CONF_DEFAULT_ROOM): cv.string,
|
|
})
|
|
|
|
|
|
def get_service(hass, config, discovery_info=None):
|
|
"""Get the Matrix notification service."""
|
|
return MatrixNotificationService(config.get(CONF_DEFAULT_ROOM))
|
|
|
|
|
|
class MatrixNotificationService(BaseNotificationService):
|
|
"""Send Notifications to a Matrix Room."""
|
|
|
|
def __init__(self, default_room):
|
|
"""Set up the notification service."""
|
|
self._default_room = default_room
|
|
|
|
def send_message(self, message="", **kwargs):
|
|
"""Send the message to the matrix server."""
|
|
target_rooms = kwargs.get(ATTR_TARGET) or [self._default_room]
|
|
|
|
service_data = {
|
|
ATTR_TARGET: target_rooms,
|
|
ATTR_MESSAGE: message
|
|
}
|
|
|
|
return self.hass.services.call(
|
|
DOMAIN, 'send_message', service_data=service_data)
|