diff --git a/src/components/ha-icon.ts b/src/components/ha-icon.ts index 4eb0a1d1a1..23f68b1fb6 100644 --- a/src/components/ha-icon.ts +++ b/src/components/ha-icon.ts @@ -10,7 +10,7 @@ import { CSSResult, } from "lit-element"; import "./ha-svg-icon"; -import { customIconsets, CustomIcons } from "../data/custom_iconsets"; +import { customIconsets, CustomIcon } from "../data/custom_iconsets"; import { Chunks, MDI_PREFIXES, @@ -64,11 +64,16 @@ export class HaIcon extends LitElement { return; } const [iconPrefix, iconName] = this.icon.split(":", 2); + + if (!iconPrefix || !iconName) { + return; + } + if (!MDI_PREFIXES.includes(iconPrefix)) { if (iconPrefix in customIconsets) { const customIconset = customIconsets[iconPrefix]; if (customIconset) { - this._setCustomPath(customIconset(iconName), iconName); + this._setCustomPath(customIconset(iconName)); } return; } @@ -97,13 +102,10 @@ export class HaIcon extends LitElement { debouncedWriteCache(); } - private async _setCustomPath( - promise: Promise, - iconName: string - ) { - const iconPack = await promise; - this._path = iconPack[iconName].path; - this._viewBox = iconPack[iconName].viewBox; + private async _setCustomPath(promise: Promise) { + const icon = await promise; + this._path = icon.path; + this._viewBox = icon.viewBox; } private async _setPath(promise: Promise, iconName: string) { diff --git a/src/data/custom_iconsets.ts b/src/data/custom_iconsets.ts index 73b2ed4e61..670c4041e2 100644 --- a/src/data/custom_iconsets.ts +++ b/src/data/custom_iconsets.ts @@ -1,9 +1,10 @@ -export interface CustomIcons { - [key: string]: { path: string; viewBox?: string }; +export interface CustomIcon { + path: string; + viewBox?: string; } export interface CustomIconsetsWindow { - customIconsets?: { [key: string]: (name: string) => Promise }; + customIconsets?: { [key: string]: (name: string) => Promise }; } const customIconsetsWindow = window as CustomIconsetsWindow;