Allow loading of more then 1 defined Apprise URL (#110868)
This commit is contained in:
parent
88b92ff2a8
commit
31ce43212a
2 changed files with 47 additions and 4 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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}
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue