From 20bdcc7fffc0918de4cee51244a15033075e0f92 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 11 Jan 2022 17:33:50 +0100 Subject: [PATCH] Replace hass.helpers: async_get_clientsession() (#63910) --- homeassistant/components/alexa/state_report.py | 9 +++++---- homeassistant/components/cloud/__init__.py | 3 ++- homeassistant/components/cloud/http_api.py | 3 ++- homeassistant/components/config/core.py | 3 ++- homeassistant/components/daikin/__init__.py | 3 ++- homeassistant/components/daikin/config_flow.py | 3 ++- homeassistant/components/ebox/sensor.py | 3 ++- homeassistant/components/fido/sensor.py | 3 ++- homeassistant/components/freedns/__init__.py | 3 ++- homeassistant/components/google_domains/__init__.py | 3 ++- homeassistant/components/hassio/__init__.py | 3 ++- homeassistant/components/hassio/ingress.py | 3 ++- homeassistant/components/melcloud/__init__.py | 3 ++- homeassistant/components/melcloud/config_flow.py | 5 +++-- homeassistant/components/mutesync/__init__.py | 3 ++- homeassistant/components/mutesync/config_flow.py | 3 ++- homeassistant/components/no_ip/__init__.py | 7 +++++-- homeassistant/components/point/__init__.py | 3 ++- homeassistant/components/point/config_flow.py | 5 +++-- homeassistant/components/ps4/__init__.py | 5 ++--- homeassistant/components/ps4/config_flow.py | 3 ++- homeassistant/components/sharkiq/__init__.py | 3 ++- homeassistant/components/sharkiq/config_flow.py | 3 ++- homeassistant/components/upc_connect/device_tracker.py | 3 ++- homeassistant/components/viaggiatreno/sensor.py | 3 ++- tests/components/cloud/test_alexa_config.py | 3 ++- tests/components/hassio/conftest.py | 3 ++- tests/util/test_location.py | 3 ++- 28 files changed, 64 insertions(+), 36 deletions(-) diff --git a/homeassistant/components/alexa/state_report.py b/homeassistant/components/alexa/state_report.py index 767bfa18224..115dd308596 100644 --- a/homeassistant/components/alexa/state_report.py +++ b/homeassistant/components/alexa/state_report.py @@ -11,6 +11,7 @@ import async_timeout from homeassistant.const import MATCH_ALL, STATE_ON from homeassistant.core import HomeAssistant, State, callback +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.significant_change import create_checker import homeassistant.util.dt as dt_util @@ -129,7 +130,7 @@ async def async_send_changereport_message( message.set_endpoint_full(token, endpoint) message_serialized = message.serialize() - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) try: async with async_timeout.timeout(DEFAULT_TIMEOUT): @@ -198,7 +199,7 @@ async def async_send_add_or_update_message(hass, config, entity_ids): ) message_serialized = message.serialize() - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) return await session.post( config.endpoint, headers=headers, json=message_serialized, allow_redirects=True @@ -231,7 +232,7 @@ async def async_send_delete_message(hass, config, entity_ids): ) message_serialized = message.serialize() - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) return await session.post( config.endpoint, headers=headers, json=message_serialized, allow_redirects=True @@ -261,7 +262,7 @@ async def async_send_doorbell_event_message(hass, config, alexa_entity): message.set_endpoint_full(token, endpoint) message_serialized = message.serialize() - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) try: async with async_timeout.timeout(DEFAULT_TIMEOUT): diff --git a/homeassistant/components/cloud/__init__.py b/homeassistant/components/cloud/__init__.py index 543744199b9..272080d63fd 100644 --- a/homeassistant/components/cloud/__init__.py +++ b/homeassistant/components/cloud/__init__.py @@ -17,6 +17,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv, entityfilter +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass from homeassistant.util.aiohttp import MockRequest @@ -187,7 +188,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: await prefs.async_initialize() # Initialize Cloud - websession = hass.helpers.aiohttp_client.async_get_clientsession() + websession = async_get_clientsession(hass) client = CloudClient(hass, prefs, websession, alexa_conf, google_conf) cloud = hass.data[DOMAIN] = Cloud(client, **kwargs) diff --git a/homeassistant/components/cloud/http_api.py b/homeassistant/components/cloud/http_api.py index 2fbb1c447ae..9ec6acfc23e 100644 --- a/homeassistant/components/cloud/http_api.py +++ b/homeassistant/components/cloud/http_api.py @@ -21,6 +21,7 @@ from homeassistant.components.google_assistant import helpers as google_helpers from homeassistant.components.http import HomeAssistantView from homeassistant.components.http.data_validator import RequestDataValidator from homeassistant.components.websocket_api import const as ws_const +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.util.location import async_detect_location_info from .const import ( @@ -224,7 +225,7 @@ class CloudRegisterView(HomeAssistantView): client_metadata = None if location_info := await async_detect_location_info( - hass.helpers.aiohttp_client.async_get_clientsession() + async_get_clientsession(hass) ): client_metadata = { "NC_COUNTRY_CODE": location_info.country_code, diff --git a/homeassistant/components/config/core.py b/homeassistant/components/config/core.py index a6b39e556aa..e9e54a688c4 100644 --- a/homeassistant/components/config/core.py +++ b/homeassistant/components/config/core.py @@ -7,6 +7,7 @@ from homeassistant.components.http import HomeAssistantView from homeassistant.config import async_check_ha_config_file from homeassistant.const import CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.util import location @@ -67,7 +68,7 @@ async def websocket_update_config(hass, connection, msg): @websocket_api.websocket_command({"type": "config/core/detect"}) async def websocket_detect_config(hass, connection, msg): """Detect core config.""" - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) location_info = await location.async_detect_location_info(session) info = {} diff --git a/homeassistant/components/daikin/__init__.py b/homeassistant/components/daikin/__init__.py index dcdc924fb4a..5f05355374c 100644 --- a/homeassistant/components/daikin/__init__.py +++ b/homeassistant/components/daikin/__init__.py @@ -11,6 +11,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.entity import DeviceInfo @@ -63,7 +64,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def daikin_api_setup(hass, host, key, uuid, password): """Create a Daikin instance only once.""" - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) try: async with timeout(TIMEOUT): device = await Appliance.factory( diff --git a/homeassistant/components/daikin/config_flow.py b/homeassistant/components/daikin/config_flow.py index 0084a89172f..fb34c947fa7 100644 --- a/homeassistant/components/daikin/config_flow.py +++ b/homeassistant/components/daikin/config_flow.py @@ -13,6 +13,7 @@ from homeassistant import config_entries from homeassistant.components import zeroconf from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD from homeassistant.data_entry_flow import FlowResult +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import CONF_UUID, DOMAIN, KEY_MAC, TIMEOUT @@ -72,7 +73,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN): async with timeout(TIMEOUT): device = await Appliance.factory( host, - self.hass.helpers.aiohttp_client.async_get_clientsession(), + async_get_clientsession(self.hass), key=key, uuid=uuid, password=password, diff --git a/homeassistant/components/ebox/sensor.py b/homeassistant/components/ebox/sensor.py index 851d8b8ab9b..ef6c0f4b323 100644 --- a/homeassistant/components/ebox/sensor.py +++ b/homeassistant/components/ebox/sensor.py @@ -28,6 +28,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -149,7 +150,7 @@ async def async_setup_platform( username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) - httpsession = hass.helpers.aiohttp_client.async_get_clientsession() + httpsession = async_get_clientsession(hass) ebox_data = EBoxData(username, password, httpsession) name = config.get(CONF_NAME) diff --git a/homeassistant/components/fido/sensor.py b/homeassistant/components/fido/sensor.py index b7a0c7745cb..2d0cd4ab53a 100644 --- a/homeassistant/components/fido/sensor.py +++ b/homeassistant/components/fido/sensor.py @@ -27,6 +27,7 @@ from homeassistant.const import ( TIME_MINUTES, ) from homeassistant.core import HomeAssistant +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -189,7 +190,7 @@ async def async_setup_platform( username = config[CONF_USERNAME] password = config[CONF_PASSWORD] - httpsession = hass.helpers.aiohttp_client.async_get_clientsession() + httpsession = async_get_clientsession(hass) fido_data = FidoData(username, password, httpsession) ret = await fido_data.async_update() if ret is False: diff --git a/homeassistant/components/freedns/__init__.py b/homeassistant/components/freedns/__init__.py index 30bddbdaeee..bc651e726ec 100644 --- a/homeassistant/components/freedns/__init__.py +++ b/homeassistant/components/freedns/__init__.py @@ -9,6 +9,7 @@ import voluptuous as vol from homeassistant.const import CONF_ACCESS_TOKEN, CONF_SCAN_INTERVAL, CONF_URL from homeassistant.core import HomeAssistant +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.typing import ConfigType @@ -44,7 +45,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: auth_token = conf.get(CONF_ACCESS_TOKEN) update_interval = conf[CONF_SCAN_INTERVAL] - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) result = await _update_freedns(hass, session, url, auth_token) diff --git a/homeassistant/components/google_domains/__init__.py b/homeassistant/components/google_domains/__init__.py index 51f29e6d68a..8ccc9d78c64 100644 --- a/homeassistant/components/google_domains/__init__.py +++ b/homeassistant/components/google_domains/__init__.py @@ -9,6 +9,7 @@ import voluptuous as vol from homeassistant.const import CONF_DOMAIN, CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME from homeassistant.core import HomeAssistant +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.typing import ConfigType @@ -42,7 +43,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: password = config[DOMAIN].get(CONF_PASSWORD) timeout = config[DOMAIN].get(CONF_TIMEOUT) - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) result = await _update_google_domains( hass, session, domain, user, password, timeout diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index 15d0a885d60..0ac512d0034 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -33,6 +33,7 @@ from homeassistant.core import ( ) from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv, recorder +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import ( DeviceEntryType, DeviceRegistry, @@ -424,7 +425,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: async_load_websocket_api(hass) host = os.environ["HASSIO"] - websession = hass.helpers.aiohttp_client.async_get_clientsession() + websession = async_get_clientsession(hass) hass.data[DOMAIN] = hassio = HassIO(hass.loop, websession, host) if not await hassio.is_connected(): diff --git a/homeassistant/components/hassio/ingress.py b/homeassistant/components/hassio/ingress.py index 5369089d0f0..91aca485917 100644 --- a/homeassistant/components/hassio/ingress.py +++ b/homeassistant/components/hassio/ingress.py @@ -13,6 +13,7 @@ from multidict import CIMultiDict from homeassistant.components.http import HomeAssistantView from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import X_HASSIO, X_INGRESS_PATH @@ -22,7 +23,7 @@ _LOGGER = logging.getLogger(__name__) @callback def async_setup_ingress_view(hass: HomeAssistant, host: str): """Auth setup.""" - websession = hass.helpers.aiohttp_client.async_get_clientsession() + websession = async_get_clientsession(hass) hassio_ingress = HassIOIngress(host, websession) hass.http.register_view(hassio_ingress) diff --git a/homeassistant/components/melcloud/__init__.py b/homeassistant/components/melcloud/__init__.py index 1108848a006..6342c2bc3be 100644 --- a/homeassistant/components/melcloud/__init__.py +++ b/homeassistant/components/melcloud/__init__.py @@ -15,6 +15,7 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import CONF_TOKEN, CONF_USERNAME, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.entity import DeviceInfo @@ -143,7 +144,7 @@ class MelCloudDevice: async def mel_devices_setup(hass, token) -> list[MelCloudDevice]: """Query connected devices from MELCloud.""" - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) try: async with timeout(10): all_devices = await get_devices( diff --git a/homeassistant/components/melcloud/config_flow.py b/homeassistant/components/melcloud/config_flow.py index 139a4e8e44d..6b3eeaa19ae 100644 --- a/homeassistant/components/melcloud/config_flow.py +++ b/homeassistant/components/melcloud/config_flow.py @@ -11,6 +11,7 @@ import voluptuous as vol from homeassistant import config_entries from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import DOMAIN @@ -47,11 +48,11 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN): acquired_token = await pymelcloud.login( username, password, - self.hass.helpers.aiohttp_client.async_get_clientsession(), + async_get_clientsession(self.hass), ) await pymelcloud.get_devices( acquired_token, - self.hass.helpers.aiohttp_client.async_get_clientsession(), + async_get_clientsession(self.hass), ) except ClientResponseError as err: if err.status in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN): diff --git a/homeassistant/components/mutesync/__init__.py b/homeassistant/components/mutesync/__init__.py index 50e485d96d2..4cdd97f446b 100644 --- a/homeassistant/components/mutesync/__init__.py +++ b/homeassistant/components/mutesync/__init__.py @@ -10,6 +10,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import update_coordinator +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import DOMAIN, UPDATE_INTERVAL_IN_MEETING, UPDATE_INTERVAL_NOT_IN_MEETING @@ -21,7 +22,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: client = mutesync.PyMutesync( entry.data["token"], entry.data["host"], - hass.helpers.aiohttp_client.async_get_clientsession(), + async_get_clientsession(hass), ) async def update_data(): diff --git a/homeassistant/components/mutesync/config_flow.py b/homeassistant/components/mutesync/config_flow.py index 99412ed1795..7ebbc718a5b 100644 --- a/homeassistant/components/mutesync/config_flow.py +++ b/homeassistant/components/mutesync/config_flow.py @@ -13,6 +13,7 @@ from homeassistant import config_entries from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResult from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import DOMAIN @@ -24,7 +25,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user. """ - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) try: async with async_timeout.timeout(5): token = await mutesync.authenticate(session, data["host"]) diff --git a/homeassistant/components/no_ip/__init__.py b/homeassistant/components/no_ip/__init__.py index 245222724ab..5340e926e62 100644 --- a/homeassistant/components/no_ip/__init__.py +++ b/homeassistant/components/no_ip/__init__.py @@ -11,7 +11,10 @@ import voluptuous as vol from homeassistant.const import CONF_DOMAIN, CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME from homeassistant.core import HomeAssistant -from homeassistant.helpers.aiohttp_client import SERVER_SOFTWARE +from homeassistant.helpers.aiohttp_client import ( + SERVER_SOFTWARE, + async_get_clientsession, +) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.typing import ConfigType @@ -62,7 +65,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: auth_str = base64.b64encode(f"{user}:{password}".encode()) - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) result = await _update_no_ip(hass, session, domain, auth_str, timeout) diff --git a/homeassistant/components/point/__init__.py b/homeassistant/components/point/__init__.py index f6587ea774a..05fe13f3419 100644 --- a/homeassistant/components/point/__init__.py +++ b/homeassistant/components/point/__init__.py @@ -18,6 +18,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import config_validation as cv, device_registry +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, @@ -88,7 +89,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ) session = PointSession( - hass.helpers.aiohttp_client.async_get_clientsession(), + async_get_clientsession(hass), entry.data["refresh_args"][CONF_CLIENT_ID], entry.data["refresh_args"][CONF_CLIENT_SECRET], token=entry.data[CONF_TOKEN], diff --git a/homeassistant/components/point/config_flow.py b/homeassistant/components/point/config_flow.py index 8520e53654f..994047a2758 100644 --- a/homeassistant/components/point/config_flow.py +++ b/homeassistant/components/point/config_flow.py @@ -11,6 +11,7 @@ from homeassistant import config_entries from homeassistant.components.http import HomeAssistantView from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET from homeassistant.core import callback +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import DOMAIN @@ -112,7 +113,7 @@ class PointFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): client_id = flow[CONF_CLIENT_ID] client_secret = flow[CONF_CLIENT_SECRET] point_session = PointSession( - self.hass.helpers.aiohttp_client.async_get_clientsession(), + async_get_clientsession(self.hass), client_id, client_secret, ) @@ -144,7 +145,7 @@ class PointFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): client_id = flow[CONF_CLIENT_ID] client_secret = flow[CONF_CLIENT_SECRET] point_session = PointSession( - self.hass.helpers.aiohttp_client.async_get_clientsession(), + async_get_clientsession(self.hass), client_id, client_secret, ) diff --git a/homeassistant/components/ps4/__init__.py b/homeassistant/components/ps4/__init__.py index 7498a74f8d2..9293d684a85 100644 --- a/homeassistant/components/ps4/__init__.py +++ b/homeassistant/components/ps4/__init__.py @@ -24,6 +24,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant, ServiceCall, split_entity_id from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv, entity_registry +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.typing import ConfigType from homeassistant.util import location from homeassistant.util.json import load_json, save_json @@ -98,9 +99,7 @@ async def async_migrate_entry(hass, entry): # Migrate Version 1 -> Version 2: New region codes. if version == 1: - loc = await location.async_detect_location_info( - hass.helpers.aiohttp_client.async_get_clientsession() - ) + loc = await location.async_detect_location_info(async_get_clientsession(hass)) if loc: country = COUNTRYCODE_NAMES.get(loc.country_code) if country in COUNTRIES: diff --git a/homeassistant/components/ps4/config_flow.py b/homeassistant/components/ps4/config_flow.py index 23ee1e061e3..0865d09a460 100644 --- a/homeassistant/components/ps4/config_flow.py +++ b/homeassistant/components/ps4/config_flow.py @@ -15,6 +15,7 @@ from homeassistant.const import ( CONF_REGION, CONF_TOKEN, ) +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.util import location from .const import ( @@ -180,7 +181,7 @@ class PlayStation4FlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # Try to find region automatically. if not self.location: self.location = await location.async_detect_location_info( - self.hass.helpers.aiohttp_client.async_get_clientsession() + async_get_clientsession(self.hass) ) if self.location: country = COUNTRYCODE_NAMES.get(self.location.country_code) diff --git a/homeassistant/components/sharkiq/__init__.py b/homeassistant/components/sharkiq/__init__.py index 23f92c3bfdc..08235a57780 100644 --- a/homeassistant/components/sharkiq/__init__.py +++ b/homeassistant/components/sharkiq/__init__.py @@ -15,6 +15,7 @@ from homeassistant import exceptions from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import _LOGGER, API_TIMEOUT, DOMAIN, PLATFORMS from .update_coordinator import SharkIqUpdateCoordinator @@ -45,7 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b ayla_api = get_ayla_api( username=config_entry.data[CONF_USERNAME], password=config_entry.data[CONF_PASSWORD], - websession=hass.helpers.aiohttp_client.async_get_clientsession(), + websession=async_get_clientsession(hass), ) try: diff --git a/homeassistant/components/sharkiq/config_flow.py b/homeassistant/components/sharkiq/config_flow.py index 53306e15d12..2910521e7ae 100644 --- a/homeassistant/components/sharkiq/config_flow.py +++ b/homeassistant/components/sharkiq/config_flow.py @@ -10,6 +10,7 @@ import voluptuous as vol from homeassistant import config_entries, core, exceptions from homeassistant.const import CONF_PASSWORD, CONF_USERNAME +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import _LOGGER, DOMAIN @@ -23,7 +24,7 @@ async def validate_input(hass: core.HomeAssistant, data): ayla_api = get_ayla_api( username=data[CONF_USERNAME], password=data[CONF_PASSWORD], - websession=hass.helpers.aiohttp_client.async_get_clientsession(hass), + websession=async_get_clientsession(hass), ) try: diff --git a/homeassistant/components/upc_connect/device_tracker.py b/homeassistant/components/upc_connect/device_tracker.py index 9908520342a..35960dcf706 100644 --- a/homeassistant/components/upc_connect/device_tracker.py +++ b/homeassistant/components/upc_connect/device_tracker.py @@ -14,6 +14,7 @@ from homeassistant.components.device_tracker import ( ) from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.typing import ConfigType @@ -34,7 +35,7 @@ async def async_get_scanner( ) -> DeviceScanner | None: """Return the UPC device scanner.""" conf = config[DOMAIN] - session = hass.helpers.aiohttp_client.async_get_clientsession() + session = async_get_clientsession(hass) connect_box = ConnectBox(session, conf[CONF_PASSWORD], host=conf[CONF_HOST]) # Check login data diff --git a/homeassistant/components/viaggiatreno/sensor.py b/homeassistant/components/viaggiatreno/sensor.py index 6d1e0f94cab..3fdca6653d0 100644 --- a/homeassistant/components/viaggiatreno/sensor.py +++ b/homeassistant/components/viaggiatreno/sensor.py @@ -13,6 +13,7 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ATTR_ATTRIBUTION, TIME_MINUTES from homeassistant.core import HomeAssistant +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -79,7 +80,7 @@ async def async_setup_platform( async def async_http_request(hass, uri): """Perform actual request.""" try: - session = hass.helpers.aiohttp_client.async_get_clientsession(hass) + session = async_get_clientsession(hass) async with async_timeout.timeout(REQUEST_TIMEOUT): req = await session.get(uri) if req.status != HTTPStatus.OK: diff --git a/tests/components/cloud/test_alexa_config.py b/tests/components/cloud/test_alexa_config.py index 8d08e924be7..b034fc21a27 100644 --- a/tests/components/cloud/test_alexa_config.py +++ b/tests/components/cloud/test_alexa_config.py @@ -5,6 +5,7 @@ from unittest.mock import AsyncMock, Mock, patch import pytest from homeassistant.components.cloud import ALEXA_SCHEMA, alexa_config +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED from homeassistant.util.dt import utcnow @@ -127,7 +128,7 @@ async def test_alexa_config_invalidate_token(hass, cloud_prefs, aioclient_mock): Mock( alexa_access_token_url="http://example/alexa_token", auth=Mock(async_check_token=AsyncMock()), - websession=hass.helpers.aiohttp_client.async_get_clientsession(), + websession=async_get_clientsession(hass), ), ) diff --git a/tests/components/hassio/conftest.py b/tests/components/hassio/conftest.py index efa983c3440..89a8c6f5c51 100644 --- a/tests/components/hassio/conftest.py +++ b/tests/components/hassio/conftest.py @@ -6,6 +6,7 @@ import pytest from homeassistant.components.hassio.handler import HassIO, HassioAPIError from homeassistant.core import CoreState +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.setup import async_setup_component from . import HASSIO_TOKEN @@ -70,7 +71,7 @@ def hassio_handler(hass, aioclient_mock): """Create mock hassio handler.""" async def get_client_session(): - return hass.helpers.aiohttp_client.async_get_clientsession() + return async_get_clientsession(hass) websession = hass.loop.run_until_complete(get_client_session()) diff --git a/tests/util/test_location.py b/tests/util/test_location.py index d25e6859727..3dff36744ee 100644 --- a/tests/util/test_location.py +++ b/tests/util/test_location.py @@ -4,6 +4,7 @@ from unittest.mock import Mock, patch import aiohttp import pytest +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.util.location as location_util from tests.common import load_fixture @@ -27,7 +28,7 @@ DISTANCE_MILES = 3632.78 @pytest.fixture async def session(hass): """Return aioclient session.""" - return hass.helpers.aiohttp_client.async_get_clientsession() + return async_get_clientsession(hass) @pytest.fixture