Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions custom_components/hacs/utils/store.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Storage handers."""
"""Storage handlers."""

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
Expand All @@ -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


Expand Down Expand Up @@ -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):
Expand Down
21 changes: 21 additions & 0 deletions tests/utils/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,24 @@ 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


@pytest.mark.parametrize(
"ha_version, expected_supported",
[
("2025.11.0", False),
("2025.12.0", True),
],
)
def test_serialize_in_event_loop_version_check(ha_version: str, expected_supported: bool) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This is no longer checking _SERIALIZE_IN_EVENT_LOOP_SUPPORTED

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 532fda9. The test now patches and verifies _SERIALIZE_IN_EVENT_LOOP_SUPPORTED directly.

"""Test that serialize_in_event_loop flag is set based on HA version."""
from awesomeversion import AwesomeVersion

with patch(
"custom_components.hacs.utils.store._SERIALIZE_IN_EVENT_LOOP_SUPPORTED",
AwesomeVersion(ha_version) >= "2025.12.0",
):
# 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
Loading