From 943b1afb557f7d3cc61568c4367f26ecdae3c598 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Wed, 24 Jul 2024 17:19:12 +0100 Subject: [PATCH] Fix target service attribute on Mastodon integration (#122546) * Fix target * Fix --- homeassistant/components/mastodon/notify.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/mastodon/notify.py b/homeassistant/components/mastodon/notify.py index f15b8c6f0ab..99999275aeb 100644 --- a/homeassistant/components/mastodon/notify.py +++ b/homeassistant/components/mastodon/notify.py @@ -3,7 +3,7 @@ from __future__ import annotations import mimetypes -from typing import Any +from typing import Any, cast from mastodon import Mastodon from mastodon.Mastodon import MastodonAPIError, MastodonUnauthorizedError @@ -71,11 +71,15 @@ class MastodonNotificationService(BaseNotificationService): def send_message(self, message: str = "", **kwargs: Any) -> None: """Toot a message, with media perhaps.""" + + target = None + if (target_list := kwargs.get(ATTR_TARGET)) is not None: + target = cast(list[str], target_list)[0] + data = kwargs.get(ATTR_DATA) media = None mediadata = None - target = None sensitive = False content_warning = None @@ -87,7 +91,6 @@ class MastodonNotificationService(BaseNotificationService): return mediadata = self._upload_media(media) - target = data.get(ATTR_TARGET) sensitive = data.get(ATTR_MEDIA_WARNING) content_warning = data.get(ATTR_CONTENT_WARNING)