def ws_close(self):
"""Close the websocket connection."""
if not self.ws_connected:
return
# Try to gracefully end the connection
try:
yield from self._ws_connection.send_str('41')
yield from self._ws_connection.send_str('1')
except (ClientError, HttpProcessingError, asyncio.TimeoutError):
pass
# Close any remaining ping handles
handle = self._ws_session_data.get(ATTR_PING_INTERVAL_HANDLE)
if handle:
handle.cancel()
handle = self._ws_session_data.get(ATTR_PING_TIMEOUT_HANDLE)
if handle:
handle.cancel()
yield from self._ws_connection.close()
self._ws_connection = None
self._ws_session_data = None
评论列表
文章目录