1 """HomeAssistant specific aiohttp Site."""
3 from __future__
import annotations
6 from ssl
import SSLContext
8 from aiohttp
import web
13 """HomeAssistant specific aiohttp Site.
15 Vanilla TCPSite accepts only str as host. However, the underlying asyncio's
16 create_server() implementation does take a list of strings to bind to multiple
17 host IP's. To support multiple server_host entries (e.g. to enable dual-stack
18 explicitly), we would like to pass an array of strings. Bring our own
19 implementation inspired by TCPSite.
21 Custom TCPSite can be dropped when https://github.com/aio-libs/aiohttp/pull/4894
25 __slots__ = (
"_host",
"_port",
"_reuse_address",
"_reuse_port",
"_hosturl")
29 runner: web.BaseRunner,
30 host: str | list[str] |
None,
33 ssl_context: SSLContext |
None =
None,
35 reuse_address: bool |
None =
None,
36 reuse_port: bool |
None =
None,
38 """Initialize HomeAssistantTCPSite."""
41 ssl_context=ssl_context,
51 """Return server URL."""
52 scheme =
"https" if self._ssl_context
else "http"
53 host = self.
_host_host[0]
if isinstance(self.
_host_host, list)
else "0.0.0.0"
54 return str(URL.build(scheme=scheme, host=host, port=self.
_port_port))
59 loop = asyncio.get_running_loop()
60 server = self._runner.server
61 assert server
is not None
62 self.
_server_server = await loop.create_server(
66 ssl=self._ssl_context,
67 backlog=self._backlog,
None __init__(self, web.BaseRunner runner, str|list[str]|None host, int port, *SSLContext|None ssl_context=None, int backlog=128, bool|None reuse_address=None, bool|None reuse_port=None)