mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-06-30 21:46:30 +00:00
Compare commits
2 Commits
d5c43fe3b5
..
v2.5.7
| Author | SHA1 | Date | |
|---|---|---|---|
| d50bd39210 | |||
| 8652996b65 |
@@ -27,27 +27,33 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
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")
|
||||||
|
|
||||||
# Get component path for loading data files
|
# Get component path for loading data files
|
||||||
component_path = os.path.dirname(__file__)
|
component_path = os.path.dirname(__file__)
|
||||||
config_path = hass.config.path()
|
config_path = hass.config.path()
|
||||||
|
|
||||||
# Get country from options (or fall back to data, or default to NZ)
|
# Get country from options (or fall back to data, or default to NZ)
|
||||||
country = entry.options.get("country") or entry.data.get("country", "NZ")
|
country = entry.options.get("country") or entry.data.get("country", "NZ")
|
||||||
_LOGGER.info("Using country: %s", country)
|
_LOGGER.info("Using country: %s", country)
|
||||||
|
|
||||||
# Initialize storage with country
|
# Initialize storage with country
|
||||||
storage = ShoppingListStorage(hass, component_path, country)
|
storage = ShoppingListStorage(hass, component_path, country)
|
||||||
await storage.async_load()
|
await storage.async_load()
|
||||||
|
|
||||||
# Initialize image handler
|
# Initialize image handler
|
||||||
image_handler = ImageHandler(hass, config_path)
|
image_handler = ImageHandler(hass, config_path)
|
||||||
|
|
||||||
|
# Read installed version from manifest
|
||||||
|
import json as _json
|
||||||
|
with open(os.path.join(component_path, "manifest.json")) as _f:
|
||||||
|
_manifest = _json.load(_f)
|
||||||
|
|
||||||
# Store instances in hass.data
|
# Store instances in hass.data
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][DATA_STORAGE] = storage
|
hass.data[DOMAIN][DATA_STORAGE] = storage
|
||||||
hass.data[DOMAIN]["image_handler"] = image_handler
|
hass.data[DOMAIN]["image_handler"] = image_handler
|
||||||
hass.data[DOMAIN]["country"] = country
|
hass.data[DOMAIN]["country"] = country
|
||||||
|
hass.data[DOMAIN]["version"] = _manifest.get("version", "unknown")
|
||||||
|
|
||||||
# Register update listener for options changes
|
# Register update listener for options changes
|
||||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
entry.async_on_unload(entry.add_update_listener(update_listener))
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"step": {
|
||||||
|
"user": {
|
||||||
|
"title": "Shopping List Manager",
|
||||||
|
"description": "Set up the Shopping List Manager integration. Country and other settings can be configured after setup via the Configure button."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"abort": {
|
||||||
|
"single_instance_allowed": "Only a single instance of Shopping List Manager is allowed."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"step": {
|
||||||
|
"init": {
|
||||||
|
"title": "Shopping List Manager Options",
|
||||||
|
"description": "Changing country will reload the product catalog on next restart.",
|
||||||
|
"data": {
|
||||||
|
"country": "Country",
|
||||||
|
"enable_price_tracking": "Enable price tracking",
|
||||||
|
"enable_image_search": "Enable image search",
|
||||||
|
"metric_units_only": "Metric units only"
|
||||||
|
},
|
||||||
|
"data_description": {
|
||||||
|
"country": "Used to localise product catalog and pricing.",
|
||||||
|
"enable_price_tracking": "Track and display product prices.",
|
||||||
|
"enable_image_search": "Search for product images automatically.",
|
||||||
|
"metric_units_only": "Show only metric units (g, kg, ml, L)."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1182,10 +1182,12 @@ def websocket_get_integration_settings(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Return current country and available country options."""
|
"""Return current country and available country options."""
|
||||||
country = hass.data[DOMAIN].get("country", "NZ")
|
country = hass.data[DOMAIN].get("country", "NZ")
|
||||||
|
version = hass.data[DOMAIN].get("version", "unknown")
|
||||||
connection.send_result(
|
connection.send_result(
|
||||||
msg["id"],
|
msg["id"],
|
||||||
{
|
{
|
||||||
"country": country,
|
"country": country,
|
||||||
|
"version": version,
|
||||||
"available_countries": {
|
"available_countries": {
|
||||||
"NZ": "New Zealand",
|
"NZ": "New Zealand",
|
||||||
"AU": "Australia",
|
"AU": "Australia",
|
||||||
|
|||||||
Reference in New Issue
Block a user