Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading of more then 1 defined Apprise URL #110868

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions homeassistant/components/apprise/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ def get_service(
return None

# Ordered list of URLs
if config.get(CONF_URL) and not a_obj.add(config[CONF_URL]):
_LOGGER.error("Invalid Apprise URL(s) supplied")
return None
if config.get(CONF_URL):
has_error = False
for entry in config[CONF_URL]:
if not a_obj.add(entry):
has_error = True

if has_error:
_LOGGER.error("One or more specified Apprise URL(s) are invalid")
return None
raman325 marked this conversation as resolved.
Show resolved Hide resolved

return AppriseNotificationService(a_obj)

Expand Down
43 changes: 42 additions & 1 deletion tests/components/apprise/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,48 @@ async def test_apprise_notification(hass: HomeAssistant) -> None:
await hass.async_block_till_done()

# Validate calls were made under the hood correctly
obj.add.assert_called_once_with([config[BASE_COMPONENT]["url"]])
obj.add.assert_called_once_with(config[BASE_COMPONENT]["url"])
obj.notify.assert_called_once_with(
**{"body": data["message"], "title": data["title"], "tag": None}
)


async def test_apprise_multiple_notification(hass: HomeAssistant) -> None:
"""Test apprise notification."""

config = {
BASE_COMPONENT: {
"name": "test",
"platform": "apprise",
"url": [
"mailto://user:pass@example.com, mailto://user:pass@gmail.com",
"json://user:pass@gmail.com",
],
}
}

# Our Message
data = {"title": "Test Title", "message": "Test Message"}

with patch(
"homeassistant.components.apprise.notify.apprise.Apprise"
) as mock_apprise:
obj = MagicMock()
obj.add.return_value = True
obj.notify.return_value = True
mock_apprise.return_value = obj
assert await async_setup_component(hass, BASE_COMPONENT, config)
await hass.async_block_till_done()

# Test the existence of our service
assert hass.services.has_service(BASE_COMPONENT, "test")

# Test the call to our underlining notify() call
await hass.services.async_call(BASE_COMPONENT, "test", data)
await hass.async_block_till_done()

# Validate 2 calls were made under the hood
assert obj.add.call_count == 2
obj.notify.assert_called_once_with(
**{"body": data["message"], "title": data["title"], "tag": None}
)
Expand Down
Loading