From 11eb698c20c4c73f93962d2fe8ec2db6428fd49c Mon Sep 17 00:00:00 2001 From: thekiwismarthome Date: Mon, 16 Feb 2026 21:27:23 +1300 Subject: [PATCH] Product Items VACA Sync Bug Fix --- .../shopping_list_manager/__init__.py | 5 +++ .../websocket/handlers.py | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/custom_components/shopping_list_manager/__init__.py b/custom_components/shopping_list_manager/__init__.py index c76937f..6d14e14 100644 --- a/custom_components/shopping_list_manager/__init__.py +++ b/custom_components/shopping_list_manager/__init__.py @@ -126,6 +126,11 @@ async def _async_register_websocket_handlers( hass, handlers.websocket_check_item, ) + websocket_api.async_register_command( + hass, + handlers.websocket_increment_item, + ) + websocket_api.async_register_command( hass, handlers.websocket_delete_item, diff --git a/custom_components/shopping_list_manager/websocket/handlers.py b/custom_components/shopping_list_manager/websocket/handlers.py index 02cc2c3..8f8484c 100644 --- a/custom_components/shopping_list_manager/websocket/handlers.py +++ b/custom_components/shopping_list_manager/websocket/handlers.py @@ -44,6 +44,43 @@ _LOGGER = logging.getLogger(__name__) # LIST HANDLERS # ============================================================================= +@websocket_api.websocket_command({ + vol.Required("type"): "shopping_list_manager/items/increment", + vol.Required("item_id"): str, + vol.Required("amount"): vol.Coerce(float), +}) +@websocket_api.async_response +async def websocket_increment_item( + hass: HomeAssistant, + connection: websocket_api.ActiveConnection, + msg: Dict[str, Any], +) -> None: + """Increment item quantity atomically.""" + + storage = get_storage(hass) + item_id = msg["item_id"] + amount = msg["amount"] + + # Get current item + item = storage.get_item(item_id) + + if not item: + connection.send_error(msg["id"], "not_found", "Item not found") + return + + # Atomic update + item.quantity += amount + + await storage.async_save() + + # Fire update event so all clients refresh + hass.bus.async_fire( + "shopping_list_manager_item_updated", + {"item_id": item.id} + ) + + connection.send_result(msg["id"], {"item": item.to_dict()}) + @websocket_api.websocket_command({ vol.Required("type"): "shopping_list_manager/products/get_by_ids", vol.Required("product_ids"): [str],