diff --git a/homeassistant/components/notify_events/notify.py b/homeassistant/components/notify_events/notify.py index ce7c353badb..51705453edf 100644 --- a/homeassistant/components/notify_events/notify.py +++ b/homeassistant/components/notify_events/notify.py @@ -116,12 +116,9 @@ class NotifyEventsNotificationService(BaseNotificationService): def send_message(self, message, **kwargs): """Send a message.""" - token = self.token data = kwargs.get(ATTR_DATA) or {} + token = data.get(ATTR_TOKEN, self.token) msg = self.prepare_message(message, data) - if data.get(ATTR_TOKEN, "").trim(): - token = data[ATTR_TOKEN] - msg.send(token) diff --git a/requirements_test_all.txt b/requirements_test_all.txt index aee9fa9e67f..b0403065e96 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -518,6 +518,9 @@ netdisco==2.8.2 # homeassistant.components.nexia nexia==0.9.5 +# homeassistant.components.notify_events +notify-events==1.0.4 + # homeassistant.components.nsw_fuel_station nsw-fuel-api-client==1.0.10 diff --git a/tests/components/notify_events/__init__.py b/tests/components/notify_events/__init__.py new file mode 100644 index 00000000000..5e2f9c2eaf1 --- /dev/null +++ b/tests/components/notify_events/__init__.py @@ -0,0 +1 @@ +"""Tests for the notify_events integration.""" diff --git a/tests/components/notify_events/test_init.py b/tests/components/notify_events/test_init.py new file mode 100644 index 00000000000..861be83a9cc --- /dev/null +++ b/tests/components/notify_events/test_init.py @@ -0,0 +1,12 @@ +"""The tests for notify_events.""" +from homeassistant.components.notify_events.const import DOMAIN +from homeassistant.setup import async_setup_component + + +async def test_setup(hass): + """Test setup of the integration.""" + config = {"notify_events": {"token": "ABC"}} + assert await async_setup_component(hass, DOMAIN, config) + await hass.async_block_till_done() + + assert DOMAIN in hass.data diff --git a/tests/components/notify_events/test_notify.py b/tests/components/notify_events/test_notify.py new file mode 100644 index 00000000000..55cf6275044 --- /dev/null +++ b/tests/components/notify_events/test_notify.py @@ -0,0 +1,38 @@ +"""The tests for notify_events.""" +from homeassistant.components.notify import ATTR_DATA, ATTR_MESSAGE, DOMAIN +from homeassistant.components.notify_events.notify import ( + ATTR_LEVEL, + ATTR_PRIORITY, + ATTR_TOKEN, +) + +from tests.common import async_mock_service + + +async def test_send_msg(hass): + """Test notify.events service.""" + notify_calls = async_mock_service(hass, DOMAIN, "events") + + await hass.services.async_call( + DOMAIN, + "events", + { + ATTR_MESSAGE: "message content", + ATTR_DATA: { + ATTR_TOKEN: "XYZ", + ATTR_LEVEL: "warning", + ATTR_PRIORITY: "high", + }, + }, + blocking=True, + ) + + assert len(notify_calls) == 1 + call = notify_calls[-1] + + assert call.domain == DOMAIN + assert call.service == "events" + assert call.data.get(ATTR_MESSAGE) == "message content" + assert call.data.get(ATTR_DATA).get(ATTR_TOKEN) == "XYZ" + assert call.data.get(ATTR_DATA).get(ATTR_LEVEL) == "warning" + assert call.data.get(ATTR_DATA).get(ATTR_PRIORITY) == "high"