From 31ce43212a3577db77d8f6a7c377b5d639cbecb3 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Mon, 19 Feb 2024 03:29:26 -0500 Subject: [PATCH] Allow loading of more then 1 defined Apprise URL (#110868) --- homeassistant/components/apprise/notify.py | 8 ++-- tests/components/apprise/test_notify.py | 43 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/apprise/notify.py b/homeassistant/components/apprise/notify.py index e4b350c4da8..acd1db00d93 100644 --- a/homeassistant/components/apprise/notify.py +++ b/homeassistant/components/apprise/notify.py @@ -52,9 +52,11 @@ 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 urls := config.get(CONF_URL): + for entry in urls: + if not a_obj.add(entry): + _LOGGER.error("One or more specified Apprise URL(s) are invalid") + return None return AppriseNotificationService(a_obj) diff --git a/tests/components/apprise/test_notify.py b/tests/components/apprise/test_notify.py index ab827a95210..ead8f735236 100644 --- a/tests/components/apprise/test_notify.py +++ b/tests/components/apprise/test_notify.py @@ -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} )