Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions src/haclient/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Configuration objects for `HAClient`.

The connection settings, URL handling, and aiohttp session ownership are
captured in `ConnectionConfig`. This isolates configuration parsing from
the rest of the package and keeps `HAClient.__init__` boring.
The connection settings and URL handling are captured in
`ConnectionConfig`. This isolates configuration parsing from the rest of
the package and keeps `HAClient.__init__` boring.
"""

from __future__ import annotations
Expand All @@ -11,8 +11,6 @@
from typing import Literal
from urllib.parse import urlparse, urlunparse

import aiohttp

ServicePolicy = Literal["ws", "rest", "auto"]
"""How `ServiceCaller` should choose between WebSocket and REST.

Expand Down Expand Up @@ -126,25 +124,3 @@ def from_url(
verify_ssl=verify_ssl,
service_policy=service_policy,
)


class SharedSession:
"""Holder for an optional shared `aiohttp.ClientSession`.

Both REST and WebSocket adapters can use the same session instance,
which is the recommended pattern for users who already manage their
own ``aiohttp.ClientSession``. When no session is provided here, each
adapter creates and owns its own.
"""

def __init__(self, session: aiohttp.ClientSession | None = None) -> None:
"""Wrap *session* and record whether it was externally owned.

Parameters
----------
session : aiohttp.ClientSession or None, optional
Pre-existing session to share between transports. ``None``
leaves each adapter to manage its own session.
"""
self.session = session
self.shared = session is not None
Loading