Replace hass.helpers: async_get_clientsession() (#63910)

This commit is contained in:
Franck Nijhof 2022-01-11 17:33:50 +01:00 committed by GitHub
parent 43aec6e784
commit 20bdcc7fff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 64 additions and 36 deletions

View file

@ -11,6 +11,7 @@ import async_timeout
from homeassistant.const import MATCH_ALL, STATE_ON from homeassistant.const import MATCH_ALL, STATE_ON
from homeassistant.core import HomeAssistant, State, callback from homeassistant.core import HomeAssistant, State, callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.significant_change import create_checker from homeassistant.helpers.significant_change import create_checker
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -129,7 +130,7 @@ async def async_send_changereport_message(
message.set_endpoint_full(token, endpoint) message.set_endpoint_full(token, endpoint)
message_serialized = message.serialize() message_serialized = message.serialize()
session = hass.helpers.aiohttp_client.async_get_clientsession() session = async_get_clientsession(hass)
try: try:
async with async_timeout.timeout(DEFAULT_TIMEOUT): 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() message_serialized = message.serialize()
session = hass.helpers.aiohttp_client.async_get_clientsession() session = async_get_clientsession(hass)
return await session.post( return await session.post(
config.endpoint, headers=headers, json=message_serialized, allow_redirects=True 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() message_serialized = message.serialize()
session = hass.helpers.aiohttp_client.async_get_clientsession() session = async_get_clientsession(hass)
return await session.post( return await session.post(
config.endpoint, headers=headers, json=message_serialized, allow_redirects=True 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.set_endpoint_full(token, endpoint)
message_serialized = message.serialize() message_serialized = message.serialize()
session = hass.helpers.aiohttp_client.async_get_clientsession() session = async_get_clientsession(hass)
try: try:
async with async_timeout.timeout(DEFAULT_TIMEOUT): async with async_timeout.timeout(DEFAULT_TIMEOUT):

View file

@ -17,6 +17,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entityfilter 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.helpers.typing import ConfigType
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
from homeassistant.util.aiohttp import MockRequest from homeassistant.util.aiohttp import MockRequest
@ -187,7 +188,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
await prefs.async_initialize() await prefs.async_initialize()
# Initialize Cloud # Initialize Cloud
websession = hass.helpers.aiohttp_client.async_get_clientsession() websession = async_get_clientsession(hass)
client = CloudClient(hass, prefs, websession, alexa_conf, google_conf) client = CloudClient(hass, prefs, websession, alexa_conf, google_conf)
cloud = hass.data[DOMAIN] = Cloud(client, **kwargs) cloud = hass.data[DOMAIN] = Cloud(client, **kwargs)

View file

@ -21,6 +21,7 @@ from homeassistant.components.google_assistant import helpers as google_helpers
from homeassistant.components.http import HomeAssistantView from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http.data_validator import RequestDataValidator from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.components.websocket_api import const as ws_const 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 homeassistant.util.location import async_detect_location_info
from .const import ( from .const import (
@ -224,7 +225,7 @@ class CloudRegisterView(HomeAssistantView):
client_metadata = None client_metadata = None
if location_info := await async_detect_location_info( if location_info := await async_detect_location_info(
hass.helpers.aiohttp_client.async_get_clientsession() async_get_clientsession(hass)
): ):
client_metadata = { client_metadata = {
"NC_COUNTRY_CODE": location_info.country_code, "NC_COUNTRY_CODE": location_info.country_code,

View file

@ -7,6 +7,7 @@ from homeassistant.components.http import HomeAssistantView
from homeassistant.config import async_check_ha_config_file from homeassistant.config import async_check_ha_config_file
from homeassistant.const import CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC from homeassistant.const import CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.util import location 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"}) @websocket_api.websocket_command({"type": "config/core/detect"})
async def websocket_detect_config(hass, connection, msg): async def websocket_detect_config(hass, connection, msg):
"""Detect core config.""" """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) location_info = await location.async_detect_location_info(session)
info = {} info = {}

View file

@ -11,6 +11,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD, Platform from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.entity import DeviceInfo 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): async def daikin_api_setup(hass, host, key, uuid, password):
"""Create a Daikin instance only once.""" """Create a Daikin instance only once."""
session = hass.helpers.aiohttp_client.async_get_clientsession() session = async_get_clientsession(hass)
try: try:
async with timeout(TIMEOUT): async with timeout(TIMEOUT):
device = await Appliance.factory( device = await Appliance.factory(

View file

@ -13,6 +13,7 @@ from homeassistant import config_entries
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD
from homeassistant.data_entry_flow import FlowResult 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 from .const import CONF_UUID, DOMAIN, KEY_MAC, TIMEOUT
@ -72,7 +73,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
async with timeout(TIMEOUT): async with timeout(TIMEOUT):
device = await Appliance.factory( device = await Appliance.factory(
host, host,
self.hass.helpers.aiohttp_client.async_get_clientsession(), async_get_clientsession(self.hass),
key=key, key=key,
uuid=uuid, uuid=uuid,
password=password, password=password,

View file

@ -28,6 +28,7 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -149,7 +150,7 @@ async def async_setup_platform(
username = config.get(CONF_USERNAME) username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD) password = config.get(CONF_PASSWORD)
httpsession = hass.helpers.aiohttp_client.async_get_clientsession() httpsession = async_get_clientsession(hass)
ebox_data = EBoxData(username, password, httpsession) ebox_data = EBoxData(username, password, httpsession)
name = config.get(CONF_NAME) name = config.get(CONF_NAME)

View file

@ -27,6 +27,7 @@ from homeassistant.const import (
TIME_MINUTES, TIME_MINUTES,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -189,7 +190,7 @@ async def async_setup_platform(
username = config[CONF_USERNAME] username = config[CONF_USERNAME]
password = config[CONF_PASSWORD] password = config[CONF_PASSWORD]
httpsession = hass.helpers.aiohttp_client.async_get_clientsession() httpsession = async_get_clientsession(hass)
fido_data = FidoData(username, password, httpsession) fido_data = FidoData(username, password, httpsession)
ret = await fido_data.async_update() ret = await fido_data.async_update()
if ret is False: if ret is False:

View file

@ -9,6 +9,7 @@ import voluptuous as vol
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_SCAN_INTERVAL, CONF_URL from homeassistant.const import CONF_ACCESS_TOKEN, CONF_SCAN_INTERVAL, CONF_URL
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType 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) auth_token = conf.get(CONF_ACCESS_TOKEN)
update_interval = conf[CONF_SCAN_INTERVAL] 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) result = await _update_freedns(hass, session, url, auth_token)

View file

@ -9,6 +9,7 @@ import voluptuous as vol
from homeassistant.const import CONF_DOMAIN, CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME from homeassistant.const import CONF_DOMAIN, CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType 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) password = config[DOMAIN].get(CONF_PASSWORD)
timeout = config[DOMAIN].get(CONF_TIMEOUT) timeout = config[DOMAIN].get(CONF_TIMEOUT)
session = hass.helpers.aiohttp_client.async_get_clientsession() session = async_get_clientsession(hass)
result = await _update_google_domains( result = await _update_google_domains(
hass, session, domain, user, password, timeout hass, session, domain, user, password, timeout

View file

@ -33,6 +33,7 @@ from homeassistant.core import (
) )
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, recorder from homeassistant.helpers import config_validation as cv, recorder
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.device_registry import ( from homeassistant.helpers.device_registry import (
DeviceEntryType, DeviceEntryType,
DeviceRegistry, DeviceRegistry,
@ -424,7 +425,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
async_load_websocket_api(hass) async_load_websocket_api(hass)
host = os.environ["HASSIO"] 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) hass.data[DOMAIN] = hassio = HassIO(hass.loop, websession, host)
if not await hassio.is_connected(): if not await hassio.is_connected():

View file

@ -13,6 +13,7 @@ from multidict import CIMultiDict
from homeassistant.components.http import HomeAssistantView from homeassistant.components.http import HomeAssistantView
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import X_HASSIO, X_INGRESS_PATH from .const import X_HASSIO, X_INGRESS_PATH
@ -22,7 +23,7 @@ _LOGGER = logging.getLogger(__name__)
@callback @callback
def async_setup_ingress_view(hass: HomeAssistant, host: str): def async_setup_ingress_view(hass: HomeAssistant, host: str):
"""Auth setup.""" """Auth setup."""
websession = hass.helpers.aiohttp_client.async_get_clientsession() websession = async_get_clientsession(hass)
hassio_ingress = HassIOIngress(host, websession) hassio_ingress = HassIOIngress(host, websession)
hass.http.register_view(hassio_ingress) hass.http.register_view(hassio_ingress)

View file

@ -15,6 +15,7 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_TOKEN, CONF_USERNAME, Platform from homeassistant.const import CONF_TOKEN, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
@ -143,7 +144,7 @@ class MelCloudDevice:
async def mel_devices_setup(hass, token) -> list[MelCloudDevice]: async def mel_devices_setup(hass, token) -> list[MelCloudDevice]:
"""Query connected devices from MELCloud.""" """Query connected devices from MELCloud."""
session = hass.helpers.aiohttp_client.async_get_clientsession() session = async_get_clientsession(hass)
try: try:
async with timeout(10): async with timeout(10):
all_devices = await get_devices( all_devices = await get_devices(

View file

@ -11,6 +11,7 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN from .const import DOMAIN
@ -47,11 +48,11 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
acquired_token = await pymelcloud.login( acquired_token = await pymelcloud.login(
username, username,
password, password,
self.hass.helpers.aiohttp_client.async_get_clientsession(), async_get_clientsession(self.hass),
) )
await pymelcloud.get_devices( await pymelcloud.get_devices(
acquired_token, acquired_token,
self.hass.helpers.aiohttp_client.async_get_clientsession(), async_get_clientsession(self.hass),
) )
except ClientResponseError as err: except ClientResponseError as err:
if err.status in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN): if err.status in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN):

View file

@ -10,6 +10,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import update_coordinator 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 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( client = mutesync.PyMutesync(
entry.data["token"], entry.data["token"],
entry.data["host"], entry.data["host"],
hass.helpers.aiohttp_client.async_get_clientsession(), async_get_clientsession(hass),
) )
async def update_data(): async def update_data():

View file

@ -13,6 +13,7 @@ from homeassistant import config_entries
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN 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. 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: try:
async with async_timeout.timeout(5): async with async_timeout.timeout(5):
token = await mutesync.authenticate(session, data["host"]) token = await mutesync.authenticate(session, data["host"])

View file

@ -11,7 +11,10 @@ import voluptuous as vol
from homeassistant.const import CONF_DOMAIN, CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME from homeassistant.const import CONF_DOMAIN, CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME
from homeassistant.core import HomeAssistant 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 import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType 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()) 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) result = await _update_no_ip(hass, session, domain, auth_str, timeout)

View file

@ -18,6 +18,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.dispatcher import ( from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
async_dispatcher_send, async_dispatcher_send,
@ -88,7 +89,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
) )
session = PointSession( 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_ID],
entry.data["refresh_args"][CONF_CLIENT_SECRET], entry.data["refresh_args"][CONF_CLIENT_SECRET],
token=entry.data[CONF_TOKEN], token=entry.data[CONF_TOKEN],

View file

@ -11,6 +11,7 @@ from homeassistant import config_entries
from homeassistant.components.http import HomeAssistantView from homeassistant.components.http import HomeAssistantView
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN from .const import DOMAIN
@ -112,7 +113,7 @@ class PointFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
client_id = flow[CONF_CLIENT_ID] client_id = flow[CONF_CLIENT_ID]
client_secret = flow[CONF_CLIENT_SECRET] client_secret = flow[CONF_CLIENT_SECRET]
point_session = PointSession( point_session = PointSession(
self.hass.helpers.aiohttp_client.async_get_clientsession(), async_get_clientsession(self.hass),
client_id, client_id,
client_secret, client_secret,
) )
@ -144,7 +145,7 @@ class PointFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
client_id = flow[CONF_CLIENT_ID] client_id = flow[CONF_CLIENT_ID]
client_secret = flow[CONF_CLIENT_SECRET] client_secret = flow[CONF_CLIENT_SECRET]
point_session = PointSession( point_session = PointSession(
self.hass.helpers.aiohttp_client.async_get_clientsession(), async_get_clientsession(self.hass),
client_id, client_id,
client_secret, client_secret,
) )

View file

@ -24,6 +24,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, ServiceCall, split_entity_id from homeassistant.core import HomeAssistant, ServiceCall, split_entity_id
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entity_registry 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.helpers.typing import ConfigType
from homeassistant.util import location from homeassistant.util import location
from homeassistant.util.json import load_json, save_json 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. # Migrate Version 1 -> Version 2: New region codes.
if version == 1: if version == 1:
loc = await location.async_detect_location_info( loc = await location.async_detect_location_info(async_get_clientsession(hass))
hass.helpers.aiohttp_client.async_get_clientsession()
)
if loc: if loc:
country = COUNTRYCODE_NAMES.get(loc.country_code) country = COUNTRYCODE_NAMES.get(loc.country_code)
if country in COUNTRIES: if country in COUNTRIES:

View file

@ -15,6 +15,7 @@ from homeassistant.const import (
CONF_REGION, CONF_REGION,
CONF_TOKEN, CONF_TOKEN,
) )
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.util import location from homeassistant.util import location
from .const import ( from .const import (
@ -180,7 +181,7 @@ class PlayStation4FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
# Try to find region automatically. # Try to find region automatically.
if not self.location: if not self.location:
self.location = await location.async_detect_location_info( self.location = await location.async_detect_location_info(
self.hass.helpers.aiohttp_client.async_get_clientsession() async_get_clientsession(self.hass)
) )
if self.location: if self.location:
country = COUNTRYCODE_NAMES.get(self.location.country_code) country = COUNTRYCODE_NAMES.get(self.location.country_code)

View file

@ -15,6 +15,7 @@ from homeassistant import exceptions
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import _LOGGER, API_TIMEOUT, DOMAIN, PLATFORMS from .const import _LOGGER, API_TIMEOUT, DOMAIN, PLATFORMS
from .update_coordinator import SharkIqUpdateCoordinator 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( ayla_api = get_ayla_api(
username=config_entry.data[CONF_USERNAME], username=config_entry.data[CONF_USERNAME],
password=config_entry.data[CONF_PASSWORD], password=config_entry.data[CONF_PASSWORD],
websession=hass.helpers.aiohttp_client.async_get_clientsession(), websession=async_get_clientsession(hass),
) )
try: try:

View file

@ -10,6 +10,7 @@ import voluptuous as vol
from homeassistant import config_entries, core, exceptions from homeassistant import config_entries, core, exceptions
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import _LOGGER, DOMAIN from .const import _LOGGER, DOMAIN
@ -23,7 +24,7 @@ async def validate_input(hass: core.HomeAssistant, data):
ayla_api = get_ayla_api( ayla_api = get_ayla_api(
username=data[CONF_USERNAME], username=data[CONF_USERNAME],
password=data[CONF_PASSWORD], password=data[CONF_PASSWORD],
websession=hass.helpers.aiohttp_client.async_get_clientsession(hass), websession=async_get_clientsession(hass),
) )
try: try:

View file

@ -14,6 +14,7 @@ from homeassistant.components.device_tracker import (
) )
from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
@ -34,7 +35,7 @@ async def async_get_scanner(
) -> DeviceScanner | None: ) -> DeviceScanner | None:
"""Return the UPC device scanner.""" """Return the UPC device scanner."""
conf = config[DOMAIN] 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]) connect_box = ConnectBox(session, conf[CONF_PASSWORD], host=conf[CONF_HOST])
# Check login data # Check login data

View file

@ -13,6 +13,7 @@ import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import ATTR_ATTRIBUTION, TIME_MINUTES from homeassistant.const import ATTR_ATTRIBUTION, TIME_MINUTES
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -79,7 +80,7 @@ async def async_setup_platform(
async def async_http_request(hass, uri): async def async_http_request(hass, uri):
"""Perform actual request.""" """Perform actual request."""
try: try:
session = hass.helpers.aiohttp_client.async_get_clientsession(hass) session = async_get_clientsession(hass)
async with async_timeout.timeout(REQUEST_TIMEOUT): async with async_timeout.timeout(REQUEST_TIMEOUT):
req = await session.get(uri) req = await session.get(uri)
if req.status != HTTPStatus.OK: if req.status != HTTPStatus.OK:

View file

@ -5,6 +5,7 @@ from unittest.mock import AsyncMock, Mock, patch
import pytest import pytest
from homeassistant.components.cloud import ALEXA_SCHEMA, alexa_config 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.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
@ -127,7 +128,7 @@ async def test_alexa_config_invalidate_token(hass, cloud_prefs, aioclient_mock):
Mock( Mock(
alexa_access_token_url="http://example/alexa_token", alexa_access_token_url="http://example/alexa_token",
auth=Mock(async_check_token=AsyncMock()), auth=Mock(async_check_token=AsyncMock()),
websession=hass.helpers.aiohttp_client.async_get_clientsession(), websession=async_get_clientsession(hass),
), ),
) )

View file

@ -6,6 +6,7 @@ import pytest
from homeassistant.components.hassio.handler import HassIO, HassioAPIError from homeassistant.components.hassio.handler import HassIO, HassioAPIError
from homeassistant.core import CoreState from homeassistant.core import CoreState
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from . import HASSIO_TOKEN from . import HASSIO_TOKEN
@ -70,7 +71,7 @@ def hassio_handler(hass, aioclient_mock):
"""Create mock hassio handler.""" """Create mock hassio handler."""
async def get_client_session(): 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()) websession = hass.loop.run_until_complete(get_client_session())

View file

@ -4,6 +4,7 @@ from unittest.mock import Mock, patch
import aiohttp import aiohttp
import pytest import pytest
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.util.location as location_util import homeassistant.util.location as location_util
from tests.common import load_fixture from tests.common import load_fixture
@ -27,7 +28,7 @@ DISTANCE_MILES = 3632.78
@pytest.fixture @pytest.fixture
async def session(hass): async def session(hass):
"""Return aioclient session.""" """Return aioclient session."""
return hass.helpers.aiohttp_client.async_get_clientsession() return async_get_clientsession(hass)
@pytest.fixture @pytest.fixture