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],
|
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,
|
||||||
|
|||||||
Reference in New Issue
Block a user