mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add notify demo data test
This commit is contained in:
parent
492ade7b1a
commit
6bb6a6ebe9
@ -44,16 +44,19 @@ NOTIFY_SERVICE_SCHEMA = vol.Schema({
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def send_message(hass, message, title=None):
|
def send_message(hass, message, title=None, data=None):
|
||||||
"""Send a notification message."""
|
"""Send a notification message."""
|
||||||
data = {
|
info = {
|
||||||
ATTR_MESSAGE: message
|
ATTR_MESSAGE: message
|
||||||
}
|
}
|
||||||
|
|
||||||
if title is not None:
|
if title is not None:
|
||||||
data[ATTR_TITLE] = title
|
info[ATTR_TITLE] = title
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_NOTIFY, data)
|
if data is not None:
|
||||||
|
info[ATTR_DATA] = data
|
||||||
|
|
||||||
|
hass.services.call(DOMAIN, SERVICE_NOTIFY, info)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
|
@ -4,7 +4,7 @@ Demo notification service.
|
|||||||
For more details about this platform, please refer to the documentation
|
For more details about this platform, please refer to the documentation
|
||||||
https://home-assistant.io/components/demo/
|
https://home-assistant.io/components/demo/
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.notify import ATTR_TITLE, BaseNotificationService
|
from homeassistant.components.notify import BaseNotificationService
|
||||||
|
|
||||||
EVENT_NOTIFY = "notify"
|
EVENT_NOTIFY = "notify"
|
||||||
|
|
||||||
@ -24,5 +24,5 @@ class DemoNotificationService(BaseNotificationService):
|
|||||||
|
|
||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message="", **kwargs):
|
||||||
"""Send a message to a user."""
|
"""Send a message to a user."""
|
||||||
title = kwargs.get(ATTR_TITLE)
|
kwargs['message'] = message
|
||||||
self.hass.bus.fire(EVENT_NOTIFY, {"title": title, "message": message})
|
self.hass.bus.fire(EVENT_NOTIFY, kwargs)
|
||||||
|
@ -45,3 +45,17 @@ class TestNotifyDemo(unittest.TestCase):
|
|||||||
last_event = self.events[-1]
|
last_event = self.events[-1]
|
||||||
self.assertEqual(last_event.data[notify.ATTR_TITLE], 'temperature')
|
self.assertEqual(last_event.data[notify.ATTR_TITLE], 'temperature')
|
||||||
self.assertEqual(last_event.data[notify.ATTR_MESSAGE], '10')
|
self.assertEqual(last_event.data[notify.ATTR_MESSAGE], '10')
|
||||||
|
|
||||||
|
def test_method_forwards_correct_data(self):
|
||||||
|
"""Test that all data from the service gets forwarded to service."""
|
||||||
|
notify.send_message(self.hass, 'my message', 'my title',
|
||||||
|
{'hello': 'world'})
|
||||||
|
self.hass.pool.block_till_done()
|
||||||
|
self.assertTrue(len(self.events) == 1)
|
||||||
|
data = self.events[0].data
|
||||||
|
assert {
|
||||||
|
'message': 'my message',
|
||||||
|
'target': None,
|
||||||
|
'title': 'my title',
|
||||||
|
'data': {'hello': 'world'}
|
||||||
|
} == data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user