Fix possible issue with apprise notification.
This commit is contained in:
parent
ed9ce05ac0
commit
06698cb54e
2 changed files with 8 additions and 3 deletions
|
|
@ -438,7 +438,7 @@ class Notification(metaclass=Singleton):
|
||||||
import apprise
|
import apprise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
notify = apprise.Apprise()
|
notify = apprise.Apprise(debug=self._debug)
|
||||||
apr_config = Path(Config.get_instance().apprise_config)
|
apr_config = Path(Config.get_instance().apprise_config)
|
||||||
if apr_config.exists():
|
if apr_config.exists():
|
||||||
apprise_config = notify.AppriseConfig()
|
apprise_config = notify.AppriseConfig()
|
||||||
|
|
@ -448,11 +448,14 @@ class Notification(metaclass=Singleton):
|
||||||
for t in target:
|
for t in target:
|
||||||
notify.add(t.request.url)
|
notify.add(t.request.url)
|
||||||
|
|
||||||
notify.notify(
|
status = await notify.async_notify(
|
||||||
body=ev.message or json.dumps(ev.serialize(), sort_keys=False, ensure_ascii=False),
|
body=ev.message or json.dumps(ev.serialize(), sort_keys=False, ensure_ascii=False),
|
||||||
title=ev.title or f"YTPTube Event: {ev.event}",
|
title=ev.title or f"YTPTube Event: {ev.event}",
|
||||||
notify_type=ev.event,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not status:
|
||||||
|
msg = "Apprise failed to send notification."
|
||||||
|
raise RuntimeError(msg) # noqa: TRY301
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception(e)
|
LOG.exception(e)
|
||||||
LOG.error(f"Error sending Apprise notification: {e!s}")
|
LOG.error(f"Error sending Apprise notification: {e!s}")
|
||||||
|
|
|
||||||
|
|
@ -812,6 +812,8 @@ class TestNotification:
|
||||||
# Mock apprise import
|
# Mock apprise import
|
||||||
mock_apprise = Mock()
|
mock_apprise = Mock()
|
||||||
mock_notify = Mock()
|
mock_notify = Mock()
|
||||||
|
# Mock async_notify as an AsyncMock that returns True
|
||||||
|
mock_notify.async_notify = AsyncMock(return_value=True)
|
||||||
mock_apprise.Apprise.return_value = mock_notify
|
mock_apprise.Apprise.return_value = mock_notify
|
||||||
mock_import.return_value = mock_apprise
|
mock_import.return_value = mock_apprise
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue