diff --git a/homeassistant/components/pushover/const.py b/homeassistant/components/pushover/const.py index af5411322972..d890cf014b94 100644 --- a/homeassistant/components/pushover/const.py +++ b/homeassistant/components/pushover/const.py @@ -15,6 +15,8 @@ ATTR_SOUND: Final = "sound" ATTR_HTML: Final = "html" ATTR_CALLBACK_URL: Final = "callback_url" ATTR_EXPIRE: Final = "expire" +ATTR_TTL: Final = "ttl" +ATTR_DATA: Final = "data" ATTR_TIMESTAMP: Final = "timestamp" CONF_USER_KEY: Final = "user_key" diff --git a/homeassistant/components/pushover/notify.py b/homeassistant/components/pushover/notify.py index 34ee1d08bdda..af27fa26639c 100644 --- a/homeassistant/components/pushover/notify.py +++ b/homeassistant/components/pushover/notify.py @@ -27,6 +27,7 @@ from .const import ( ATTR_RETRY, ATTR_SOUND, ATTR_TIMESTAMP, + ATTR_TTL, ATTR_URL, ATTR_URL_TITLE, CONF_USER_KEY, @@ -66,12 +67,13 @@ class PushoverNotificationService(BaseNotificationService): # Extract params from data dict title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) - data = dict(kwargs.get(ATTR_DATA) or {}) + data = kwargs.get(ATTR_DATA, {}) url = data.get(ATTR_URL) url_title = data.get(ATTR_URL_TITLE) priority = data.get(ATTR_PRIORITY) retry = data.get(ATTR_RETRY) expire = data.get(ATTR_EXPIRE) + ttl = data.get(ATTR_TTL) callback_url = data.get(ATTR_CALLBACK_URL) timestamp = data.get(ATTR_TIMESTAMP) sound = data.get(ATTR_SOUND) @@ -98,20 +100,21 @@ class PushoverNotificationService(BaseNotificationService): try: self.pushover.send_message( - self._user_key, - message, - ",".join(kwargs.get(ATTR_TARGET, [])), - title, - url, - url_title, - image, - priority, - retry, - expire, - callback_url, - timestamp, - sound, - html, + user=self._user_key, + message=message, + device=",".join(kwargs.get(ATTR_TARGET, [])), + title=title, + url=url, + url_title=url_title, + image=image, + priority=priority, + retry=retry, + expire=expire, + callback_url=callback_url, + timestamp=timestamp, + sound=sound, + html=html, + ttl=ttl, ) except BadAPIRequestError as err: raise HomeAssistantError(str(err)) from err diff --git a/tests/components/pushover/test_notify.py b/tests/components/pushover/test_notify.py new file mode 100644 index 000000000000..52f581855837 --- /dev/null +++ b/tests/components/pushover/test_notify.py @@ -0,0 +1,71 @@ +"""Test the pushover notify platform.""" + +from unittest.mock import MagicMock, patch + +import pytest + +from homeassistant.components.pushover import DOMAIN +from homeassistant.core import HomeAssistant + +from tests.common import MockConfigEntry + + +@pytest.fixture(autouse=False) +def mock_pushover(): + """Mock pushover.""" + with patch( + "pushover_complete.PushoverAPI._generic_post", return_value={} + ) as mock_generic_post: + yield mock_generic_post + + +@pytest.fixture +def mock_send_message(): + """Patch PushoverAPI.send_message for TTL test.""" + with patch( + "homeassistant.components.pushover.notify.PushoverAPI.send_message" + ) as mock: + yield mock + + +async def test_send_message( + hass: HomeAssistant, mock_pushover: MagicMock, mock_send_message: MagicMock +) -> None: + """Test sending a message.""" + entry = MockConfigEntry( + domain=DOMAIN, + data={ + "name": "pushover", + "api_key": "API_KEY", + "user_key": "USER_KEY", + }, + ) + entry.add_to_hass(hass) + + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + await hass.services.async_call( + "notify", + "pushover", + {"message": "Hello TTL", "data": {"ttl": 900}}, + blocking=True, + ) + + mock_send_message.assert_called_once_with( + user="USER_KEY", + message="Hello TTL", + device="", + title="Home Assistant", + url=None, + url_title=None, + image=None, + priority=None, + retry=None, + expire=None, + callback_url=None, + timestamp=None, + sound=None, + html=0, + ttl=900, + )