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:
parent
2f6da20065
commit
2a120d9045
4 changed files with 205 additions and 2 deletions
36
homeassistant/helpers/frame.py
Normal file
36
homeassistant/helpers/frame.py
Normal 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."""
|
Loading…
Add table
Add a link
Reference in a new issue