mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-05-01 11:46:30 +00:00
Product Items VACA Sync Bug Fix
This commit is contained in:
@@ -126,6 +126,11 @@ async def _async_register_websocket_handlers(
|
|||||||
hass,
|
hass,
|
||||||
handlers.websocket_check_item,
|
handlers.websocket_check_item,
|
||||||
)
|
)
|
||||||
|
websocket_api.async_register_command(
|
||||||
|
hass,
|
||||||
|
handlers.websocket_increment_item,
|
||||||
|
)
|
||||||
|
|
||||||
websocket_api.async_register_command(
|
websocket_api.async_register_command(
|
||||||
hass,
|
hass,
|
||||||
handlers.websocket_delete_item,
|
handlers.websocket_delete_item,
|
||||||
|
|||||||
@@ -44,6 +44,43 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
# LIST HANDLERS
|
# 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({
|
@websocket_api.websocket_command({
|
||||||
vol.Required("type"): "shopping_list_manager/products/get_by_ids",
|
vol.Required("type"): "shopping_list_manager/products/get_by_ids",
|
||||||
vol.Required("product_ids"): [str],
|
vol.Required("product_ids"): [str],
|
||||||
|
|||||||
Reference in New Issue
Block a user