mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 03:03:17 +01:00
Cleanup deprecated get access in Lovelace data (#161749)
This commit is contained in:
@@ -21,7 +21,6 @@ from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
issue_registry as ir,
|
||||
)
|
||||
from homeassistant.helpers.frame import report_usage
|
||||
from homeassistant.helpers.service import async_register_admin_service
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.translation import async_get_translations
|
||||
@@ -109,34 +108,6 @@ class LovelaceData:
|
||||
resources: resources.ResourceYAMLCollection | resources.ResourceStorageCollection
|
||||
yaml_dashboards: dict[str | None, ConfigType]
|
||||
|
||||
def __getitem__(self, name: str) -> Any:
|
||||
"""Enable method for compatibility reason.
|
||||
|
||||
Following migration from an untyped dict to a dataclass in
|
||||
https://github.com/home-assistant/core/pull/136313
|
||||
"""
|
||||
report_usage(
|
||||
f"accessed lovelace_data['{name}'] instead of lovelace_data.{name}",
|
||||
breaks_in_ha_version="2026.2",
|
||||
exclude_integrations={DOMAIN},
|
||||
)
|
||||
return getattr(self, name)
|
||||
|
||||
def get(self, name: str, default: Any = None) -> Any:
|
||||
"""Enable method for compatibility reason.
|
||||
|
||||
Following migration from an untyped dict to a dataclass in
|
||||
https://github.com/home-assistant/core/pull/136313
|
||||
"""
|
||||
report_usage(
|
||||
f"accessed lovelace_data.get('{name}') instead of lovelace_data.{name}",
|
||||
breaks_in_ha_version="2026.2",
|
||||
exclude_integrations={DOMAIN},
|
||||
)
|
||||
if hasattr(self, name):
|
||||
return getattr(self, name)
|
||||
return default
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Lovelace commands."""
|
||||
|
||||
@@ -7,7 +7,6 @@ from unittest.mock import MagicMock, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import frame
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.typing import WebSocketGenerator
|
||||
@@ -97,38 +96,3 @@ async def test_create_dashboards_when_not_onboarded(
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
assert response["result"] == {"strategy": {"type": "map"}}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("integration_frame_path", ["custom_components/my_integration"])
|
||||
@pytest.mark.usefixtures("mock_integration_frame")
|
||||
async def test_hass_data_compatibility(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test compatibility for external access.
|
||||
|
||||
See:
|
||||
https://github.com/hacs/integration/blob/4a820e8b1b066bc54a1c9c61102038af6c030603
|
||||
/custom_components/hacs/repositories/plugin.py#L173
|
||||
"""
|
||||
expected_prefix = (
|
||||
"Detected that custom integration 'my_integration' accessed lovelace_data"
|
||||
)
|
||||
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
|
||||
assert (lovelace_data := hass.data.get("lovelace")) is not None
|
||||
|
||||
# Direct access to resources is fine
|
||||
assert lovelace_data.resources is not None
|
||||
assert expected_prefix not in caplog.text
|
||||
|
||||
# Dict compatibility logs warning
|
||||
with patch.object(frame, "_REPORTED_INTEGRATIONS", set()):
|
||||
assert lovelace_data["resources"] is not None
|
||||
assert f"{expected_prefix}['resources']" in caplog.text
|
||||
|
||||
# Dict get compatibility logs warning
|
||||
with patch.object(frame, "_REPORTED_INTEGRATIONS", set()):
|
||||
assert lovelace_data.get("resources") is not None
|
||||
assert f"{expected_prefix}.get('resources')" in caplog.text
|
||||
|
||||
Reference in New Issue
Block a user