mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-06-30 21:46:30 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e043d45f2 | |||
| 17cb680f1f | |||
| 94450a4450 | |||
| ae11549469 | |||
| 5429b97605 |
@@ -1,135 +1,33 @@
|
||||
# Shopping List Manager
|
||||
|
||||
A custom Home Assistant integration that provides an enhanced shopping list experience, including a companion Lovelace card for managing items directly from your dashboard.
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
- 📋 Manage shopping list items from Home Assistant
|
||||
- 🔌 WebSocket-based backend (no polling entities)
|
||||
- 🖥️ Custom Lovelace card
|
||||
- ⚙️ UI-based configuration (Config Flow)
|
||||
- 🚀 Compatible with Home Assistant **2024.8+**
|
||||
|
||||
---
|
||||
|
||||
## 1. Installation (HACS)
|
||||
|
||||
[](
|
||||
https://my.home-assistant.io/redirect/hacs_repository/?owner=thekiwismarthome&repository=shopping-list-manager&category=integration
|
||||
)
|
||||
### Recommended
|
||||
|
||||
Click the button above **or** follow the manual steps below.
|
||||
[](https://my.home-assistant.io/redirect/hacs_repository/?owner=thekiwismarthome&repository=shopping-list-manager&category=integration)
|
||||
|
||||
1. Open **HACS**
|
||||
2. Go to **Integrations**
|
||||
3. Click **⋮ → Custom repositories**
|
||||
4. Add this repository:
|
||||
- **Repository:** `https://github.com/thekiwismarthome/shopping-list-manager`
|
||||
- **Category:** Integration
|
||||
5. Install **Shopping List Manager**
|
||||
6. **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.
|
||||
|
||||
---
|
||||
|
||||
## 2. Install the Lovelace Card Resource (Required)
|
||||
### Manual Repository URL
|
||||
|
||||
The Lovelace card JavaScript file is included with the integration, but **must be copied manually** to the `www` directory so Home Assistant can load it.
|
||||
https://github.com/thekiwismarthome/shopping-list-manager
|
||||
|
||||
### Step 1: Copy the card file
|
||||
|
||||
Run the following command (via SSH, Terminal add-on, or container shell):
|
||||
|
||||
```bash
|
||||
mkdir -p /config/www/community/shopping_list_card && \
|
||||
cp /config/custom_components/shopping_list_manager/frontend/shopping_list_card.js \
|
||||
/config/www/community/shopping_list_card/shopping_list_card.js
|
||||
```
|
||||
Repository type: **Integration**
|
||||
|
||||
---
|
||||
|
||||
### Step 2: Add the resource to Home Assistant
|
||||
## 2. Manual Installation (Optional)
|
||||
|
||||
1. Go to **Settings → Dashboards**
|
||||
2. Click **⋮ (top right) → Resources**
|
||||
3. Click **Add Resource**
|
||||
4. Enter:
|
||||
1. Copy the folder:
|
||||
custom_components/shopping_list_manager
|
||||
|
||||
```text
|
||||
URL: /local/community/shopping_list_card/shopping_list_card.js
|
||||
Type: JavaScript Module
|
||||
```
|
||||
2. Paste it into:
|
||||
/config/custom_components/
|
||||
|
||||
5. Click **Create**
|
||||
6. Refresh your browser (**Ctrl + F5**)
|
||||
3. Restart Home Assistant.
|
||||
|
||||
---
|
||||
|
||||
## 3. Add the Integration
|
||||
|
||||
[](
|
||||
https://my.home-assistant.io/redirect/config_flow_start/?domain=shopping_list_manager
|
||||
)
|
||||
|
||||
Click the button above **or** add it manually:
|
||||
|
||||
1. Go to **Settings → Devices & Services**
|
||||
2. Click **Add Integration**
|
||||
3. Search for **Shopping List Manager**
|
||||
4. Follow the setup steps
|
||||
|
||||
No YAML configuration is required.
|
||||
|
||||
---
|
||||
|
||||
## 4. Add the Card to a Dashboard
|
||||
|
||||
Add a **Manual** card to your dashboard and use the following YAML:
|
||||
|
||||
```yaml
|
||||
type: custom:shopping-list-card
|
||||
title: Shopping List
|
||||
list_id: groceries
|
||||
```
|
||||
|
||||
Use the **⚙️ cog button** in the card to configure additional settings.
|
||||
|
||||
---
|
||||
|
||||
## Updating
|
||||
|
||||
- HACS updates will update the **integration**
|
||||
- If the Lovelace card JavaScript changes in a future release, you must **repeat the copy command** above
|
||||
|
||||
This is expected behavior for single-repository integrations.
|
||||
|
||||
---
|
||||
|
||||
## Compatibility Notes
|
||||
|
||||
- Designed for **Home Assistant 2024.8+**
|
||||
- Uses WebSocket APIs
|
||||
- Fully compatible with the **Services → Actions** change introduced in Home Assistant 2024.8
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If the card does not load:
|
||||
|
||||
1. Ensure Home Assistant was restarted after installation
|
||||
2. Verify the file exists at:
|
||||
|
||||
```
|
||||
/config/www/community/shopping_list_card/shopping_list_card.js
|
||||
```
|
||||
|
||||
3. Confirm the resource URL is correct
|
||||
4. Perform a hard browser refresh (**Ctrl + F5**)
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
## 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)
|
||||
|
||||
@@ -16,6 +16,8 @@ from .websocket_api import (
|
||||
websocket_get_products,
|
||||
websocket_get_active,
|
||||
websocket_delete_product,
|
||||
ws_get_catalogues,
|
||||
ws_get_lists,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -37,8 +39,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
ha_websocket.async_register_command(hass, websocket_get_products)
|
||||
ha_websocket.async_register_command(hass, websocket_get_active)
|
||||
ha_websocket.async_register_command(hass, websocket_delete_product)
|
||||
ha_websocket.async_register_command(hass, ws_get_catalogues)
|
||||
ha_websocket.async_register_command(hass, ws_get_lists)
|
||||
|
||||
_LOGGER.info("Shopping List Manager setup complete - registered 5 WebSocket commands")
|
||||
_LOGGER.info("Shopping List Manager setup complete - registered 7 WebSocket commands")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ DOMAIN = "shopping_list_manager"
|
||||
STORAGE_VERSION = 1
|
||||
STORAGE_KEY_PRODUCTS = f"{DOMAIN}.products"
|
||||
STORAGE_KEY_ACTIVE = f"{DOMAIN}.active_list"
|
||||
LISTS_STORE_KEY = "shopping_list_manager.lists"
|
||||
|
||||
# Events
|
||||
EVENT_SHOPPING_LIST_UPDATED = f"{DOMAIN}_updated"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,8 @@ from typing import Dict, Optional, List
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import storage
|
||||
from homeassistant.helpers.storage import Store
|
||||
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
@@ -58,7 +60,21 @@ class ShoppingListManager:
|
||||
self._store_active["groceries"] = storage.Store(
|
||||
hass, STORAGE_VERSION, STORAGE_KEY_ACTIVE # "shopping_list_manager.active_list"
|
||||
)
|
||||
|
||||
# --- Catalogue + list metadata (NEW, additive) ---
|
||||
self._store_catalogues = Store(
|
||||
hass,
|
||||
STORAGE_VERSION,
|
||||
f"{DOMAIN}.catalogues",
|
||||
)
|
||||
self._catalogues: Dict[str, dict] = {}
|
||||
|
||||
self._store_lists = Store(
|
||||
hass,
|
||||
STORAGE_VERSION,
|
||||
f"{DOMAIN}.lists",
|
||||
)
|
||||
self._lists: Dict[str, dict] = {}
|
||||
|
||||
def _lock_for(self, list_id: str) -> asyncio.Lock:
|
||||
"""Get or create lock for a list."""
|
||||
if list_id not in self._locks:
|
||||
@@ -68,10 +84,20 @@ class ShoppingListManager:
|
||||
def _store_products_for(self, list_id: str) -> storage.Store:
|
||||
"""Get or create products Store for a list."""
|
||||
if list_id not in self._store_products:
|
||||
# Non-groceries lists use namespaced keys
|
||||
key = f"{DOMAIN}.{list_id}.products"
|
||||
self._store_products[list_id] = storage.Store(self.hass, STORAGE_VERSION, key)
|
||||
catalogue_id = self._lists.get(list_id, {}).get("catalogue", list_id)
|
||||
catalogue = self._catalogues.get(catalogue_id)
|
||||
|
||||
key = (
|
||||
catalogue["products_store"]
|
||||
if catalogue
|
||||
else f"{DOMAIN}.{list_id}.products"
|
||||
)
|
||||
|
||||
self._store_products[list_id] = storage.Store(
|
||||
self.hass, STORAGE_VERSION, key
|
||||
)
|
||||
return self._store_products[list_id]
|
||||
|
||||
|
||||
def _store_active_for(self, list_id: str) -> storage.Store:
|
||||
"""Get or create active Store for a list."""
|
||||
@@ -82,6 +108,17 @@ class ShoppingListManager:
|
||||
|
||||
async def _ensure_loaded(self, list_id: str) -> None:
|
||||
"""Lazily load a list from storage if not yet in memory."""
|
||||
await self._ensure_catalogues_loaded()
|
||||
await self._ensure_lists_loaded()
|
||||
|
||||
# Register list if it does not exist yet
|
||||
if list_id not in self._lists:
|
||||
self._lists[list_id] = {
|
||||
"catalogue": list_id
|
||||
}
|
||||
await self._store_lists.async_save(self._lists)
|
||||
|
||||
|
||||
if list_id in self._products:
|
||||
return # already loaded
|
||||
|
||||
@@ -103,6 +140,38 @@ class ShoppingListManager:
|
||||
list_id, len(self._products[list_id]), len(self._active_list[list_id])
|
||||
)
|
||||
|
||||
async def _ensure_catalogues_loaded(self) -> None:
|
||||
data = await self._store_catalogues.async_load()
|
||||
if isinstance(data, dict):
|
||||
self._catalogues = data
|
||||
return
|
||||
|
||||
# Bootstrap from existing behavior (no changes)
|
||||
self._catalogues = {
|
||||
"groceries": {
|
||||
"name": "Groceries",
|
||||
"icon": "🛒",
|
||||
"products_store": f"{DOMAIN}.products",
|
||||
}
|
||||
}
|
||||
|
||||
await self._store_catalogues.async_save(self._catalogues)
|
||||
|
||||
async def _ensure_lists_loaded(self) -> None:
|
||||
data = await self._store_lists.async_load()
|
||||
if isinstance(data, dict):
|
||||
self._lists = data
|
||||
return
|
||||
|
||||
# Default: list_id == catalogue_id (current behavior)
|
||||
self._lists = {
|
||||
"groceries": {
|
||||
"catalogue": "groceries",
|
||||
}
|
||||
}
|
||||
|
||||
await self._store_lists.async_save(self._lists)
|
||||
|
||||
async def async_load(self) -> None:
|
||||
"""Pre-load the default groceries list for backward compat."""
|
||||
async with self._lock_for("groceries"):
|
||||
@@ -265,6 +334,15 @@ class ShoppingListManager:
|
||||
_LOGGER.debug("List '%s': deleted product: %s", list_id, key)
|
||||
self._fire_update_event()
|
||||
|
||||
def get_catalogues(self) -> Dict[str, dict]:
|
||||
return self._catalogues
|
||||
|
||||
async def async_get_lists(self) -> Dict[str, dict]:
|
||||
await self._ensure_catalogues_loaded()
|
||||
await self._ensure_lists_loaded()
|
||||
return self._lists
|
||||
|
||||
|
||||
async def async_get_products(self, list_id: str) -> Dict[str, dict]:
|
||||
"""
|
||||
Get all products in a list's catalog.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"domain": "shopping_list_manager",
|
||||
"name": "Shopping List Manager",
|
||||
"version": "1.4.0",
|
||||
"version": "1.5.0",
|
||||
"documentation": "https://github.com/thekiwismarthome/shopping-list-manager",
|
||||
"issue_tracker": "https://github.com/thekiwismarthome/shopping-list-manager/issues",
|
||||
"requirements": [],
|
||||
|
||||
@@ -74,6 +74,48 @@ async def websocket_add_product(
|
||||
connection.send_error(msg["id"], "add_product_failed", str(err))
|
||||
|
||||
|
||||
@websocket_api.websocket_command({
|
||||
vol.Required("type"): "shopping_list_manager/get_catalogues",
|
||||
})
|
||||
@websocket_api.async_response
|
||||
async def ws_get_catalogues(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict,
|
||||
) -> None:
|
||||
"""Return catalogue metadata (read-only)."""
|
||||
manager = hass.data[DOMAIN]["manager"]
|
||||
|
||||
try:
|
||||
catalogues = manager.get_catalogues()
|
||||
connection.send_result(msg["id"], catalogues)
|
||||
except Exception as err:
|
||||
_LOGGER.error("Error getting catalogues: %s", err)
|
||||
connection.send_error(msg["id"], "get_catalogues_failed", str(err))
|
||||
|
||||
|
||||
@websocket_api.websocket_command({
|
||||
vol.Required("type"): "shopping_list_manager/get_lists",
|
||||
})
|
||||
@websocket_api.async_response
|
||||
async def ws_get_lists(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict,
|
||||
) -> None:
|
||||
"""Return list → catalogue mapping (read-only)."""
|
||||
manager = hass.data[DOMAIN]["manager"]
|
||||
|
||||
try:
|
||||
# Ensure lists are loaded
|
||||
await manager._ensure_lists_loaded()
|
||||
lists = manager._lists
|
||||
connection.send_result(msg["id"], lists)
|
||||
except Exception as err:
|
||||
_LOGGER.error("Error getting lists: %s", err)
|
||||
connection.send_error(msg["id"], "get_lists_failed", str(err))
|
||||
|
||||
|
||||
@websocket_api.websocket_command({
|
||||
vol.Required("type"): "shopping_list_manager/set_qty",
|
||||
vol.Optional("list_id", default="groceries"): str,
|
||||
|
||||
Reference in New Issue
Block a user