Update handlers.py

This commit is contained in:
thekiwismarthome
2026-02-16 20:09:54 +13:00
committed by GitHub
parent c9c1d16f08
commit 9d8fd3f63e
@@ -49,23 +49,29 @@ _LOGGER = logging.getLogger(__name__)
vol.Required("product_ids"): [str], vol.Required("product_ids"): [str],
}) })
@websocket_api.async_response @websocket_api.async_response
async def ws_get_products_by_ids(hass, connection, msg): async def ws_get_products_by_ids(
hass: HomeAssistant,
connection: websocket_api.ActiveConnection,
msg: Dict[str, Any],
) -> None:
"""Return products matching given product IDs.""" """Return products matching given product IDs."""
storage = get_storage(hass)
product_ids = set(msg["product_ids"]) product_ids = set(msg["product_ids"])
# Catalog is stored as a LIST # Get all products from storage
catalog = hass.data[DOMAIN].get("catalog", []) all_products = storage.get_all_products()
products = [ products = [
product product.to_dict()
for product in catalog for product in all_products
if str(product.get("id")) in product_ids if product.id in product_ids
] ]
connection.send_result(msg["id"], {"products": products}) connection.send_result(msg["id"], {"products": products})
@websocket_api.websocket_command( @websocket_api.websocket_command(
{ {
vol.Required("type"): WS_TYPE_LISTS_GET_ALL, vol.Required("type"): WS_TYPE_LISTS_GET_ALL,