mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Fix implicit-return in twitter (#122931)
This commit is contained in:
parent
c702ffa7dd
commit
9023d80d1b
@ -129,10 +129,11 @@ class TwitterNotificationService(BaseNotificationService):
|
|||||||
else:
|
else:
|
||||||
_LOGGER.debug("Message posted: %s", resp.json())
|
_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."""
|
"""Upload media."""
|
||||||
if not media_path:
|
if not media_path:
|
||||||
return callback()
|
callback()
|
||||||
|
return
|
||||||
|
|
||||||
with open(media_path, "rb") as file:
|
with open(media_path, "rb") as file:
|
||||||
total_bytes = os.path.getsize(media_path)
|
total_bytes = os.path.getsize(media_path)
|
||||||
@ -141,7 +142,7 @@ class TwitterNotificationService(BaseNotificationService):
|
|||||||
|
|
||||||
if 199 > resp.status_code < 300:
|
if 199 > resp.status_code < 300:
|
||||||
self.log_error_resp(resp)
|
self.log_error_resp(resp)
|
||||||
return None
|
return
|
||||||
|
|
||||||
media_id = resp.json()["media_id"]
|
media_id = resp.json()["media_id"]
|
||||||
media_id = self.upload_media_chunked(file, total_bytes, 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)
|
resp = self.upload_media_finalize(media_id)
|
||||||
if 199 > resp.status_code < 300:
|
if 199 > resp.status_code < 300:
|
||||||
self.log_error_resp(resp)
|
self.log_error_resp(resp)
|
||||||
return None
|
return
|
||||||
|
|
||||||
if resp.json().get("processing_info") is None:
|
if resp.json().get("processing_info") is None:
|
||||||
return callback(media_id)
|
callback(media_id)
|
||||||
|
return
|
||||||
|
|
||||||
self.check_status_until_done(media_id, callback)
|
self.check_status_until_done(media_id, callback)
|
||||||
|
|
||||||
@ -209,7 +211,7 @@ class TwitterNotificationService(BaseNotificationService):
|
|||||||
"media/upload", {"command": "FINALIZE", "media_id": media_id}
|
"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."""
|
"""Upload media, STATUS phase."""
|
||||||
resp = self.api.request(
|
resp = self.api.request(
|
||||||
"media/upload",
|
"media/upload",
|
||||||
@ -223,7 +225,8 @@ class TwitterNotificationService(BaseNotificationService):
|
|||||||
_LOGGER.debug("media processing %s status: %s", media_id, processing_info)
|
_LOGGER.debug("media processing %s status: %s", media_id, processing_info)
|
||||||
|
|
||||||
if processing_info["state"] in {"succeeded", "failed"}:
|
if processing_info["state"] in {"succeeded", "failed"}:
|
||||||
return callback(media_id)
|
callback(media_id)
|
||||||
|
return
|
||||||
|
|
||||||
check_after_secs = processing_info["check_after_secs"]
|
check_after_secs = processing_info["check_after_secs"]
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user