Fix aiohttp deprecation warnings (#13240)
* Fix aiohttp deprecation warnings * Fix Ring deprecation warning * Lint
This commit is contained in:
parent
a86bf81768
commit
89a19c89a7
45 changed files with 221 additions and 225 deletions
|
@ -149,34 +149,27 @@ def _async_get_connector(hass, verify_ssl=True):
|
|||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
is_new = False
|
||||
key = DATA_CONNECTOR if verify_ssl else DATA_CONNECTOR_NOTVERIFY
|
||||
|
||||
if key in hass.data:
|
||||
return hass.data[key]
|
||||
|
||||
if verify_ssl:
|
||||
if DATA_CONNECTOR not in hass.data:
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
||||
ssl_context.load_verify_locations(cafile=certifi.where(),
|
||||
capath=None)
|
||||
connector = aiohttp.TCPConnector(loop=hass.loop,
|
||||
ssl_context=ssl_context)
|
||||
hass.data[DATA_CONNECTOR] = connector
|
||||
is_new = True
|
||||
else:
|
||||
connector = hass.data[DATA_CONNECTOR]
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
||||
ssl_context.load_verify_locations(cafile=certifi.where(),
|
||||
capath=None)
|
||||
else:
|
||||
if DATA_CONNECTOR_NOTVERIFY not in hass.data:
|
||||
connector = aiohttp.TCPConnector(loop=hass.loop, verify_ssl=False)
|
||||
hass.data[DATA_CONNECTOR_NOTVERIFY] = connector
|
||||
is_new = True
|
||||
else:
|
||||
connector = hass.data[DATA_CONNECTOR_NOTVERIFY]
|
||||
ssl_context = False
|
||||
|
||||
if is_new:
|
||||
@callback
|
||||
def _async_close_connector(event):
|
||||
"""Close connector pool."""
|
||||
connector.close()
|
||||
connector = aiohttp.TCPConnector(loop=hass.loop, ssl=ssl_context)
|
||||
hass.data[key] = connector
|
||||
|
||||
hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_CLOSE, _async_close_connector)
|
||||
@callback
|
||||
def _async_close_connector(event):
|
||||
"""Close connector pool."""
|
||||
connector.close()
|
||||
|
||||
hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_CLOSE, _async_close_connector)
|
||||
|
||||
return connector
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue