mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-05-01 11:46:30 +00:00
Fix the Broken Increment Handler
This commit is contained in:
@@ -61,25 +61,27 @@ async def websocket_increment_item(
|
|||||||
item_id = msg["item_id"]
|
item_id = msg["item_id"]
|
||||||
amount = msg["amount"]
|
amount = msg["amount"]
|
||||||
|
|
||||||
# Get current item
|
# Loop through all lists to find the item
|
||||||
item = storage.get_items(item_id)
|
for list_id in storage.lists:
|
||||||
|
items = storage.get_items(list_id)
|
||||||
|
|
||||||
if not item:
|
for item in items:
|
||||||
connection.send_error(msg["id"], "not_found", "Item not found")
|
if item.id == item_id:
|
||||||
return
|
|
||||||
|
|
||||||
# Atomic update
|
|
||||||
item.quantity += amount
|
item.quantity += amount
|
||||||
|
|
||||||
|
# Prevent negative quantities
|
||||||
|
if item.quantity < 1:
|
||||||
|
item.quantity = 1
|
||||||
|
|
||||||
await storage.async_save()
|
await storage.async_save()
|
||||||
|
|
||||||
# Fire update event so all clients refresh
|
connection.send_result(msg["id"], {
|
||||||
hass.bus.async_fire(
|
"item": item.to_dict()
|
||||||
"shopping_list_manager_item_updated",
|
})
|
||||||
{"item_id": item.id}
|
return
|
||||||
)
|
|
||||||
|
connection.send_error(msg["id"], "not_found", "Item not found")
|
||||||
|
|
||||||
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",
|
||||||
|
|||||||
Reference in New Issue
Block a user