diff --git a/homeassistant/components/reolink/host.py b/homeassistant/components/reolink/host.py index 58ae191eb9f..527f40469b4 100644 --- a/homeassistant/components/reolink/host.py +++ b/homeassistant/components/reolink/host.py @@ -25,6 +25,7 @@ from homeassistant.const import ( ) from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback from homeassistant.helpers import issue_registry as ir +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import format_mac from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_call_later @@ -64,10 +65,12 @@ class ReolinkHost: ) -> None: """Initialize Reolink Host. Could be either NVR, or Camera.""" self._hass: HomeAssistant = hass - - self._clientsession: aiohttp.ClientSession | None = None self._unique_id: str = "" + def get_aiohttp_session() -> aiohttp.ClientSession: + """Return the HA aiohttp session.""" + return async_get_clientsession(hass, verify_ssl=False) + self._api = Host( config[CONF_HOST], config[CONF_USERNAME], @@ -76,6 +79,7 @@ class ReolinkHost: use_https=config.get(CONF_USE_HTTPS), protocol=options[CONF_PROTOCOL], timeout=DEFAULT_TIMEOUT, + aiohttp_get_session_callback=get_aiohttp_session, ) self.last_wake: float = 0 diff --git a/tests/components/reolink/test_config_flow.py b/tests/components/reolink/test_config_flow.py index 4c362e150ca..4d89906a768 100644 --- a/tests/components/reolink/test_config_flow.py +++ b/tests/components/reolink/test_config_flow.py @@ -2,8 +2,9 @@ import json from typing import Any -from unittest.mock import AsyncMock, MagicMock, call +from unittest.mock import ANY, AsyncMock, MagicMock, call +from aiohttp import ClientSession from freezegun.api import FrozenDateTimeFactory import pytest from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkError @@ -492,11 +493,14 @@ async def test_dhcp_ip_update( use_https=TEST_USE_HTTPS, protocol=DEFAULT_PROTOCOL, timeout=DEFAULT_TIMEOUT, + aiohttp_get_session_callback=ANY, ) assert expected_call in reolink_connect_class.call_args_list for exc_call in reolink_connect_class.call_args_list: assert exc_call[0][0] in host_call_list + get_session = exc_call[1]["aiohttp_get_session_callback"] + assert isinstance(get_session(), ClientSession) assert result["type"] is FlowResultType.ABORT assert result["reason"] == "already_configured"