Skip to content

Commit 96379da

Browse files
authored
Handle deprecation in lovelace data (#4402)
* Handle breaking change in lovelace * one more * more * fix * context * one more * Reverse to not trigger deprecation warning * one more
1 parent 4a820e8 commit 96379da

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

custom_components/hacs/repositories/plugin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def generate_dashboard_resource_url(self) -> str:
172172

173173
def _get_resource_handler(self) -> ResourceStorageCollection | None:
174174
"""Get the resource handler."""
175+
resources: ResourceStorageCollection | None
175176
if not (hass_data := self.hacs.hass.data):
176177
self.logger.error("%s Can not access the hass data", self.string)
177178
return
@@ -180,7 +181,12 @@ def _get_resource_handler(self) -> ResourceStorageCollection | None:
180181
self.logger.warning("%s Can not access the lovelace integration data", self.string)
181182
return
182183

183-
resources: ResourceStorageCollection | None = lovelace_data.get("resources")
184+
if self.hacs.core.ha_version > "2025.1.99":
185+
# Changed to 2025.2.0
186+
# Changed in https://github.com/home-assistant/core/pull/136313
187+
resources = lovelace_data.resources
188+
else:
189+
resources = lovelace_data.get("resources")
184190

185191
if resources is None:
186192
self.logger.warning("%s Can not access the dashboard resources", self.string)

tests/conftest.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,15 @@ async def assert_hacs_data(
274274
for entry in value:
275275
data[key][entry["id"]] = entry
276276

277-
dashboard_resources: ResourceStorageCollection = hacs.hass.data[LOVELACE_DOMAIN][
278-
"resources"
279-
]
277+
dashboard_resources: ResourceStorageCollection
278+
try:
279+
# Changed to 2025.2.0
280+
# Changed in https://github.com/home-assistant/core/pull/136313
281+
dashboard_resources = hacs.hass.data[LOVELACE_DOMAIN].resources
282+
except AttributeError:
283+
dashboard_resources = hacs.hass.data[LOVELACE_DOMAIN][
284+
"resources"
285+
]
280286

281287
def _entity_state(entity: er.RegistryEntry) -> dict[str, Any]:
282288
state = hacs.hass.states.get(entity.entity_id)

tests/repositories/test_plugin_repository.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ async def test_get_resource_handler_wrong_version(
9494
caplog: pytest.LogCaptureFixture,
9595
) -> None:
9696
"""Test the resource handler with wrong storage version."""
97-
hass.data["lovelace"]["resources"].store.version = 2
97+
try:
98+
hass.data["lovelace"].resources.store.version = 2
99+
except AttributeError:
100+
# Changed to 2025.2.0
101+
# Changed in https://github.com/home-assistant/core/pull/136313
102+
hass.data["lovelace"]["resources"].store.version = 2
98103
resources = downloaded_plugin_repository._get_resource_handler()
99104
assert resources is None
100105
assert "Can not use the dashboard resources" in caplog.text
@@ -106,7 +111,13 @@ async def test_get_resource_handler_wrong_key(
106111
caplog: pytest.LogCaptureFixture,
107112
) -> None:
108113
"""Test the resource handler with wrong storage key."""
109-
hass.data["lovelace"]["resources"].store.key = "wrong_key"
114+
try:
115+
hass.data["lovelace"].resources.store.key = "wrong_key"
116+
except AttributeError:
117+
# Changed to 2025.2.0
118+
# Changed in https://github.com/home-assistant/core/pull/136313
119+
hass.data["lovelace"]["resources"].store.key = "wrong_key"
120+
110121
resources = downloaded_plugin_repository._get_resource_handler()
111122
assert resources is None
112123
assert "Can not use the dashboard resources" in caplog.text
@@ -118,7 +129,13 @@ async def test_get_resource_handler_none_store(
118129
caplog: pytest.LogCaptureFixture,
119130
) -> None:
120131
"""Test the resource handler with store being none."""
121-
hass.data["lovelace"]["resources"].store = None
132+
try:
133+
134+
hass.data["lovelace"].resources.store = None
135+
except AttributeError:
136+
# Changed to 2025.2.0
137+
# Changed in https://github.com/home-assistant/core/pull/136313
138+
hass.data["lovelace"]["resources"].store = None
122139
resources = downloaded_plugin_repository._get_resource_handler()
123140
assert resources is None
124141
assert "YAML mode detected, can not update resources" in caplog.text
@@ -130,7 +147,13 @@ async def test_get_resource_handler_no_store(
130147
caplog: pytest.LogCaptureFixture,
131148
) -> None:
132149
"""Test the resource handler with no store."""
133-
del hass.data["lovelace"]["resources"].store
150+
try:
151+
hass.data["lovelace"].resources.store = None
152+
except AttributeError:
153+
# Changed to 2025.2.0
154+
# Changed in https://github.com/home-assistant/core/pull/136313
155+
del hass.data["lovelace"]["resources"].store
156+
134157
resources = downloaded_plugin_repository._get_resource_handler()
135158
assert resources is None
136159
assert "YAML mode detected, can not update resources" in caplog.text
@@ -142,7 +165,12 @@ async def test_get_resource_handler_no_lovelace_resources(
142165
caplog: pytest.LogCaptureFixture,
143166
) -> None:
144167
"""Test the resource handler with no lovelace resources."""
145-
del hass.data["lovelace"]["resources"]
168+
try:
169+
hass.data["lovelace"].resources = None
170+
except AttributeError:
171+
# Changed to 2025.2.0
172+
# Changed in https://github.com/home-assistant/core/pull/136313
173+
del hass.data["lovelace"]["resources"]
146174
resources = downloaded_plugin_repository._get_resource_handler()
147175
assert resources is None
148176
assert "Can not access the dashboard resources" in caplog.text

0 commit comments

Comments
 (0)