Add files via upload

This commit is contained in:
thekiwismarthome
2026-02-06 08:36:47 +13:00
committed by GitHub
parent 9358751eb5
commit ff3e85d384
3 changed files with 19 additions and 38 deletions
@@ -3,35 +3,24 @@ Shopping List Manager - Home Assistant Custom Integration
Clean-slate architecture with enforced invariants Clean-slate architecture with enforced invariants
""" """
import logging import logging
from pathlib import Path
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.components import websocket_api from homeassistant.components import websocket_api as ha_websocket
from .const import DOMAIN from .const import DOMAIN
from .manager import ShoppingListManager from .manager import ShoppingListManager
# Import websocket handler functions directly
from .websocket_api import (
websocket_add_product,
websocket_set_qty,
websocket_get_products,
websocket_get_active,
websocket_delete_product,
)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
"""Set up the Shopping List Manager component."""
# Register frontend path for the card (updated for HA 2023+)
frontend_path = Path(__file__).parent / "frontend"
hass.http.async_register_static_paths(
[
{
"url_path": f"/hacsfiles/{DOMAIN}",
"path": str(frontend_path),
"cache_headers": False,
}
]
)
_LOGGER.info(f"Registered frontend path: /hacsfiles/{DOMAIN}")
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Shopping List Manager from a config entry.""" """Set up Shopping List Manager from a config entry."""
# Initialize the manager # Initialize the manager
@@ -42,20 +31,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN]["manager"] = manager hass.data[DOMAIN]["manager"] = manager
# Register WebSocket commands # Register WebSocket commands using Home Assistant's websocket_api
from .websocket_api import ( ha_websocket.async_register_command(hass, websocket_add_product)
websocket_add_product, ha_websocket.async_register_command(hass, websocket_set_qty)
websocket_set_qty, ha_websocket.async_register_command(hass, websocket_get_products)
websocket_get_products, ha_websocket.async_register_command(hass, websocket_get_active)
websocket_get_active, ha_websocket.async_register_command(hass, websocket_delete_product)
websocket_delete_product,
)
websocket_api.async_register_command(hass, websocket_add_product)
websocket_api.async_register_command(hass, websocket_set_qty)
websocket_api.async_register_command(hass, websocket_get_products)
websocket_api.async_register_command(hass, websocket_get_active)
websocket_api.async_register_command(hass, websocket_delete_product)
_LOGGER.info("Shopping List Manager setup complete - registered 5 WebSocket commands") _LOGGER.info("Shopping List Manager setup complete - registered 5 WebSocket commands")
@@ -65,4 +46,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload Shopping List Manager.""" """Unload Shopping List Manager."""
hass.data[DOMAIN].pop("manager", None) hass.data[DOMAIN].pop("manager", None)
return True return True
@@ -2199,4 +2199,4 @@ window.customCards.push({
name: 'Shopping List', name: 'Shopping List',
description: 'A shopping list card with search, categories, and product images.', description: 'A shopping list card with search, categories, and product images.',
preview: false preview: false
}); });
@@ -1,7 +1,7 @@
{ {
"domain": "shopping_list_manager", "domain": "shopping_list_manager",
"name": "Shopping List Manager", "name": "Shopping List Manager",
"version": "1.1.0", "version": "1.0.0",
"documentation": "https://github.com/thekiwismarthome/shopping-list-manager", "documentation": "https://github.com/thekiwismarthome/shopping-list-manager",
"issue_tracker": "https://github.com/thekiwismarthome/shopping-list-manager/issues", "issue_tracker": "https://github.com/thekiwismarthome/shopping-list-manager/issues",
"requirements": [], "requirements": [],
@@ -9,4 +9,4 @@
"codeowners": ["@thekiwismarthome"], "codeowners": ["@thekiwismarthome"],
"config_flow": true, "config_flow": true,
"iot_class": "local_polling" "iot_class": "local_polling"
} }