From 61a7678e24e0a683c61d3f63e5f36a9f9c8ce5c0 Mon Sep 17 00:00:00 2001 From: thekiwismarthome <134335563+thekiwismarthome@users.noreply.github.com> Date: Sat, 14 Feb 2026 07:04:22 +1300 Subject: [PATCH] Update category_loader.py --- .../shopping_list_manager/data/category_loader.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/custom_components/shopping_list_manager/data/category_loader.py b/custom_components/shopping_list_manager/data/category_loader.py index 65c7f8f..ac4f0f5 100644 --- a/custom_components/shopping_list_manager/data/category_loader.py +++ b/custom_components/shopping_list_manager/data/category_loader.py @@ -3,12 +3,13 @@ import json import logging import os from typing import List, Dict, Any +import aiofiles _LOGGER = logging.getLogger(__name__) -def load_categories(component_path: str, country_code: str = None) -> List[Dict[str, Any]]: - """Load categories from JSON file. +async def load_categories(component_path: str, country_code: str = None) -> List[Dict[str, Any]]: + """Load categories from JSON file asynchronously. Args: component_path: Path to the component directory @@ -18,6 +19,8 @@ def load_categories(component_path: str, country_code: str = None) -> List[Dict[ Returns: List of category dictionaries """ + import os + # Try country-specific file first if country_code provided if country_code: country_file = os.path.join( @@ -36,8 +39,9 @@ def load_categories(component_path: str, country_code: str = None) -> List[Dict[ categories_file = os.path.join(component_path, "data", "categories.json") try: - with open(categories_file, "r", encoding="utf-8") as f: - data = json.load(f) + async with aiofiles.open(categories_file, "r", encoding="utf-8") as f: + content = await f.read() + data = json.loads(content) _LOGGER.info( "Loaded categories version %s for region %s",