Skip to content

Commit

Permalink
Add option to override ssl config
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Jul 5, 2024
1 parent 3e0d056 commit 185f722
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hass_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import os
import pprint
from collections.abc import Callable
from ssl import SSLContext
from typing import TYPE_CHECKING, Any

import aiohttp
from aiohttp import (
ClientSession,
ClientWebSocketResponse,
Fingerprint,
TCPConnector,
WSMsgType,
client_exceptions,
Expand Down Expand Up @@ -262,21 +264,22 @@ def remove_listener():

return remove_listener

async def connect(self) -> None:
async def connect(self, ssl: SSLContext | bool | Fingerprint | None = True) -> None:
"""Connect to the websocket server."""
if self.connected:
# already connected
return
if not self._http_session_provided and self._http_session is None:
self._http_session = ClientSession(
loop=self._loop, connector=TCPConnector(enable_cleanup_closed=True)
loop=self._loop,
connector=TCPConnector(enable_cleanup_closed=True),
)
ws_url = self._websocket_url or "ws://supervisor/core/websocket"
ws_token = self._token or os.environ.get("HASSIO_TOKEN")
LOGGER.debug("Connecting to Home Assistant Websocket API on %s", ws_url)
try:
self._client = await self._http_session.ws_connect(
ws_url, heartbeat=55, max_msg_size=MAX_MESSAGE_SIZE
ws_url, heartbeat=55, max_msg_size=MAX_MESSAGE_SIZE, ssl=ssl
)
version_msg: AuthRequiredMessage = await self._client.receive_json()
self._version = version_msg["ha_version"]
Expand Down

0 comments on commit 185f722

Please sign in to comment.