Compare commits

...

2 Commits

Author SHA1 Message Date
thekiwismarthome 9a5a0bbcaf Bump version to 1.3.0 in manifest.json 2026-02-06 21:51:21 +13:00
thekiwismarthome 40d29aee3a Improve setConfig method for better validation
Enhance configuration handling with validation and normalization.
2026-02-06 21:50:23 +13:00
2 changed files with 62 additions and 16 deletions
@@ -112,16 +112,53 @@ class ShoppingListCard extends HTMLElement {
} }
setConfig(config) { setConfig(config) {
this._config = { ...config }; // shallow-copy: HA 2026+ freezes the original if (!config || typeof config !== 'object') {
// Derive a unique settings key for THIS card instance so each card on throw new Error('Invalid configuration');
// the dashboard keeps its own independent settings in localStorage. }
// Set `card_id` in YAML for an explicit stable label; otherwise title is used.
const id = (config.card_id || config.title || 'shopping_list').toString().trim().toLowerCase().replace(/[^a-z0-9_]/g, '_'); // Normalize + freeze config shape here
this._settingsKey = `shopping_list_settings_${id}`; this._config = {
// Re-load settings now that we have the correct key title: config.title ?? 'Shopping List',
this._settings = this._loadSettings(); card_id: config.card_id,
products_per_row: config.products_per_row ?? 'auto',
layout: config.layout ?? 'grid',
haptics: config.haptics ?? 'medium',
hide_completed: !!config.hide_completed,
compact_headers: !!config.compact_headers
};
// Derive a stable per-card storage key
const idSource =
this._config.card_id ||
this._config.title ||
'shopping_list';
const id = idSource
.toString()
.trim()
.toLowerCase()
.replace(/[^a-z0-9_]/g, '_');
const newSettingsKey = `shopping_list_settings_${id}`;
// If the card_id / title changed, reload settings
if (this._settingsKey !== newSettingsKey) {
this._settingsKey = newSettingsKey;
this._settings = this._loadSettings();
}
// First-time init
if (!this._settings) {
this._settings = this._loadSettings();
}
// Trigger a re-render if already attached
if (this.isConnected) {
this._render?.();
}
} }
/** /**
* Load data using Home Assistant's connection.sendMessagePromise * Load data using Home Assistant's connection.sendMessagePromise
*/ */
@@ -1941,17 +1978,26 @@ class ShoppingListCard extends HTMLElement {
} }
// Temporarily disabled GUI editor - use YAML configuration // Temporarily disabled GUI editor - use YAML configuration
// static getConfigElement() { static getConfigElement() {
// return document.createElement('shopping-list-card-editor'); return document.createElement('shopping-list-card-editor');
// }
static getStubConfig() {
return { title: 'Shopping List' };
} }
static getStubConfig() {
return {
type: 'custom:shopping-list-card',
title: 'Shopping List',
products_per_row: 'auto',
layout: 'grid',
haptics: 'medium',
hide_completed: false,
compact_headers: false
};
}
getCardSize() { getCardSize() {
return 3; return 3;
} }
} }
// ── GUI Config Editor ───────────────────────────────────────── // ── GUI Config Editor ─────────────────────────────────────────
@@ -1,7 +1,7 @@
{ {
"domain": "shopping_list_manager", "domain": "shopping_list_manager",
"name": "Shopping List Manager", "name": "Shopping List Manager",
"version": "1.2.1", "version": "1.3.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": [],