diff --git a/src/cards/AbstractCard.ts b/src/cards/AbstractCard.ts index c5524ad..f2adcbd 100644 --- a/src/cards/AbstractCard.ts +++ b/src/cards/AbstractCard.ts @@ -1,59 +1,59 @@ -import {Helper} from "../Helper"; -import {EntityCardConfig} from "../types/lovelace-mushroom/cards/entity-card-config"; -import {cards} from "../types/strategy/cards"; -import {generic} from "../types/strategy/generic"; +import { Registry } from '../Registry'; +import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config'; +import { AbstractCardConfig } from '../types/strategy/strategy-cards'; +import { RegistryEntry } from '../types/strategy/strategy-generics'; +import { logMessage, lvlFatal } from '../utilities/debug'; /** * Abstract Card Class * - * To create a new card, extend the new class with this one. + * To create a card configuration, this class should be extended by a child class. + * Child classes should override the default configuration so the card correctly reflects the entity. * - * @class - * @abstract + * @remarks + * Before using this class, the Registry module must be initialized by calling {@link Registry.initialize}. */ abstract class AbstractCard { - /** - * Entity to create the card for. - * - * @type {generic.RegistryEntry} - */ - entity: generic.RegistryEntry; + /** The registry entry this card represents. */ + readonly entity: RegistryEntry; /** - * Configuration of the card. + * The card configuration for this entity. * - * @type {EntityCardConfig} + * Child classes should override this property to reflect their own card type and options. */ - config: EntityCardConfig = { - type: "custom:mushroom-entity-card", - icon: "mdi:help-circle", + configuration: EntityCardConfig = { + type: 'custom:mushroom-entity-card', + icon: 'mdi:help-circle', }; /** * Class constructor. * - * @param {generic.RegistryEntry} entity The hass entity to create a card for. - * @throws {Error} If the Helper module isn't initialized. + * @param {RegistryEntry} entity The registry entry to create a card configuration for. + * + * @remarks + * Before this class can be used, the Registry module must be initialized by calling {@link Registry.initialize}. */ - protected constructor(entity: generic.RegistryEntry) { - if (!Helper.isInitialized()) { - throw new Error("The Helper module must be initialized before using this one."); + protected constructor(entity: RegistryEntry) { + if (!Registry.initialized) { + logMessage(lvlFatal, 'Registry not initialized!'); } this.entity = entity; } /** - * Get a card. + * Get a card configuration. * - * @returns {cards.AbstractCardConfig} A card object. + * The configuration should be set by any of the child classes so the card correctly reflects an entity. */ - getCard(): cards.AbstractCardConfig { + getCard(): AbstractCardConfig { return { - ...this.config, - entity: "entity_id" in this.entity ? this.entity.entity_id : undefined, + ...this.configuration, + entity: 'entity_id' in this.entity ? this.entity.entity_id : undefined, }; } } -export {AbstractCard}; +export default AbstractCard; diff --git a/src/cards/AreaCard.ts b/src/cards/AreaCard.ts index 5054a99..8028958 100644 --- a/src/cards/AreaCard.ts +++ b/src/cards/AreaCard.ts @@ -1,68 +1,52 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {AreaRegistryEntry} from "../types/homeassistant/data/area_registry"; -import {TemplateCardConfig} from "../types/lovelace-mushroom/cards/template-card-config"; +import { AreaRegistryEntry } from '../types/homeassistant/data/area_registry'; +import { TemplateCardConfig } from '../types/lovelace-mushroom/cards/template-card-config'; +import AbstractCard from './AbstractCard'; -// noinspection JSUnusedGlobalSymbols Class is dynamically imported. /** * Area Card Class * - * Used to create a card for an entity of the area domain. - * - * @class - * @extends AbstractCard + * Used to create card configuration for an entry of the HASS area registry. */ class AreaCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {TemplateCardConfig} - * @private - */ - #defaultConfig: TemplateCardConfig = { - type: "custom:mushroom-template-card", - primary: undefined, - icon: "mdi:floor-plan", - icon_color: "blue", - tap_action: { - action: "navigate", - navigation_path: "", - }, - hold_action: { - action: "none", - }, - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): TemplateCardConfig { + return { + type: 'custom:mushroom-template-card', + primary: undefined, + icon: 'mdi:floor-plan', + icon_color: 'blue', + tap_action: { action: 'navigate', navigation_path: '' }, + hold_action: { action: 'none' }, + }; + } /** * Class constructor. * - * @param {AreaRegistryEntry} area The area entity to create a card for. - * @param {cards.TemplateCardOptions} [options={}] Options for the card. - * - * @throws {Error} If the Helper module isn't initialized. + * @param {AreaRegistryEntry} area The HASS area to create a card configuration for. + * @param {TemplateCardConfig} [customConfiguration] Custom card configuration. */ - constructor(area: AreaRegistryEntry, options: cards.TemplateCardOptions = {}) { + constructor(area: AreaRegistryEntry, customConfiguration?: TemplateCardConfig) { super(area); + const configuration = AreaCard.getDefaultConfig(); + + let customConfig = customConfiguration; + + configuration.primary = area.name; + configuration.icon = area.icon || configuration.icon; + + if (configuration.tap_action && 'navigation_path' in configuration.tap_action) { + configuration.tap_action.navigation_path = area.area_id; + } + // Don't override the default card type if default is set in the strategy options. - if (options.type === "default") { - delete options.type; + if (customConfig && customConfig.type === 'default') { + customConfig = { ...customConfig, type: configuration.type }; } - // Initialize the default configuration. - this.#defaultConfig.primary = area.name; - - if (this.#defaultConfig.tap_action && ("navigation_path" in this.#defaultConfig.tap_action)) { - this.#defaultConfig.tap_action.navigation_path = area.area_id; - } - - // Overwrite the default icon to the user-defined icon in hass. - if (area.icon) { - this.#defaultConfig.icon = area.icon; - } - - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...configuration, ...customConfig }; } } -export {AreaCard}; +export default AreaCard; diff --git a/src/cards/BinarySensorCard.ts b/src/cards/BinarySensorCard.ts index 7d7d8a6..065a3e8 100644 --- a/src/cards/BinarySensorCard.ts +++ b/src/cards/BinarySensorCard.ts @@ -1,42 +1,35 @@ -import {SensorCard} from "./SensorCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {EntityCardConfig} from "../types/lovelace-mushroom/cards/entity-card-config"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config'; +import SensorCard from './SensorCard'; + /** * Sensor Card Class * - * Used to create a card for controlling an entity of the binary_sensor domain. - * - * @class - * @extends SensorCard + * Used to create a card configuration to control an entity of the binary_sensor domain. */ class BinarySensorCard extends SensorCard { - /** - * Default configuration of the card. - * - * @type {EntityCardConfig} - * @private - */ - #defaultConfig: EntityCardConfig = { - type: "custom:mushroom-entity-card", - icon: "mdi:power-cycle", - icon_color: "green", - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): EntityCardConfig { + return { + type: 'custom:mushroom-entity-card', + icon: 'mdi:power-cycle', + icon_color: 'green', + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.EntityCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {EntityCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...BinarySensorCard.getDefaultConfig(), ...customConfiguration }; } } -export {BinarySensorCard}; +export default BinarySensorCard; diff --git a/src/cards/CameraCard.ts b/src/cards/CameraCard.ts index 812ec81..161ca45 100644 --- a/src/cards/CameraCard.ts +++ b/src/cards/CameraCard.ts @@ -1,44 +1,37 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {PictureEntityCardConfig} from "../types/homeassistant/panels/lovelace/cards/types"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { PictureEntityCardConfig } from '../types/homeassistant/panels/lovelace/cards/types'; +import AbstractCard from './AbstractCard'; + /** * Camera Card Class * - * Used to create a card for controlling an entity of the camera domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the camera domain. */ class CameraCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {PictureEntityCardConfig} - * @private - */ - #defaultConfig: PictureEntityCardConfig = { - entity: "", - type: "picture-entity", - show_name: false, - show_state: false, - camera_view: "live", - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): PictureEntityCardConfig { + return { + entity: '', + type: 'picture-entity', + show_name: false, + show_state: false, + camera_view: 'live', + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.PictureEntityCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {PictureEntityCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.PictureEntityCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: PictureEntityCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...CameraCard.getDefaultConfig(), ...customConfiguration }; } } -export {CameraCard}; +export default CameraCard; diff --git a/src/cards/ClimateCard.ts b/src/cards/ClimateCard.ts index 14fc24f..f00c6a9 100644 --- a/src/cards/ClimateCard.ts +++ b/src/cards/ClimateCard.ts @@ -1,48 +1,36 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {ClimateCardConfig} from "../types/lovelace-mushroom/cards/climate-card-config"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { ClimateCardConfig } from '../types/lovelace-mushroom/cards/climate-card-config'; +import AbstractCard from './AbstractCard'; + /** * Climate Card Class * - * Used to create a card for controlling an entity of the climate domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the climate domain. */ class ClimateCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {ClimateCardConfig} - * @private - */ - #defaultConfig: ClimateCardConfig = { - type: "custom:mushroom-climate-card", - icon: undefined, - hvac_modes: [ - "off", - "cool", - "heat", - "fan_only", - ], - show_temperature_control: true, - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): ClimateCardConfig { + return { + type: 'custom:mushroom-climate-card', + icon: undefined, + hvac_modes: ['off', 'cool', 'heat', 'fan_only'], + show_temperature_control: true, + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.ClimateCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {ClimateCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.ClimateCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: ClimateCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...ClimateCard.getDefaultConfig(), ...customConfiguration }; } } -export {ClimateCard}; +export default ClimateCard; diff --git a/src/cards/CoverCard.ts b/src/cards/CoverCard.ts index a1486cb..d6c2933 100644 --- a/src/cards/CoverCard.ts +++ b/src/cards/CoverCard.ts @@ -1,44 +1,37 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {CoverCardConfig} from "../types/lovelace-mushroom/cards/cover-card-config"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { CoverCardConfig } from '../types/lovelace-mushroom/cards/cover-card-config'; +import AbstractCard from './AbstractCard'; + /** * Cover Card Class * - * Used to create a card for controlling an entity of the cover domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the cover domain. */ class CoverCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {CoverCardConfig} - * @private - */ - #defaultConfig: CoverCardConfig = { - type: "custom:mushroom-cover-card", - icon: undefined, - show_buttons_control: true, - show_position_control: true, - show_tilt_position_control: true, - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): CoverCardConfig { + return { + type: 'custom:mushroom-cover-card', + icon: undefined, + show_buttons_control: true, + show_position_control: true, + show_tilt_position_control: true, + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.CoverCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {CoverCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.CoverCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: CoverCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...CoverCard.getDefaultConfig(), ...customConfiguration }; } } -export {CoverCard}; +export default CoverCard; diff --git a/src/cards/FanCard.ts b/src/cards/FanCard.ts index 4cf1103..7706ed7 100644 --- a/src/cards/FanCard.ts +++ b/src/cards/FanCard.ts @@ -1,44 +1,37 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {FanCardConfig} from "../types/lovelace-mushroom/cards/fan-card-config"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { FanCardConfig } from '../types/lovelace-mushroom/cards/fan-card-config'; +import AbstractCard from './AbstractCard'; + /** * Fan Card Class * - * Used to create a card for controlling an entity of the fan domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the fan domain. */ class FanCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {FanCardConfig} - * @private - */ - #defaultConfig: FanCardConfig = { - type: "custom:mushroom-fan-card", - icon: undefined, - show_percentage_control: true, - show_oscillate_control: true, - icon_animation: true, - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): FanCardConfig { + return { + type: 'custom:mushroom-fan-card', + icon: undefined, + show_percentage_control: true, + show_oscillate_control: true, + icon_animation: true, + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.FanCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {FanCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.FanCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: FanCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...FanCard.getDefaultConfig(), ...customConfiguration }; } } -export {FanCard}; +export default FanCard; diff --git a/src/cards/HaAreaCard.ts b/src/cards/HaAreaCard.ts index ce31b34..4bdca38 100644 --- a/src/cards/HaAreaCard.ts +++ b/src/cards/HaAreaCard.ts @@ -1,49 +1,45 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {AreaRegistryEntry} from "../types/homeassistant/data/area_registry"; -import {AreaCardConfig} from "../types/homeassistant/panels/lovelace/cards/types"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { AreaRegistryEntry } from '../types/homeassistant/data/area_registry'; +import { AreaCardConfig } from '../types/homeassistant/panels/lovelace/cards/types'; +import AbstractCard from './AbstractCard'; + /** * HA Area Card Class * - * Used to create a card for an entity of the area domain using the built-in type 'area'. - * - * @class - * @extends AbstractCard + * Used to create card configuration for an entry of the HASS area registry. */ class AreaCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {AreaCardConfig} - * @private - */ - #defaultConfig: AreaCardConfig = { - type: "area", - area: "", - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): AreaCardConfig { + return { + type: 'area', + area: '', + }; + } /** * Class constructor. * - * @param {AreaRegistryEntry} area The area entity to create a card for. - * @param {cards.AreaCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {AreaRegistryEntry} area The HASS entity to create a card configuration for. + * @param {AreaCardConfig} [customConfiguration] Custom card configuration. */ - - constructor(area: AreaRegistryEntry, options: cards.AreaCardOptions = {}) { + constructor(area: AreaRegistryEntry, customConfiguration?: AreaCardConfig) { super(area); // Initialize the default configuration. - this.#defaultConfig.area = area.area_id; - this.#defaultConfig.navigation_path = this.#defaultConfig.area; + const configuration = AreaCard.getDefaultConfig(); - // Enforce the card type. - delete options.type; + configuration.area = area.area_id; + configuration.navigation_path = configuration.area; - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { + ...this.configuration, + ...configuration, + ...customConfiguration, + type: configuration.type, // Enforce the card type. + }; } } -export {AreaCard}; +export default AreaCard; diff --git a/src/cards/InputSelectCard.ts b/src/cards/InputSelectCard.ts index 1aee6a9..86253b0 100644 --- a/src/cards/InputSelectCard.ts +++ b/src/cards/InputSelectCard.ts @@ -1,41 +1,34 @@ -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {SelectCardConfig} from "../types/lovelace-mushroom/cards/select-card-config"; -import {SelectCard} from './SelectCard'; +// noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { SelectCardConfig } from '../types/lovelace-mushroom/cards/select-card-config'; +import SelectCard from './SelectCard'; -// noinspection JSUnusedGlobalSymbols Class is dynamically imported /** * InputSelect Card Class * - * Used to create a card for controlling an entity of the input_select domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the input_select domain. */ class InputSelectCard extends SelectCard { - /** - * Default configuration of the card. - * - * @type {SelectCardConfig} - * @private - */ - #defaultConfig: SelectCardConfig = { - type: "custom:mushroom-select-card", - icon: undefined, - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): SelectCardConfig { + return { + type: 'custom:mushroom-select-card', + icon: undefined, + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.InputSelectCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {SelectCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.InputSelectCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: SelectCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...InputSelectCard.getDefaultConfig(), ...customConfiguration }; } } -export {InputSelectCard}; +export default InputSelectCard; diff --git a/src/cards/LightCard.ts b/src/cards/LightCard.ts index 2045eaf..1da21f8 100644 --- a/src/cards/LightCard.ts +++ b/src/cards/LightCard.ts @@ -1,67 +1,58 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {LightCardConfig} from "../types/lovelace-mushroom/cards/light-card-config"; -import {generic} from "../types/strategy/generic"; -import isCallServiceActionConfig = generic.isCallServiceActionConfig; -import isCallServiceActionTarget = generic.isCallServiceActionTarget; - - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { LightCardConfig } from '../types/lovelace-mushroom/cards/light-card-config'; +import { isCallServiceActionConfig, isCallServiceActionTarget } from '../types/strategy/strategy-generics'; +import AbstractCard from './AbstractCard'; + /** * Light Card Class * - * Used to create a card for controlling an entity of the light domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the light domain. */ class LightCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {LightCardConfig} - * @private - */ - #defaultConfig: LightCardConfig = { - type: "custom:mushroom-light-card", - icon: undefined, - show_brightness_control: true, - show_color_control: true, - show_color_temp_control: true, - use_light_color: true, - double_tap_action: { - action: "call-service", - service: "light.turn_on", - target: { - entity_id: undefined, + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): LightCardConfig { + return { + type: 'custom:mushroom-light-card', + icon: undefined, + show_brightness_control: true, + show_color_control: true, + show_color_temp_control: true, + use_light_color: true, + double_tap_action: { + action: 'call-service', + perform_action: 'light.turn_on', + target: { + entity_id: undefined, + }, + data: { + rgb_color: [255, 255, 255], + }, }, - data: { - rgb_color: [255, 255, 255], - }, - }, - }; + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.LightCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {LightCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.LightCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: LightCardConfig) { super(entity); - // Set the target for double-tap action. + const configuration = LightCard.getDefaultConfig(); + if ( - isCallServiceActionConfig(this.#defaultConfig.double_tap_action) - && isCallServiceActionTarget(this.#defaultConfig.double_tap_action.target) + isCallServiceActionConfig(configuration.double_tap_action) && + isCallServiceActionTarget(configuration.double_tap_action.target) ) { - this.#defaultConfig.double_tap_action.target.entity_id = entity.entity_id; + configuration.double_tap_action.target.entity_id = entity.entity_id; } - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...configuration, ...customConfiguration }; } } -export {LightCard}; +export default LightCard; diff --git a/src/cards/LockCard.ts b/src/cards/LockCard.ts index 4e1fdf8..d0892d9 100644 --- a/src/cards/LockCard.ts +++ b/src/cards/LockCard.ts @@ -1,41 +1,34 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {LockCardConfig} from "../types/lovelace-mushroom/cards/lock-card-config"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { LockCardConfig } from '../types/lovelace-mushroom/cards/lock-card-config'; +import AbstractCard from './AbstractCard'; + /** * Lock Card Class * - * Used to create a card for controlling an entity of the lock domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the lock domain. */ class LockCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {LockCardConfig} - * @private - */ - #defaultConfig: LockCardConfig = { - type: "custom:mushroom-lock-card", - icon: undefined, - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): LockCardConfig { + return { + type: 'custom:mushroom-lock-card', + icon: undefined, + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.LockCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {LockCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.LockCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: LockCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...LockCard.getDefaultConfig(), ...customConfiguration }; } } -export {LockCard}; +export default LockCard; diff --git a/src/cards/MediaPlayerCard.ts b/src/cards/MediaPlayerCard.ts index 964dae5..4464567 100644 --- a/src/cards/MediaPlayerCard.ts +++ b/src/cards/MediaPlayerCard.ts @@ -1,51 +1,37 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {MediaPlayerCardConfig} from "../types/lovelace-mushroom/cards/media-player-card-config"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { MediaPlayerCardConfig } from '../types/lovelace-mushroom/cards/media-player-card-config'; +import AbstractCard from './AbstractCard'; + /** * Mediaplayer Card Class * - * Used to create a card for controlling an entity of the media_player domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the media_player domain. */ class MediaPlayerCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {MediaPlayerCardConfig} - * @private - */ - #defaultConfig: MediaPlayerCardConfig = { - type: "custom:mushroom-media-player-card", - use_media_info: true, - media_controls: [ - "on_off", - "play_pause_stop", - ], - show_volume_level: true, - volume_controls: [ - "volume_mute", - "volume_set", - "volume_buttons", - ], - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): MediaPlayerCardConfig { + return { + type: 'custom:mushroom-media-player-card', + use_media_info: true, + media_controls: ['on_off', 'play_pause_stop'], + show_volume_level: true, + volume_controls: ['volume_mute', 'volume_set', 'volume_buttons'], + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.MediaPlayerCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {MediaPlayerCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.MediaPlayerCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: MediaPlayerCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...MediaPlayerCard.getDefaultConfig(), ...customConfiguration }; } } -export {MediaPlayerCard}; +export default MediaPlayerCard; diff --git a/src/cards/MiscellaneousCard.ts b/src/cards/MiscellaneousCard.ts index 3c75282..1b1fe3a 100644 --- a/src/cards/MiscellaneousCard.ts +++ b/src/cards/MiscellaneousCard.ts @@ -1,40 +1,32 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {EntityCardConfig} from "../types/lovelace-mushroom/cards/entity-card-config"; +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config'; +import AbstractCard from './AbstractCard'; /** * Miscellaneous Card Class * - * Used to create a card an entity of any domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of any domain. */ class MiscellaneousCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {EntityCardConfig} - * @private - */ - #defaultConfig: EntityCardConfig = { - type: "custom:mushroom-entity-card", - icon_color: "blue-grey", - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): EntityCardConfig { + return { + type: 'custom:mushroom-entity-card', + icon_color: 'blue-grey', + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.EntityCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {EntityCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...MiscellaneousCard.getDefaultConfig(), ...customConfiguration }; } } -export {MiscellaneousCard}; +export default MiscellaneousCard; diff --git a/src/cards/NumberCard.ts b/src/cards/NumberCard.ts index c5808b7..a5eef46 100644 --- a/src/cards/NumberCard.ts +++ b/src/cards/NumberCard.ts @@ -1,41 +1,34 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {NumberCardConfig} from "../types/lovelace-mushroom/cards/number-card-config"; +// noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { NumberCardConfig } from '../types/lovelace-mushroom/cards/number-card-config'; +import AbstractCard from './AbstractCard'; -// noinspection JSUnusedGlobalSymbols Class is dynamically imported /** * Number Card Class * - * Used to create a card for controlling an entity of the number domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the number domain. */ class NumberCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {NumberCardConfig} - * @private - */ - #defaultConfig: NumberCardConfig = { - type: "custom:mushroom-number-card", - icon: undefined, - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): NumberCardConfig { + return { + type: 'custom:mushroom-number-card', + icon: undefined, + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.NumberCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {NumberCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.NumberCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: NumberCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...NumberCard.getDefaultConfig(), ...customConfiguration }; } } -export {NumberCard}; +export default NumberCard; diff --git a/src/cards/PersonCard.ts b/src/cards/PersonCard.ts index 10d300f..9f65382 100644 --- a/src/cards/PersonCard.ts +++ b/src/cards/PersonCard.ts @@ -1,43 +1,35 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {PersonCardConfig} from "../types/lovelace-mushroom/cards/person-card-config"; +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { PersonCardConfig } from '../types/lovelace-mushroom/cards/person-card-config'; +import AbstractCard from './AbstractCard'; /** * Person Card Class * - * Used to create a card for an entity of the Person domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the person domain. */ class PersonCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {PersonCardConfig} - * @private - */ - #defaultConfig: PersonCardConfig = { - type: "custom:mushroom-person-card", - layout: "vertical", - primary_info: "none", - secondary_info: "none", - icon_type: "entity-picture", - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): PersonCardConfig { + return { + type: 'custom:mushroom-person-card', + layout: 'vertical', + primary_info: 'none', + secondary_info: 'none', + icon_type: 'entity-picture', + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.PersonCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {PersonCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.PersonCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: PersonCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...PersonCard.getDefaultConfig(), ...customConfiguration }; } } -export {PersonCard}; +export default PersonCard; diff --git a/src/cards/SceneCard.ts b/src/cards/SceneCard.ts index 09f40de..4a4706f 100644 --- a/src/cards/SceneCard.ts +++ b/src/cards/SceneCard.ts @@ -1,63 +1,54 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {generic} from "../types/strategy/generic"; -import {EntityCardConfig} from "../types/lovelace-mushroom/cards/entity-card-config"; -import {Helper} from "../Helper"; -import isCallServiceActionConfig = generic.isCallServiceActionConfig; -import isCallServiceActionTarget = generic.isCallServiceActionTarget; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { Registry } from '../Registry'; +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config'; +import { isCallServiceActionConfig, isCallServiceActionTarget } from '../types/strategy/strategy-generics'; +import AbstractCard from './AbstractCard'; + /** * Scene Card Class * - * Used to create a card for an entity of the scene domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the scene domain. */ class SceneCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {EntityCardConfig} - * @private - */ - #defaultConfig: EntityCardConfig = { - type: "custom:mushroom-entity-card", - icon: "mdi:palette", - icon_color: "blue", - tap_action: { - action: "call-service", - service: "scene.turn_on", - target: { - entity_id: undefined, + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): EntityCardConfig { + return { + type: 'custom:mushroom-entity-card', + icon: 'mdi:palette', + icon_color: 'blue', + tap_action: { + action: 'call-service', + perform_action: 'scene.turn_on', + target: { + entity_id: undefined, + }, }, - }, - }; + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.EntityCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {EntityCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) { super(entity); - // Set the target for tap action. + const configuration = SceneCard.getDefaultConfig(); + if ( - isCallServiceActionConfig(this.#defaultConfig.tap_action) - && isCallServiceActionTarget(this.#defaultConfig.tap_action.target) + isCallServiceActionConfig(configuration.tap_action) && + isCallServiceActionTarget(configuration.tap_action.target) ) { - this.#defaultConfig.tap_action.target.entity_id = entity.entity_id; + configuration.tap_action.target.entity_id = entity.entity_id; } + configuration.icon = Registry.hassStates[entity.entity_id]?.attributes.icon ?? configuration.icon; - this.#defaultConfig.icon = Helper.getEntityState(entity)?.attributes.icon ?? this.#defaultConfig.icon; - - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...configuration, ...customConfiguration }; } } -export {SceneCard}; +export default SceneCard; diff --git a/src/cards/SelectCard.ts b/src/cards/SelectCard.ts index a1c7ad3..9fad989 100644 --- a/src/cards/SelectCard.ts +++ b/src/cards/SelectCard.ts @@ -1,41 +1,34 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {SelectCardConfig} from "../types/lovelace-mushroom/cards/select-card-config"; +// noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { SelectCardConfig } from '../types/lovelace-mushroom/cards/select-card-config'; +import AbstractCard from './AbstractCard'; -// noinspection JSUnusedGlobalSymbols Class is dynamically imported /** * Select Card Class * - * Used to create a card for controlling an entity of the select domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the select domain. */ class SelectCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {SelectCardConfig} - * @private - */ - #defaultConfig: SelectCardConfig = { - type: "custom:mushroom-select-card", - icon: undefined, - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): SelectCardConfig { + return { + type: 'custom:mushroom-select-card', + icon: undefined, + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.SelectCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {SelectCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.SelectCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: SelectCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...SelectCard.getDefaultConfig(), ...customConfiguration }; } } -export {SelectCard}; +export default SelectCard; diff --git a/src/cards/SensorCard.ts b/src/cards/SensorCard.ts index 92e9107..32c59d6 100644 --- a/src/cards/SensorCard.ts +++ b/src/cards/SensorCard.ts @@ -1,42 +1,34 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {EntityCardConfig} from "../types/lovelace-mushroom/cards/entity-card-config"; +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config'; +import AbstractCard from './AbstractCard'; /** * Sensor Card Class * * Used to create a card for controlling an entity of the sensor domain. - * - * @class - * @extends AbstractCard */ class SensorCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {EntityCardConfig} - * @private - */ - #defaultConfig: EntityCardConfig = { - type: "custom:mushroom-entity-card", - icon: "mdi:information", - animate: true, - line_color: "green", - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): EntityCardConfig { + return { + type: 'custom:mushroom-entity-card', + icon: 'mdi:information', + animate: true, + line_color: 'green', + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.EntityCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {EntityCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...SensorCard.getDefaultConfig(), ...customConfiguration }; } } -export {SensorCard}; +export default SensorCard; diff --git a/src/cards/SwitchCard.ts b/src/cards/SwitchCard.ts index 5d3f78a..02d3982 100644 --- a/src/cards/SwitchCard.ts +++ b/src/cards/SwitchCard.ts @@ -1,44 +1,37 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {EntityCardConfig} from "../types/lovelace-mushroom/cards/entity-card-config"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config'; +import AbstractCard from './AbstractCard'; + /** * Switch Card Class * - * Used to create a card for controlling an entity of the switch domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the switch domain. */ class SwitchCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {EntityCardConfig} - * @private - */ - #defaultConfig: EntityCardConfig = { - type: "custom:mushroom-entity-card", - icon: undefined, - tap_action: { - action: "toggle", - }, - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): EntityCardConfig { + return { + type: 'custom:mushroom-entity-card', + icon: undefined, + tap_action: { + action: 'toggle', + }, + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.EntityCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {EntityCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...SwitchCard.getDefaultConfig(), ...customConfiguration }; } } -export {SwitchCard}; +export default SwitchCard; diff --git a/src/cards/VacuumCard.ts b/src/cards/VacuumCard.ts index f76b4fa..513557d 100644 --- a/src/cards/VacuumCard.ts +++ b/src/cards/VacuumCard.ts @@ -1,46 +1,39 @@ -import {AbstractCard} from "./AbstractCard"; -import {cards} from "../types/strategy/cards"; -import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry"; -import {VACUUM_COMMANDS, VacuumCardConfig} from "../types/lovelace-mushroom/cards/vacuum-card-config"; - // noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { VACUUM_COMMANDS, VacuumCardConfig } from '../types/lovelace-mushroom/cards/vacuum-card-config'; +import AbstractCard from './AbstractCard'; + /** * Vacuum Card Class * - * Used to create a card for controlling an entity of the vacuum domain. - * - * @class - * @extends AbstractCard + * Used to create a card configuration to control an entity of the vacuum domain. */ class VacuumCard extends AbstractCard { - /** - * Default configuration of the card. - * - * @type {VacuumCardConfig} - * @private - */ - #defaultConfig: VacuumCardConfig = { - type: "custom:mushroom-vacuum-card", - icon: undefined, - icon_animation: true, - commands: [...VACUUM_COMMANDS], - tap_action: { - action: "more-info", - } - }; + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): VacuumCardConfig { + return { + type: 'custom:mushroom-vacuum-card', + icon: undefined, + icon_animation: true, + commands: [...VACUUM_COMMANDS], + tap_action: { + action: 'more-info', + }, + }; + } /** * Class constructor. * - * @param {EntityRegistryEntry} entity The hass entity to create a card for. - * @param {cards.VacuumCardOptions} [options={}] Options for the card. - * @throws {Error} If the Helper module isn't initialized. + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {VacuumCardConfig} [customConfiguration] Custom card configuration. */ - constructor(entity: EntityRegistryEntry, options: cards.VacuumCardOptions = {}) { + constructor(entity: EntityRegistryEntry, customConfiguration?: VacuumCardConfig) { super(entity); - this.config = Object.assign(this.config, this.#defaultConfig, options); + this.configuration = { ...this.configuration, ...VacuumCard.getDefaultConfig(), ...customConfiguration }; } } -export {VacuumCard}; +export default VacuumCard;