Correct Increment Handler

This commit is contained in:
thekiwismarthome
2026-02-16 22:17:16 +13:00
parent bcfde6df9a
commit e76fad5a92
@@ -61,22 +61,23 @@ async def websocket_increment_item(
item_id = msg["item_id"]
amount = msg["amount"]
# Loop through all lists to find the item
for list_id in storage.lists:
items = storage.get_items(list_id)
# First get current item
for list_id, items in storage._items.items():
for item in items:
if item.id == item_id:
item.quantity += amount
new_quantity = item.quantity + amount
# Prevent negative quantities
if item.quantity < 1:
item.quantity = 1
if new_quantity < 1:
new_quantity = 1
await storage.async_save()
updated_item = await storage.update_item(
item_id,
quantity=new_quantity
)
if updated_item:
connection.send_result(msg["id"], {
"item": item.to_dict()
"item": updated_item.to_dict()
})
return