feat: Add websocket command to search for products by barcode.

This commit is contained in:
thekiwismarthome
2026-03-01 20:15:29 +13:00
parent 8eb403ed8e
commit 433c03035b
2 changed files with 26 additions and 0 deletions
@@ -171,6 +171,10 @@ async def _async_register_websocket_handlers(
)
# Products handlers
websocket_api.async_register_command(
hass,
handlers.websocket_search_by_barcode,
)
websocket_api.async_register_command(
hass,
handlers.websocket_search_products,
@@ -782,6 +782,28 @@ def websocket_get_list_total(
# PRODUCT HANDLERS
# =============================================================================
@websocket_api.websocket_command(
{
vol.Required("type"): "shopping_list_manager/products/search_by_barcode",
vol.Required("barcode"): str,
}
)
@callback
def websocket_search_by_barcode(
hass: HomeAssistant,
connection: websocket_api.ActiveConnection,
msg: Dict[str, Any],
) -> None:
"""Find a single product by exact barcode match."""
storage = get_storage(hass)
barcode = msg["barcode"].strip()
match = next(
(p for p in storage._products.values() if p.barcode and p.barcode == barcode),
None,
)
connection.send_result(msg["id"], {"product": match.to_dict() if match else None})
@websocket_api.websocket_command(
{
vol.Required("type"): "shopping_list_manager/products/substitutes",