mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-05-01 11:46:30 +00:00
Update handlers.py
This commit is contained in:
@@ -49,23 +49,29 @@ _LOGGER = logging.getLogger(__name__)
|
||||
vol.Required("product_ids"): [str],
|
||||
})
|
||||
@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."""
|
||||
|
||||
storage = get_storage(hass)
|
||||
product_ids = set(msg["product_ids"])
|
||||
|
||||
# Catalog is stored as a LIST
|
||||
catalog = hass.data[DOMAIN].get("catalog", [])
|
||||
# Get all products from storage
|
||||
all_products = storage.get_all_products()
|
||||
|
||||
products = [
|
||||
product
|
||||
for product in catalog
|
||||
if str(product.get("id")) in product_ids
|
||||
product.to_dict()
|
||||
for product in all_products
|
||||
if product.id in product_ids
|
||||
]
|
||||
|
||||
connection.send_result(msg["id"], {"products": products})
|
||||
|
||||
|
||||
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
vol.Required("type"): WS_TYPE_LISTS_GET_ALL,
|
||||
|
||||
Reference in New Issue
Block a user