diff --git a/src/mushroom-strategy.ts b/src/mushroom-strategy.ts index 929fd210..5b1ffb1b 100644 --- a/src/mushroom-strategy.ts +++ b/src/mushroom-strategy.ts @@ -293,13 +293,39 @@ class MushroomStrategy extends HTMLTemplateElement { logMessage(lvlError, 'Error while handling persistent notifications for Mushroom Strategy', e); } } -} -customElements.define('ll-strategy-mushroom-strategy', MushroomStrategy); + /** + * Returns suggestions for creating a new dashboard with this strategy. + * + * @returns An object containing the title and icon for the dashboard creation suggestion. + * + * @remarks + * This method is used by Home Assistant to display a suggestion when the user opts to create a new dashboard. + */ + static getCreateSuggestions() { + return { + title: 'Mushroom Dashboard', + icon: 'mdi:mushroom', + }; + } +} const STRATEGY_VERSION = 'v3.1.0'; + console.info( '%c Mushroom Strategy %c '.concat(STRATEGY_VERSION, ' '), 'color: white; background: coral; font-weight: 700;', 'color: coral; background: white; font-weight: 700;' ); + +customElements.define('ll-strategy-mushroom-strategy', MushroomStrategy); + +// Register the strategy as a custom HASS dashboard. +window.customStrategies = window.customStrategies || []; +window.customStrategies.push({ + type: 'mushroom-strategy', + strategyType: 'dashboard', + name: `Mushroom Dashboard Strategy ${STRATEGY_VERSION}`, + description: `A strategy to automatically generate a dashboard using mushroom cards.`, + documentationURL: `https://digilive.github.io/mushroom-strategy/${STRATEGY_VERSION}/`, +}); diff --git a/src/types/homeassistant/data/lovelace/lovelace_custom_strategies.ts b/src/types/homeassistant/data/lovelace/lovelace_custom_strategies.ts new file mode 100644 index 00000000..1672bc00 --- /dev/null +++ b/src/types/homeassistant/data/lovelace/lovelace_custom_strategies.ts @@ -0,0 +1,28 @@ +/** + * Represents an entry in the custom Lovelace strategy registry in Home Assistant. + * + * @property {string} type - The unique strategy type identifier. + * @property {string} [name] - The display name of the strategy. + * @property {string} [description] - The description of the strategy. + * @property {string} [documentationURL] - The URL to the strategy documentation. + * @property {'dashboard'} strategyType - The strategy type. + */ +export interface CustomStrategyEntry { + type: string; + name?: string; + description?: string; + documentationURL?: string; + strategyType: 'dashboard'; +} + +declare global { + //noinspection JSUnusedGlobalSymbols This extends global Window and is used in mushroom-strategy.ts + /** + * Represents the browser window object for custom Lovelace strategy registration. + * + * @property {CustomStrategyEntry[]} [customStrategies] - The registered custom Lovelace strategies. + */ + interface Window { + customStrategies?: CustomStrategyEntry[]; + } +}