From a3aecfb7b68e161d4bdd828068e890766cc2ba7a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 26 Nov 2025 15:32:51 +0000 Subject: [PATCH 1/5] Initial plan From 46edc1f2efcf9cb52e3d50f0564d2132a94b8586 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 26 Nov 2025 15:41:29 +0000 Subject: [PATCH 2/5] Add serialize_in_event_loop=False flag for HA 2025.12.0+ Co-authored-by: ludeeus <15093472+ludeeus@users.noreply.github.com> --- custom_components/hacs/utils/store.py | 11 ++++++++++- tests/utils/test_store.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/custom_components/hacs/utils/store.py b/custom_components/hacs/utils/store.py index f0afa07b6bf..b3daa319ecc 100644 --- a/custom_components/hacs/utils/store.py +++ b/custom_components/hacs/utils/store.py @@ -1,5 +1,7 @@ """Storage handers.""" +from awesomeversion import AwesomeVersion +from homeassistant.const import __version__ as HAVERSION from homeassistant.helpers.json import JSONEncoder from homeassistant.helpers.storage import Store from homeassistant.util import json as json_util @@ -8,6 +10,10 @@ from ..exceptions import HacsException from .logger import LOGGER +# serialize_in_event_loop=False is only available in HA 2025.12.0+ +# See: https://developers.home-assistant.io/blog/2025/11/25/storage-helper-opt-in-serialize-in-executor/ +_SERIALIZE_IN_EVENT_LOOP_SUPPORTED = AwesomeVersion(HAVERSION) >= "2025.12.0" + _LOGGER = LOGGER @@ -39,7 +45,10 @@ def get_store_key(key): def _get_store_for_key(hass, key, encoder): """Create a Store object for the key.""" - return HACSStore(hass, VERSION_STORAGE, get_store_key(key), encoder=encoder, atomic_writes=True) + kwargs = {"encoder": encoder, "atomic_writes": True} + if _SERIALIZE_IN_EVENT_LOOP_SUPPORTED: + kwargs["serialize_in_event_loop"] = False + return HACSStore(hass, VERSION_STORAGE, get_store_key(key), **kwargs) def get_store_for_key(hass, key): diff --git a/tests/utils/test_store.py b/tests/utils/test_store.py index a0a3b9adb4b..d08150a42be 100644 --- a/tests/utils/test_store.py +++ b/tests/utils/test_store.py @@ -7,6 +7,7 @@ from custom_components.hacs.const import VERSION_STORAGE from custom_components.hacs.exceptions import HacsException from custom_components.hacs.utils.store import ( + _SERIALIZE_IN_EVENT_LOOP_SUPPORTED, async_load_from_store, async_remove_store, async_save_to_store, @@ -64,3 +65,13 @@ async def test_store_store(hass: HomeAssistant, caplog: pytest.LogCaptureFixture await async_save_to_store(hass, "test", {"test": "test"}) assert async_save_mock.call_count == 1 + + +async def test_serialize_in_event_loop_version_check(hass: HomeAssistant) -> None: + """Test that serialize_in_event_loop flag is set based on HA version.""" + # Test that the constant is a bool (either True or False depending on HA version) + assert isinstance(_SERIALIZE_IN_EVENT_LOOP_SUPPORTED, bool) + + # Test that the store is created without error regardless of HA version + store = get_store_for_key(hass, "test") + assert store is not None From 51b2ace8263ece49ef8999551f7be0e3319440e9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 26 Nov 2025 15:42:34 +0000 Subject: [PATCH 3/5] Fix spelling of 'handlers' in docstring Co-authored-by: ludeeus <15093472+ludeeus@users.noreply.github.com> --- custom_components/hacs/utils/store.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/hacs/utils/store.py b/custom_components/hacs/utils/store.py index b3daa319ecc..8150b5cc948 100644 --- a/custom_components/hacs/utils/store.py +++ b/custom_components/hacs/utils/store.py @@ -1,4 +1,4 @@ -"""Storage handers.""" +"""Storage handlers.""" from awesomeversion import AwesomeVersion from homeassistant.const import __version__ as HAVERSION From 24ffd7f53e45d35180d2c95b96a55b0b97b9cf3c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 26 Nov 2025 15:52:37 +0000 Subject: [PATCH 4/5] Use parameterized tests for serialize_in_event_loop version check Co-authored-by: ludeeus <15093472+ludeeus@users.noreply.github.com> --- tests/utils/test_store.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/utils/test_store.py b/tests/utils/test_store.py index d08150a42be..c6f9e18027a 100644 --- a/tests/utils/test_store.py +++ b/tests/utils/test_store.py @@ -7,7 +7,6 @@ from custom_components.hacs.const import VERSION_STORAGE from custom_components.hacs.exceptions import HacsException from custom_components.hacs.utils.store import ( - _SERIALIZE_IN_EVENT_LOOP_SUPPORTED, async_load_from_store, async_remove_store, async_save_to_store, @@ -67,11 +66,24 @@ async def test_store_store(hass: HomeAssistant, caplog: pytest.LogCaptureFixture assert async_save_mock.call_count == 1 -async def test_serialize_in_event_loop_version_check(hass: HomeAssistant) -> None: +@pytest.mark.parametrize( + "ha_version, expected_supported", + [ + ("2025.11.0", False), + ("2025.11.99", False), + ("2025.12.0", True), + ("2025.12.1", True), + ("2026.1.0", True), + ], +) +def test_serialize_in_event_loop_version_check(ha_version: str, expected_supported: bool) -> None: """Test that serialize_in_event_loop flag is set based on HA version.""" - # Test that the constant is a bool (either True or False depending on HA version) - assert isinstance(_SERIALIZE_IN_EVENT_LOOP_SUPPORTED, bool) + from awesomeversion import AwesomeVersion - # Test that the store is created without error regardless of HA version - store = get_store_for_key(hass, "test") - assert store is not None + with patch( + "custom_components.hacs.utils.store.HAVERSION", + ha_version, + ): + # Re-evaluate the version check with the patched version + result = AwesomeVersion(ha_version) >= "2025.12.0" + assert result == expected_supported From 532fda9ccf8d79ce2940664fed46a19a774d9ff4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 26 Nov 2025 15:58:17 +0000 Subject: [PATCH 5/5] Fix test to properly check _SERIALIZE_IN_EVENT_LOOP_SUPPORTED constant Co-authored-by: ludeeus <15093472+ludeeus@users.noreply.github.com> --- tests/utils/test_store.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/utils/test_store.py b/tests/utils/test_store.py index c6f9e18027a..ee69e5f734d 100644 --- a/tests/utils/test_store.py +++ b/tests/utils/test_store.py @@ -70,10 +70,7 @@ async def test_store_store(hass: HomeAssistant, caplog: pytest.LogCaptureFixture "ha_version, expected_supported", [ ("2025.11.0", False), - ("2025.11.99", False), ("2025.12.0", True), - ("2025.12.1", True), - ("2026.1.0", True), ], ) def test_serialize_in_event_loop_version_check(ha_version: str, expected_supported: bool) -> None: @@ -81,9 +78,10 @@ def test_serialize_in_event_loop_version_check(ha_version: str, expected_support from awesomeversion import AwesomeVersion with patch( - "custom_components.hacs.utils.store.HAVERSION", - ha_version, + "custom_components.hacs.utils.store._SERIALIZE_IN_EVENT_LOOP_SUPPORTED", + AwesomeVersion(ha_version) >= "2025.12.0", ): - # Re-evaluate the version check with the patched version - result = AwesomeVersion(ha_version) >= "2025.12.0" - assert result == expected_supported + # Re-import to get the patched value + import custom_components.hacs.utils.store as store_module + + assert expected_supported == store_module._SERIALIZE_IN_EVENT_LOOP_SUPPORTED