Feature - add Time-to-Live (ttl) parameter support to Pushover integration (#143791)

pull/152018/head
Megamind 2025-09-09 22:56:36 -07:00 committed by GitHub
parent 0f4ce58f28
commit 7053727426
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 91 additions and 15 deletions

View File

@ -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"

View File

@ -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

View File

@ -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,
)