From 73e62f419cfae2c62bedca6e73345565f2cb3340 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 28 Nov 2024 07:38:18 +0100 Subject: [PATCH] Fix is_alive --- samsungtvws/async_connection.py | 3 ++- samsungtvws/encrypted/remote.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/samsungtvws/async_connection.py b/samsungtvws/async_connection.py index dd10f50..141b035 100644 --- a/samsungtvws/async_connection.py +++ b/samsungtvws/async_connection.py @@ -24,6 +24,7 @@ from websockets.asyncio.client import ClientConnection, connect from websockets.exceptions import ConnectionClosed +from websockets.protocol import State from . import connection, exceptions, helper from .command import SamsungTVCommand, SamsungTVSleepCommand @@ -174,4 +175,4 @@ async def _send_command( await asyncio.sleep(delay) def is_alive(self) -> bool: - return self.connection is not None and not self.connection.closed + return self.connection is not None and self.connection.state is not State.CLOSED diff --git a/samsungtvws/encrypted/remote.py b/samsungtvws/encrypted/remote.py index 9b06f99..7d3b7a9 100644 --- a/samsungtvws/encrypted/remote.py +++ b/samsungtvws/encrypted/remote.py @@ -10,6 +10,7 @@ import aiohttp from websockets.asyncio.client import ClientConnection, connect from websockets.exceptions import ConnectionClosed +from websockets.protocol import State from ..exceptions import ConnectionFailure from .command import SamsungTVEncryptedCommand @@ -183,4 +184,7 @@ async def close(self) -> None: LOGGER.debug("Connection closed") def is_alive(self) -> bool: - return self._connection is not None and not self._connection.closed + return ( + self._connection is not None + and not self._connection.state is not State.CLOSED + )