mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-05-01 11:46:30 +00:00
Sync Bug
This commit is contained in:
@@ -2,12 +2,14 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
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.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN, EVENT_ITEM_ADDED, EVENT_ITEM_UPDATED, EVENT_ITEM_CHECKED, EVENT_ITEM_DELETED, EVENT_LIST_UPDATED, EVENT_LIST_DELETED
|
||||||
from .storage import ShoppingListStorage
|
from .storage import ShoppingListStorage
|
||||||
|
from .websocket import register_websocket_handlers
|
||||||
from .utils.images import ImageHandler
|
from .utils.images import ImageHandler
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -23,7 +25,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# In async_setup_entry function, after storage initialization:
|
|
||||||
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."""
|
||||||
_LOGGER.info("Setting up Shopping List Manager")
|
_LOGGER.info("Setting up Shopping List Manager")
|
||||||
@@ -58,7 +59,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
# Register frontend resources
|
# Register frontend resources
|
||||||
await _async_register_frontend(hass)
|
await _async_register_frontend(hass)
|
||||||
|
|
||||||
_LOGGER.info("Shopping List Manager setup complete")
|
# CRITICAL: Register event listeners so non-admin users can subscribe
|
||||||
|
# Without these, non-admin users cannot receive real-time updates
|
||||||
|
def _dummy_listener(event):
|
||||||
|
"""Dummy listener to enable event subscription for all users."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
hass.bus.async_listen(EVENT_ITEM_ADDED, _dummy_listener)
|
||||||
|
hass.bus.async_listen(EVENT_ITEM_UPDATED, _dummy_listener)
|
||||||
|
hass.bus.async_listen(EVENT_ITEM_CHECKED, _dummy_listener)
|
||||||
|
hass.bus.async_listen(EVENT_ITEM_DELETED, _dummy_listener)
|
||||||
|
hass.bus.async_listen(EVENT_LIST_UPDATED, _dummy_listener)
|
||||||
|
hass.bus.async_listen(EVENT_LIST_DELETED, _dummy_listener)
|
||||||
|
|
||||||
|
_LOGGER.info("Shopping List Manager setup complete with event subscriptions enabled")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@@ -158,8 +173,8 @@ async def _async_register_websocket_handlers(
|
|||||||
handlers.websocket_search_products,
|
handlers.websocket_search_products,
|
||||||
)
|
)
|
||||||
websocket_api.async_register_command(
|
websocket_api.async_register_command(
|
||||||
hass,
|
hass,
|
||||||
handlers.ws_get_products_by_ids,
|
handlers.ws_get_products_by_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
websocket_api.async_register_command(
|
websocket_api.async_register_command(
|
||||||
@@ -194,8 +209,6 @@ async def _async_register_frontend(hass: HomeAssistant) -> None:
|
|||||||
# The frontend card registers itself independently
|
# The frontend card registers itself independently
|
||||||
_LOGGER.debug("Frontend resources skipped (separate HACS module)")
|
_LOGGER.debug("Frontend resources skipped (separate HACS module)")
|
||||||
|
|
||||||
_LOGGER.debug("Frontend resources registered")
|
|
||||||
|
|
||||||
|
|
||||||
def get_storage(hass: HomeAssistant) -> ShoppingListStorage:
|
def get_storage(hass: HomeAssistant) -> ShoppingListStorage:
|
||||||
"""Get the storage instance from hass.data.
|
"""Get the storage instance from hass.data.
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ EVENT_ITEM_UPDATED = f"{DOMAIN}_item_updated"
|
|||||||
EVENT_ITEM_CHECKED = f"{DOMAIN}_item_checked"
|
EVENT_ITEM_CHECKED = f"{DOMAIN}_item_checked"
|
||||||
EVENT_ITEM_DELETED = f"{DOMAIN}_item_deleted"
|
EVENT_ITEM_DELETED = f"{DOMAIN}_item_deleted"
|
||||||
EVENT_LIST_UPDATED = f"{DOMAIN}_list_updated"
|
EVENT_LIST_UPDATED = f"{DOMAIN}_list_updated"
|
||||||
EVENT_LIST_DELETED = f"{DOMAIN}_list_deleted"
|
|
||||||
|
|
||||||
# Image Configuration
|
# Image Configuration
|
||||||
IMAGE_FORMAT = "webp"
|
IMAGE_FORMAT = "webp"
|
||||||
|
|||||||
Reference in New Issue
Block a user