mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Deprecate hass.components and log warning if used inside custom component (#111508)
* Deprecate @bind_hass and log error if used inside custom component * Log also when accessing `hass.components` * Log warning only when `hass.components` is used * Change version * Process code review
This commit is contained in:
committed by
GitHub
parent
af4771a198
commit
bc6b4d01c8
@@ -1,6 +1,5 @@
|
||||
"""Test the frame helper."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import ANY, Mock, patch
|
||||
|
||||
import pytest
|
||||
@@ -9,33 +8,6 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import frame
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_integration_frame() -> Generator[Mock, None, None]:
|
||||
"""Mock as if we're calling code from inside an integration."""
|
||||
correct_frame = Mock(
|
||||
filename="/home/paulus/homeassistant/components/hue/light.py",
|
||||
lineno="23",
|
||||
line="self.light.is_on",
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.helpers.frame.extract_stack",
|
||||
return_value=[
|
||||
Mock(
|
||||
filename="/home/paulus/homeassistant/core.py",
|
||||
lineno="23",
|
||||
line="do_something()",
|
||||
),
|
||||
correct_frame,
|
||||
Mock(
|
||||
filename="/home/paulus/aiohue/lights.py",
|
||||
lineno="2",
|
||||
line="something()",
|
||||
),
|
||||
],
|
||||
):
|
||||
yield correct_frame
|
||||
|
||||
|
||||
async def test_extract_frame_integration(
|
||||
caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
|
||||
) -> None:
|
||||
@@ -174,3 +146,8 @@ async def test_report_missing_integration_frame(
|
||||
frame.report(what, error_if_core=False)
|
||||
assert what in caplog.text
|
||||
assert caplog.text.count(what) == 1
|
||||
|
||||
caplog.clear()
|
||||
|
||||
frame.report(what, error_if_core=False, log_custom_component_only=True)
|
||||
assert caplog.text == ""
|
||||
|
||||
Reference in New Issue
Block a user