Skip to content

Commit

Permalink
added timout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
NickWaterton committed Jan 16, 2025
1 parent bdcb303 commit 0b88d9c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions example/async_art_remove_mats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down
3 changes: 3 additions & 0 deletions samsungtvws/async_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
IGNORE_EVENTS_AT_STARTUP,
MS_CHANNEL_CONNECT_EVENT,
MS_CHANNEL_UNAUTHORIZED,
MS_CHANNEL_TIMEOUT
)
from .helper import get_ssl_context

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions samsungtvws/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 0b88d9c

Please sign in to comment.