From 0b88d9c0fca11d77fd1a105924d259208c18be1a Mon Sep 17 00:00:00 2001 From: Nick Waterton Date: Thu, 16 Jan 2025 09:35:08 -0500 Subject: [PATCH] added timout handling --- example/async_art_remove_mats.py | 4 ++-- samsungtvws/async_connection.py | 3 +++ samsungtvws/event.py | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/example/async_art_remove_mats.py b/example/async_art_remove_mats.py index 29609e5..45b5673 100755 --- a/example/async_art_remove_mats.py +++ b/example/async_art_remove_mats.py @@ -29,7 +29,7 @@ async def main(): logging.info('opening art websocket with token') token_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), args.token_file) tv = SamsungTVAsyncArt(host=args.ip, port=8002, token_file=token_file) - + logging.info('getting tv info') #is art mode supported supported = await tv.supported() @@ -89,7 +89,7 @@ async def main(): except ResponseError: logging.warning('Unable to change mat to {} for {} ({}x{})'.format(target_matte_type, art["content_id"], art["width"], art["height"])) except KeyError: - logging.warning('no mat for {}'.format(art)) + logging.warning('no mat for {}'.format(art)) await tv.close() diff --git a/samsungtvws/async_connection.py b/samsungtvws/async_connection.py index be4c9e6..da42a8e 100644 --- a/samsungtvws/async_connection.py +++ b/samsungtvws/async_connection.py @@ -23,6 +23,7 @@ IGNORE_EVENTS_AT_STARTUP, MS_CHANNEL_CONNECT_EVENT, MS_CHANNEL_UNAUTHORIZED, + MS_CHANNEL_TIMEOUT ) from .helper import get_ssl_context @@ -72,6 +73,8 @@ async def open(self) -> WebSocketClientProtocol: if event != MS_CHANNEL_CONNECT_EVENT: # Unexpected event received during connection routine await self.close() + if event == MS_CHANNEL_TIMEOUT: + _LOGGING.debug("connection not accepted on TV, or token missing/incorrect") raise exceptions.ConnectionFailure(response) self._check_for_token(response) diff --git a/samsungtvws/event.py b/samsungtvws/event.py index f28f060..2fa3072 100644 --- a/samsungtvws/event.py +++ b/samsungtvws/event.py @@ -19,6 +19,7 @@ MS_CHANNEL_CLIENT_DISCONNECT_EVENT = "ms.channel.clientDisconnect" MS_CHANNEL_READY_EVENT = "ms.channel.ready" MS_CHANNEL_UNAUTHORIZED = "ms.channel.unauthorized" +MS_CHANNEL_TIMEOUT = "ms.channel.timeOut" MS_ERROR_EVENT = "ms.error" MS_VOICEAPP_HIDE_EVENT = "ms.voiceApp.hide"