diff --git a/src/patch/hui-card-element-editor.ts b/src/patch/hui-card-element-editor.ts index dc54b72..b9b55ad 100644 --- a/src/patch/hui-card-element-editor.ts +++ b/src/patch/hui-card-element-editor.ts @@ -13,30 +13,30 @@ customElements.whenDefined("hui-card-element-editor").then(() => { if (retval) { const _setConfig = retval.setConfig; try { - retval.setConfig = function (config: any, ...rest) { - // Strip card_mod from the data that's sent to the config element - // and put it back after the config has been checked - const newConfig = JSON.parse(JSON.stringify(config)); - this._cardModData = { - card: newConfig.card_mod, - entities: [], - }; - if (newConfig.entities) { - for (const [i, e] of newConfig.entities?.entries()) { - this._cardModData.entities[i] = e.card_mod; - delete e.card_mod; - } + retval.setConfig = function (config: any, ...rest) { + // Strip card_mod from the data that's sent to the config element + // and put it back after the config has been checked + const newConfig = JSON.parse(JSON.stringify(config)); + this._cardModData = { + card: newConfig.card_mod, + entities: [], + }; + if (Array.isArray(newConfig.entities)) { + for (const [i, e] of newConfig.entities?.entries()) { + this._cardModData.entities[i] = e.card_mod; + delete e.card_mod; } - delete newConfig.card_mod; + } + delete newConfig.card_mod; - _setConfig.bind(this)(newConfig, ...rest); - if (newConfig.entities) { - for (const [i, e] of newConfig.entities?.entries()) { - if (this._cardModData.entities[i]) - e.card_mod = this._cardModData.entities[i]; - } + _setConfig.bind(this)(newConfig, ...rest); + if (Array.isArray(newConfig.entities)) { + for (const [i, e] of newConfig.entities?.entries()) { + if (this._cardModData.entities[i]) + e.card_mod = this._cardModData.entities[i]; } - }; + } + }; } catch (error) { console.warn(error); } @@ -79,7 +79,8 @@ customElements.whenDefined("hui-dialog-edit-card").then(() => { button.appendChild(this._cardModIcon); if ( this._cardConfig?.card_mod || - this._cardConfig?.entities?.some((e: any) => e.card_mod) + (Array.isArray(this._cardConfig.entities) ?? + this._cardConfig?.entities?.some((e: any) => e.card_mod)) ) { this._cardModIcon.style.visibility = "visible"; } else {