Fix "notify.events" trim() issue + add initial tests (#48928)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>pull/48954/head
parent
29bb6d76f1
commit
ee78c9b08a
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
"""Tests for the notify_events integration."""
|
|
@ -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
|
|
@ -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"
|
Loading…
Reference in New Issue