mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-06-30 21:46:30 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9430811cda | |||
| 2b11632253 | |||
| ae7717a8eb | |||
| 433c03035b | |||
| 8eb403ed8e | |||
| 03fb9a9a67 |
@@ -1,33 +1,98 @@
|
||||
## 1. Installation (HACS)
|
||||
# Shopping List Manager Integration for Home Assistant
|
||||
|
||||
### Recommended
|
||||
The backend integration that powers the Shopping List Manager. Provides persistent multi-list storage, a 500+ product catalog, real-time WebSocket events, and a full API for the Lovelace card — all running natively inside Home Assistant.
|
||||
|
||||
> **Pair with the [Shopping List Manager Card](https://github.com/thekiwismarthome/shopping-list-manager-card)** for the full UI experience.
|
||||
|
||||
[](https://my.home-assistant.io/redirect/hacs_repository/?owner=thekiwismarthome&repository=shopping-list-manager&category=integration)
|
||||
|
||||
1. Click the button above.
|
||||
2. Confirm adding the repository to HACS.
|
||||
3. Install **Shopping List Manager** from **HACS → Integrations**.
|
||||
4. Restart Home Assistant.
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
### 🛒 Multi-List Management
|
||||
- Create and manage multiple shopping lists
|
||||
- Private or shared lists with per-member access control
|
||||
- Active list state shared across all connected devices and users
|
||||
- List total price calculation
|
||||
|
||||
### 📦 Items
|
||||
- Add, update, check, and delete items with quantity and unit
|
||||
- Atomic quantity increment / decrement
|
||||
- Bulk check and clear checked items
|
||||
- Per-item pricing, notes, and category assignment
|
||||
|
||||
### 🔍 Product Catalog
|
||||
- **500+ products** (NZ-focused, extensible to AU, US, GB, CA)
|
||||
- Fuzzy search with alias matching
|
||||
- Recently-used product suggestions
|
||||
- Custom product creation
|
||||
- Allergen filtering and product substitute groups
|
||||
- Product images (WebP, 200×200px, optimised)
|
||||
|
||||
### 🗂️ Categories
|
||||
- 13 default categories — Produce, Dairy, Meat, Bakery, Pantry, Frozen, Beverages, Snacks, Household, Health, Pet, Baby, Other
|
||||
- Category colour coding and emoji icons
|
||||
- Per-list category ordering
|
||||
|
||||
### 💳 Loyalty Cards
|
||||
- Store loyalty and rewards card data
|
||||
- Private or shared card access per user
|
||||
|
||||
### 🔄 Real-Time Events
|
||||
- All changes fire events on the Home Assistant bus
|
||||
- Custom WebSocket subscription proxy so **non-admin users** receive live updates without requiring HA admin privileges
|
||||
|
||||
---
|
||||
|
||||
### Manual Repository URL
|
||||
## Requirements
|
||||
|
||||
https://github.com/thekiwismarthome/shopping-list-manager
|
||||
|
||||
Repository type: **Integration**
|
||||
| Component | Minimum Version |
|
||||
|---|---|
|
||||
| Home Assistant | 2024.1 |
|
||||
| HACS | 2.x |
|
||||
|
||||
---
|
||||
|
||||
## 2. Manual Installation (Optional)
|
||||
## Installation
|
||||
|
||||
1. Copy the folder:
|
||||
custom_components/shopping_list_manager
|
||||
### Via HACS (Recommended)
|
||||
|
||||
2. Paste it into:
|
||||
/config/custom_components/
|
||||
[](https://my.home-assistant.io/redirect/hacs_repository/?owner=thekiwismarthome&repository=shopping-list-manager&category=integration)
|
||||
|
||||
3. Restart Home Assistant.
|
||||
1. Click the button above
|
||||
2. Confirm adding the repository to HACS
|
||||
3. Install **Shopping List Manager** from **HACS → Integrations**
|
||||
4. Restart Home Assistant
|
||||
5. Go to **Settings → Devices & Services → Add Integration** and search for **Shopping List Manager**
|
||||
|
||||
### Manual Installation
|
||||
|
||||
1. Copy the `custom_components/shopping_list_manager/` folder into your HA `/config/custom_components/` directory
|
||||
2. Restart Home Assistant
|
||||
3. Go to **Settings → Devices & Services → Add Integration** and search for **Shopping List Manager**
|
||||
|
||||
---
|
||||
|
||||
## Lovelace Card
|
||||
|
||||
Install the companion card to get the full shopping UI:
|
||||
|
||||
## 3. Shopping List Card to go with this Integration
|
||||
[](https://my.home-assistant.io/redirect/hacs_repository/?owner=thekiwismarthome&repository=shopping-list-manager-card&category=plugin)
|
||||
|
||||
---
|
||||
|
||||
## Documentation
|
||||
|
||||
Full documentation is available in the [Wiki](https://github.com/thekiwismarthome/shopping-list-manager/wiki).
|
||||
|
||||
## Support & Feedback
|
||||
|
||||
- [Open an Issue](https://github.com/thekiwismarthome/shopping-list-manager/issues)
|
||||
- [Home Assistant Community Forum](https://community.home-assistant.io)
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
MIT — see [LICENSE](LICENSE) for details.
|
||||
|
||||
@@ -171,6 +171,14 @@ async def _async_register_websocket_handlers(
|
||||
)
|
||||
|
||||
# Products handlers
|
||||
websocket_api.async_register_command(
|
||||
hass,
|
||||
handlers.websocket_download_product_image,
|
||||
)
|
||||
websocket_api.async_register_command(
|
||||
hass,
|
||||
handlers.websocket_search_by_barcode,
|
||||
)
|
||||
websocket_api.async_register_command(
|
||||
hass,
|
||||
handlers.websocket_search_products,
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
"""WebSocket API handlers for Shopping List Manager."""
|
||||
import io
|
||||
import logging
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
import voluptuous as vol
|
||||
from aiohttp import ClientTimeout
|
||||
from PIL import Image
|
||||
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from ..const import DOMAIN
|
||||
|
||||
from ..const import (
|
||||
IMAGE_SIZE,
|
||||
IMAGE_QUALITY,
|
||||
IMAGES_LOCAL_DIR,
|
||||
WS_TYPE_LISTS_GET_ALL,
|
||||
WS_TYPE_LISTS_CREATE,
|
||||
WS_TYPE_LISTS_UPDATE,
|
||||
@@ -782,6 +791,87 @@ def websocket_get_list_total(
|
||||
# PRODUCT HANDLERS
|
||||
# =============================================================================
|
||||
|
||||
@websocket_api.websocket_command(
|
||||
{
|
||||
vol.Required("type"): "shopping_list_manager/products/download_image",
|
||||
vol.Required("image_url"): str,
|
||||
vol.Required("product_name"): str,
|
||||
}
|
||||
)
|
||||
@websocket_api.async_response
|
||||
async def websocket_download_product_image(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: Dict[str, Any],
|
||||
) -> None:
|
||||
"""Download a remote image and save it as WebP to the local images directory."""
|
||||
raw_url: str = msg["image_url"]
|
||||
product_name: str = msg["product_name"]
|
||||
|
||||
safe_stem = re.sub(r"[^a-z0-9_]", "", product_name.lower().replace(" ", "_")) or "product"
|
||||
filename = f"{safe_stem}.webp"
|
||||
images_dir = Path(hass.config.path(IMAGES_LOCAL_DIR))
|
||||
images_dir.mkdir(parents=True, exist_ok=True)
|
||||
dest = images_dir / filename
|
||||
|
||||
try:
|
||||
session = async_get_clientsession(hass)
|
||||
headers = {"User-Agent": "Mozilla/5.0 (compatible; HomeAssistant/ShoppingListManager)"}
|
||||
async with session.get(raw_url, timeout=ClientTimeout(total=15), headers=headers) as resp:
|
||||
if resp.status != 200:
|
||||
connection.send_error(msg["id"], "download_failed", f"HTTP {resp.status}")
|
||||
return
|
||||
raw = await resp.read()
|
||||
except Exception as exc: # noqa: BLE001
|
||||
connection.send_error(msg["id"], "download_failed", str(exc))
|
||||
return
|
||||
|
||||
try:
|
||||
img = Image.open(io.BytesIO(raw))
|
||||
# Convert to RGB for reliable lossy WebP encoding
|
||||
# (RGBA, palette, grayscale modes can fail or produce oversized files)
|
||||
if img.mode == "RGBA":
|
||||
bg = Image.new("RGB", img.size, (255, 255, 255))
|
||||
bg.paste(img, mask=img.split()[3])
|
||||
img = bg
|
||||
elif img.mode != "RGB":
|
||||
img = img.convert("RGB")
|
||||
img.thumbnail((IMAGE_SIZE, IMAGE_SIZE), Image.LANCZOS)
|
||||
out = io.BytesIO()
|
||||
img.save(out, format="WEBP", quality=IMAGE_QUALITY)
|
||||
dest.write_bytes(out.getvalue())
|
||||
except Exception as exc: # noqa: BLE001
|
||||
connection.send_error(msg["id"], "conversion_failed", str(exc))
|
||||
return
|
||||
|
||||
connection.send_result(
|
||||
msg["id"],
|
||||
{"local_url": f"/local/shopping_list_manager/images/{filename}"},
|
||||
)
|
||||
|
||||
|
||||
@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",
|
||||
|
||||
Reference in New Issue
Block a user