From 9023d80d1b2835f0b66d07675bd9a075bbf76c18 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 31 Jul 2024 20:48:51 +0200 Subject: [PATCH] Fix implicit-return in twitter (#122931) --- homeassistant/components/twitter/notify.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/twitter/notify.py b/homeassistant/components/twitter/notify.py index 66b076126b5..eef51ca9613 100644 --- a/homeassistant/components/twitter/notify.py +++ b/homeassistant/components/twitter/notify.py @@ -129,10 +129,11 @@ class TwitterNotificationService(BaseNotificationService): else: _LOGGER.debug("Message posted: %s", resp.json()) - def upload_media_then_callback(self, callback, media_path=None): + def upload_media_then_callback(self, callback, media_path=None) -> None: """Upload media.""" if not media_path: - return callback() + callback() + return with open(media_path, "rb") as file: total_bytes = os.path.getsize(media_path) @@ -141,7 +142,7 @@ class TwitterNotificationService(BaseNotificationService): if 199 > resp.status_code < 300: self.log_error_resp(resp) - return None + return media_id = resp.json()["media_id"] media_id = self.upload_media_chunked(file, total_bytes, media_id) @@ -149,10 +150,11 @@ class TwitterNotificationService(BaseNotificationService): resp = self.upload_media_finalize(media_id) if 199 > resp.status_code < 300: self.log_error_resp(resp) - return None + return if resp.json().get("processing_info") is None: - return callback(media_id) + callback(media_id) + return self.check_status_until_done(media_id, callback) @@ -209,7 +211,7 @@ class TwitterNotificationService(BaseNotificationService): "media/upload", {"command": "FINALIZE", "media_id": media_id} ) - def check_status_until_done(self, media_id, callback, *args): + def check_status_until_done(self, media_id, callback, *args) -> None: """Upload media, STATUS phase.""" resp = self.api.request( "media/upload", @@ -223,7 +225,8 @@ class TwitterNotificationService(BaseNotificationService): _LOGGER.debug("media processing %s status: %s", media_id, processing_info) if processing_info["state"] in {"succeeded", "failed"}: - return callback(media_id) + callback(media_id) + return check_after_secs = processing_info["check_after_secs"] _LOGGER.debug(