Patch aiohttp client session close (#34769)

* Patch aiohttp client session close

* Add test

* Restore close regardless of auto_cleanup

* Close session instead of detaching and do not restore

* Delint test

* Add frame helper

* Use frame helper

* Test warning log when closing session

* Clean up

* Correct docstring

* Do not change shutdown

* Fix tests
This commit is contained in:
Martin Hjelmare 2020-05-13 09:58:33 +02:00 committed by GitHub
parent 2f6da20065
commit 2a120d9045
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 205 additions and 2 deletions

View file

@ -0,0 +1,36 @@
"""Provide frame helper for finding the current frame context."""
from traceback import FrameSummary, extract_stack
from typing import Tuple
from homeassistant.exceptions import HomeAssistantError
def get_integration_frame() -> Tuple[FrameSummary, str, str]:
"""Return the frame, integration and integration path of the current stack frame."""
found_frame = None
for frame in reversed(extract_stack()):
for path in ("custom_components/", "homeassistant/components/"):
try:
index = frame.filename.index(path)
found_frame = frame
break
except ValueError:
continue
if found_frame is not None:
break
if found_frame is None:
raise MissingIntegrationFrame
start = index + len(path)
end = found_frame.filename.index("/", start)
integration = found_frame.filename[start:end]
return found_frame, integration, path
class MissingIntegrationFrame(HomeAssistantError):
"""Raised when no integration is found in the frame."""