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:
@@ -6,6 +6,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components import websocket_api
|
from homeassistant.components import websocket_api
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from ..const import DOMAIN
|
||||||
|
|
||||||
from ..const import (
|
from ..const import (
|
||||||
WS_TYPE_LISTS_GET_ALL,
|
WS_TYPE_LISTS_GET_ALL,
|
||||||
@@ -49,18 +50,22 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
})
|
})
|
||||||
@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, connection, msg):
|
||||||
product_ids = msg["product_ids"]
|
"""Return products matching given product IDs."""
|
||||||
|
|
||||||
catalog = hass.data[DOMAIN]["catalog"]
|
product_ids = set(msg["product_ids"])
|
||||||
|
|
||||||
|
# Catalog is stored as a LIST
|
||||||
|
catalog = hass.data[DOMAIN].get("catalog", [])
|
||||||
|
|
||||||
products = [
|
products = [
|
||||||
product
|
product
|
||||||
for product in catalog.values()
|
for product in catalog
|
||||||
if product["id"] in product_ids
|
if str(product.get("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