diff --git a/custom_components/shopping_list_manager/websocket/handlers.py b/custom_components/shopping_list_manager/websocket/handlers.py index 2ac0727..02cc2c3 100644 --- a/custom_components/shopping_list_manager/websocket/handlers.py +++ b/custom_components/shopping_list_manager/websocket/handlers.py @@ -49,23 +49,29 @@ _LOGGER = logging.getLogger(__name__) vol.Required("product_ids"): [str], }) @websocket_api.async_response -async def ws_get_products_by_ids(hass, connection, msg): +async def ws_get_products_by_ids( + hass: HomeAssistant, + connection: websocket_api.ActiveConnection, + msg: Dict[str, Any], +) -> None: """Return products matching given product IDs.""" + storage = get_storage(hass) product_ids = set(msg["product_ids"]) - # Catalog is stored as a LIST - catalog = hass.data[DOMAIN].get("catalog", []) + # Get all products from storage + all_products = storage.get_all_products() products = [ - product - for product in catalog - if str(product.get("id")) in product_ids + product.to_dict() + for product in all_products + if product.id in product_ids ] connection.send_result(msg["id"], {"products": products}) + @websocket_api.websocket_command( { vol.Required("type"): WS_TYPE_LISTS_GET_ALL,