diff --git a/homeassistant/components/hassio/http.py b/homeassistant/components/hassio/http.py index 84b49af11c2..0d23a953128 100644 --- a/homeassistant/components/hassio/http.py +++ b/homeassistant/components/hassio/http.py @@ -157,7 +157,7 @@ class HassIOView(HomeAssistantView): if path == "backups/new/upload": # We need to reuse the full content type that includes the boundary # pylint: disable-next=protected-access - headers[CONTENT_TYPE] = request._stored_content_type # type: ignore[assignment] + headers[CONTENT_TYPE] = request._stored_content_type try: client = await self._websession.request( diff --git a/homeassistant/helpers/aiohttp_client.py b/homeassistant/helpers/aiohttp_client.py index 1948d3bca95..20351efff53 100644 --- a/homeassistant/helpers/aiohttp_client.py +++ b/homeassistant/helpers/aiohttp_client.py @@ -4,6 +4,7 @@ from __future__ import annotations import asyncio from collections.abc import Awaitable, Callable from contextlib import suppress +from ssl import SSLContext import sys from types import MappingProxyType from typing import TYPE_CHECKING, Any, cast @@ -65,8 +66,10 @@ async def _noop_wait(*args: Any, **kwargs: Any) -> None: return -# pylint: disable-next=protected-access -web.BaseSite._wait = _noop_wait # type: ignore[method-assign] +# TODO: Remove version check with aiohttp 3.9.0 # pylint: disable=fixme +if sys.version_info >= (3, 12): + # pylint: disable-next=protected-access + web.BaseSite._wait = _noop_wait # type: ignore[method-assign] class HassClientResponse(aiohttp.ClientResponse): @@ -286,7 +289,7 @@ def _async_get_connector( return cast(aiohttp.BaseConnector, hass.data[key]) if verify_ssl: - ssl_context = ssl_util.get_default_context() + ssl_context: bool | SSLContext = ssl_util.get_default_context() else: ssl_context = ssl_util.get_default_no_verify_context() diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index d9f493ce723..2a5ed1274b2 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -1,5 +1,6 @@ aiodiscover==1.5.1 -aiohttp==3.9.0b0 +aiohttp==3.8.5;python_version<'3.12' +aiohttp==3.9.0b0;python_version>='3.12' aiohttp_cors==0.7.0 astral==2.2 async-upnp-client==0.36.1 diff --git a/pyproject.toml b/pyproject.toml index 508b2c06b9e..5cc122850ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,8 @@ classifiers = [ ] requires-python = ">=3.11.0" dependencies = [ - "aiohttp==3.9.0b0", + "aiohttp==3.9.0b0;python_version>='3.12'", + "aiohttp==3.8.5;python_version<'3.12'", "astral==2.2", "attrs==23.1.0", "atomicwrites-homeassistant==1.4.1", diff --git a/requirements.txt b/requirements.txt index 3d64dbe69ff..e6359a6bfd1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,8 @@ -c homeassistant/package_constraints.txt # Home Assistant Core -aiohttp==3.9.0b0 +aiohttp==3.9.0b0;python_version>='3.12' +aiohttp==3.8.5;python_version<'3.12' astral==2.2 attrs==23.1.0 atomicwrites-homeassistant==1.4.1 diff --git a/tests/components/generic/test_camera.py b/tests/components/generic/test_camera.py index 8bfd0a66dd5..aecfcbc29c1 100644 --- a/tests/components/generic/test_camera.py +++ b/tests/components/generic/test_camera.py @@ -1,6 +1,7 @@ """The tests for generic camera component.""" import asyncio from http import HTTPStatus +import sys from unittest.mock import patch import aiohttp @@ -163,10 +164,17 @@ async def test_limit_refetch( hass.states.async_set("sensor.temp", "5") - with pytest.raises(aiohttp.ServerTimeoutError), patch( - "asyncio.timeout", side_effect=asyncio.TimeoutError() - ): - resp = await client.get("/api/camera_proxy/camera.config_test") + # TODO: Remove version check with aiohttp 3.9.0 + if sys.version_info >= (3, 12): + with pytest.raises(aiohttp.ServerTimeoutError), patch( + "asyncio.timeout", side_effect=asyncio.TimeoutError() + ): + resp = await client.get("/api/camera_proxy/camera.config_test") + else: + with pytest.raises(aiohttp.ServerTimeoutError), patch( + "async_timeout.timeout", side_effect=asyncio.TimeoutError() + ): + resp = await client.get("/api/camera_proxy/camera.config_test") assert respx.calls.call_count == 1 assert resp.status == HTTPStatus.OK diff --git a/tests/util/test_aiohttp.py b/tests/util/test_aiohttp.py index 496e6373ba5..bfdc3c3e949 100644 --- a/tests/util/test_aiohttp.py +++ b/tests/util/test_aiohttp.py @@ -1,4 +1,6 @@ """Test aiohttp request helper.""" +import sys + from aiohttp import web from homeassistant.util import aiohttp @@ -48,11 +50,22 @@ def test_serialize_text() -> None: def test_serialize_body_str() -> None: """Test serializing a response with a str as body.""" response = web.Response(status=201, body="Hello") - assert aiohttp.serialize_response(response) == { - "status": 201, - "body": "Hello", - "headers": {"Content-Type": "text/plain; charset=utf-8"}, - } + # TODO: Remove version check with aiohttp 3.9.0 + if sys.version_info >= (3, 12): + assert aiohttp.serialize_response(response) == { + "status": 201, + "body": "Hello", + "headers": {"Content-Type": "text/plain; charset=utf-8"}, + } + else: + assert aiohttp.serialize_response(response) == { + "status": 201, + "body": "Hello", + "headers": { + "Content-Length": "5", + "Content-Type": "text/plain; charset=utf-8", + }, + } def test_serialize_body_None() -> None: