diff --git a/src/Registry.ts b/src/Registry.ts index 97927d4..f5a8a12 100644 --- a/src/Registry.ts +++ b/src/Registry.ts @@ -34,16 +34,15 @@ class Registry { private static _areas: StrategyArea[] = []; /** Entries of Home Assistant's state registry */ private static _hassStates: HassEntities; - /** Indicates whether this module is initialized. */ - private static _initialized: boolean = false; + /** Entries of Home Assistant's config registry */ + private static _configEntries: ConfigEntry[] = []; /** The Custom strategy configuration. */ private static _strategyOptions: StrategyConfig; + /** Indicates whether this module is initialized. */ + private static _initialized: boolean = false; + /** Indicates whether dark mode is enabled */ static darkMode: boolean; - /** The entities which are grouped into a device view */ - // TODO: Create type or interface? - private static _configEntries: ConfigEntry[] = []; - /** * Home Assistant's Config Entries. */ diff --git a/src/cards/AreaCard.ts b/src/cards/AreaCard.ts index 8028958..61dd6a9 100644 --- a/src/cards/AreaCard.ts +++ b/src/cards/AreaCard.ts @@ -8,18 +8,6 @@ import AbstractCard from './AbstractCard'; * Used to create card configuration for an entry of the HASS area registry. */ class AreaCard extends AbstractCard { - /** 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. * @@ -47,6 +35,18 @@ class AreaCard extends AbstractCard { this.configuration = { ...this.configuration, ...configuration, ...customConfig }; } + + /** 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' }, + }; + } } export default AreaCard; diff --git a/src/cards/BinarySensorCard.ts b/src/cards/BinarySensorCard.ts index 065a3e8..883f4e9 100644 --- a/src/cards/BinarySensorCard.ts +++ b/src/cards/BinarySensorCard.ts @@ -10,15 +10,6 @@ import SensorCard from './SensorCard'; * Used to create a card configuration to control an entity of the binary_sensor domain. */ class BinarySensorCard extends SensorCard { - /** 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. * @@ -30,6 +21,15 @@ class BinarySensorCard extends SensorCard { this.configuration = { ...this.configuration, ...BinarySensorCard.getDefaultConfig(), ...customConfiguration }; } + + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): EntityCardConfig { + return { + type: 'custom:mushroom-entity-card', + icon: 'mdi:power-cycle', + icon_color: 'green', + }; + } } export default BinarySensorCard; diff --git a/src/cards/CameraCard.ts b/src/cards/CameraCard.ts index 161ca45..8581df8 100644 --- a/src/cards/CameraCard.ts +++ b/src/cards/CameraCard.ts @@ -10,17 +10,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the camera domain. */ class CameraCard extends AbstractCard { - /** 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. * @@ -32,6 +21,17 @@ class CameraCard extends AbstractCard { this.configuration = { ...this.configuration, ...CameraCard.getDefaultConfig(), ...customConfiguration }; } + + /** 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', + }; + } } export default CameraCard; diff --git a/src/cards/ClimateCard.ts b/src/cards/ClimateCard.ts index f00c6a9..8cd63b7 100644 --- a/src/cards/ClimateCard.ts +++ b/src/cards/ClimateCard.ts @@ -10,16 +10,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the climate domain. */ class ClimateCard extends AbstractCard { - /** 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. * @@ -31,6 +21,16 @@ class ClimateCard extends AbstractCard { this.configuration = { ...this.configuration, ...ClimateCard.getDefaultConfig(), ...customConfiguration }; } + + /** 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, + }; + } } export default ClimateCard; diff --git a/src/cards/CoverCard.ts b/src/cards/CoverCard.ts index d6c2933..b8099da 100644 --- a/src/cards/CoverCard.ts +++ b/src/cards/CoverCard.ts @@ -10,17 +10,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the cover domain. */ class CoverCard extends AbstractCard { - /** 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. * @@ -32,6 +21,17 @@ class CoverCard extends AbstractCard { this.configuration = { ...this.configuration, ...CoverCard.getDefaultConfig(), ...customConfiguration }; } + + /** 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, + }; + } } export default CoverCard; diff --git a/src/cards/HaAreaCard.ts b/src/cards/HaAreaCard.ts index 4bdca38..ad52467 100644 --- a/src/cards/HaAreaCard.ts +++ b/src/cards/HaAreaCard.ts @@ -10,14 +10,6 @@ import AbstractCard from './AbstractCard'; * Used to create card configuration for an entry of the HASS area registry. */ class AreaCard extends AbstractCard { - /** Returns the default configuration object for the card. */ - static getDefaultConfig(): AreaCardConfig { - return { - type: 'area', - area: '', - }; - } - /** * Class constructor. * @@ -40,6 +32,14 @@ class AreaCard extends AbstractCard { type: configuration.type, // Enforce the card type. }; } + + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): AreaCardConfig { + return { + type: 'area', + area: '', + }; + } } export default AreaCard; diff --git a/src/cards/InputSelectCard.ts b/src/cards/InputSelectCard.ts index 86253b0..2a6d081 100644 --- a/src/cards/InputSelectCard.ts +++ b/src/cards/InputSelectCard.ts @@ -10,14 +10,6 @@ import SelectCard from './SelectCard'; * Used to create a card configuration to control an entity of the input_select domain. */ class InputSelectCard extends SelectCard { - /** Returns the default configuration object for the card. */ - static getDefaultConfig(): SelectCardConfig { - return { - type: 'custom:mushroom-select-card', - icon: undefined, - }; - } - /** * Class constructor. * @@ -29,6 +21,14 @@ class InputSelectCard extends SelectCard { this.configuration = { ...this.configuration, ...InputSelectCard.getDefaultConfig(), ...customConfiguration }; } + + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): SelectCardConfig { + return { + type: 'custom:mushroom-select-card', + icon: undefined, + }; + } } export default InputSelectCard; diff --git a/src/cards/LockCard.ts b/src/cards/LockCard.ts index d0892d9..6cd1f4a 100644 --- a/src/cards/LockCard.ts +++ b/src/cards/LockCard.ts @@ -10,14 +10,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the lock domain. */ class LockCard extends AbstractCard { - /** Returns the default configuration object for the card. */ - static getDefaultConfig(): LockCardConfig { - return { - type: 'custom:mushroom-lock-card', - icon: undefined, - }; - } - /** * Class constructor. * @@ -29,6 +21,14 @@ class LockCard extends AbstractCard { this.configuration = { ...this.configuration, ...LockCard.getDefaultConfig(), ...customConfiguration }; } + + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): LockCardConfig { + return { + type: 'custom:mushroom-lock-card', + icon: undefined, + }; + } } export default LockCard; diff --git a/src/cards/MediaPlayerCard.ts b/src/cards/MediaPlayerCard.ts index 4464567..23ccf3f 100644 --- a/src/cards/MediaPlayerCard.ts +++ b/src/cards/MediaPlayerCard.ts @@ -10,17 +10,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the media_player domain. */ class MediaPlayerCard extends AbstractCard { - /** 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. * @@ -32,6 +21,17 @@ class MediaPlayerCard extends AbstractCard { this.configuration = { ...this.configuration, ...MediaPlayerCard.getDefaultConfig(), ...customConfiguration }; } + + /** 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'], + }; + } } export default MediaPlayerCard; diff --git a/src/cards/MiscellaneousCard.ts b/src/cards/MiscellaneousCard.ts index 1b1fe3a..3c98395 100644 --- a/src/cards/MiscellaneousCard.ts +++ b/src/cards/MiscellaneousCard.ts @@ -8,14 +8,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of any domain. */ class MiscellaneousCard extends AbstractCard { - /** Returns the default configuration object for the card. */ - static getDefaultConfig(): EntityCardConfig { - return { - type: 'custom:mushroom-entity-card', - icon_color: 'blue-grey', - }; - } - /** * Class constructor. * @@ -27,6 +19,14 @@ class MiscellaneousCard extends AbstractCard { this.configuration = { ...this.configuration, ...MiscellaneousCard.getDefaultConfig(), ...customConfiguration }; } + + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): EntityCardConfig { + return { + type: 'custom:mushroom-entity-card', + icon_color: 'blue-grey', + }; + } } export default MiscellaneousCard; diff --git a/src/cards/NumberCard.ts b/src/cards/NumberCard.ts index a5eef46..395b022 100644 --- a/src/cards/NumberCard.ts +++ b/src/cards/NumberCard.ts @@ -10,14 +10,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the number domain. */ class NumberCard extends AbstractCard { - /** Returns the default configuration object for the card. */ - static getDefaultConfig(): NumberCardConfig { - return { - type: 'custom:mushroom-number-card', - icon: undefined, - }; - } - /** * Class constructor. * @@ -29,6 +21,14 @@ class NumberCard extends AbstractCard { this.configuration = { ...this.configuration, ...NumberCard.getDefaultConfig(), ...customConfiguration }; } + + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): NumberCardConfig { + return { + type: 'custom:mushroom-number-card', + icon: undefined, + }; + } } export default NumberCard; diff --git a/src/cards/PersonCard.ts b/src/cards/PersonCard.ts index 9f65382..850fc0f 100644 --- a/src/cards/PersonCard.ts +++ b/src/cards/PersonCard.ts @@ -8,17 +8,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the person domain. */ class PersonCard extends AbstractCard { - /** 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. * @@ -30,6 +19,17 @@ class PersonCard extends AbstractCard { this.configuration = { ...this.configuration, ...PersonCard.getDefaultConfig(), ...customConfiguration }; } + + /** 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', + }; + } } export default PersonCard; diff --git a/src/cards/SelectCard.ts b/src/cards/SelectCard.ts index 9fad989..1bd0f1b 100644 --- a/src/cards/SelectCard.ts +++ b/src/cards/SelectCard.ts @@ -10,14 +10,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the select domain. */ class SelectCard extends AbstractCard { - /** Returns the default configuration object for the card. */ - static getDefaultConfig(): SelectCardConfig { - return { - type: 'custom:mushroom-select-card', - icon: undefined, - }; - } - /** * Class constructor. * @@ -29,6 +21,14 @@ class SelectCard extends AbstractCard { this.configuration = { ...this.configuration, ...SelectCard.getDefaultConfig(), ...customConfiguration }; } + + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): SelectCardConfig { + return { + type: 'custom:mushroom-select-card', + icon: undefined, + }; + } } export default SelectCard; diff --git a/src/cards/SensorCard.ts b/src/cards/SensorCard.ts index 32c59d6..c78d495 100644 --- a/src/cards/SensorCard.ts +++ b/src/cards/SensorCard.ts @@ -8,16 +8,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card for controlling an entity of the sensor domain. */ class SensorCard extends AbstractCard { - /** 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. * @@ -29,6 +19,16 @@ class SensorCard extends AbstractCard { this.configuration = { ...this.configuration, ...SensorCard.getDefaultConfig(), ...customConfiguration }; } + + /** 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', + }; + } } export default SensorCard; diff --git a/src/cards/SwitchCard.ts b/src/cards/SwitchCard.ts index 02d3982..470a756 100644 --- a/src/cards/SwitchCard.ts +++ b/src/cards/SwitchCard.ts @@ -10,17 +10,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the switch domain. */ class SwitchCard extends AbstractCard { - /** 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. * @@ -32,6 +21,17 @@ class SwitchCard extends AbstractCard { this.configuration = { ...this.configuration, ...SwitchCard.getDefaultConfig(), ...customConfiguration }; } + + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): EntityCardConfig { + return { + type: 'custom:mushroom-entity-card', + icon: undefined, + tap_action: { + action: 'toggle', + }, + }; + } } export default SwitchCard; diff --git a/src/cards/VacuumCard.ts b/src/cards/VacuumCard.ts index 513557d..913ee0a 100644 --- a/src/cards/VacuumCard.ts +++ b/src/cards/VacuumCard.ts @@ -10,6 +10,18 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the vacuum domain. */ class VacuumCard extends AbstractCard { + /** + * Class constructor. + * + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {VacuumCardConfig} [customConfiguration] Custom card configuration. + */ + constructor(entity: EntityRegistryEntry, customConfiguration?: VacuumCardConfig) { + super(entity); + + this.configuration = { ...this.configuration, ...VacuumCard.getDefaultConfig(), ...customConfiguration }; + } + /** Returns the default configuration object for the card. */ static getDefaultConfig(): VacuumCardConfig { return { @@ -22,18 +34,6 @@ class VacuumCard extends AbstractCard { }, }; } - - /** - * Class constructor. - * - * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. - * @param {VacuumCardConfig} [customConfiguration] Custom card configuration. - */ - constructor(entity: EntityRegistryEntry, customConfiguration?: VacuumCardConfig) { - super(entity); - - this.configuration = { ...this.configuration, ...VacuumCard.getDefaultConfig(), ...customConfiguration }; - } } export default VacuumCard; diff --git a/src/cards/ValveCard.ts b/src/cards/ValveCard.ts index e9a5e38..a0f6350 100644 --- a/src/cards/ValveCard.ts +++ b/src/cards/ValveCard.ts @@ -11,18 +11,6 @@ import AbstractCard from './AbstractCard'; * Used to create a card configuration to control an entity of the valve domain. */ class ValveCard extends AbstractCard { - /** Returns the default configuration object for the card. */ - static getDefaultConfig(): TemplateCardConfig { - return { - type: 'custom:mushroom-template-card', - icon: 'mdi:valve', - icon_color: 'blue', - double_tap_action: { - action: 'toggle', - }, - }; - } - /** * Class constructor. * @@ -38,7 +26,7 @@ class ValveCard extends AbstractCard { configuration.entity = entity.entity_id; configuration.icon = entity.icon ?? configuration.icon; configuration.primary = entity.name ?? entity.original_name ?? '?'; - configuration.secondary = `{% + configuration.secondary = `{% set mapping = { 'open': '${localize('valve.open')}', 'opening': '${localize('valve.opening')}', @@ -52,6 +40,18 @@ class ValveCard extends AbstractCard { this.configuration = { ...this.configuration, ...configuration, ...customConfiguration }; } + + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): TemplateCardConfig { + return { + type: 'custom:mushroom-template-card', + icon: 'mdi:valve', + icon_color: 'blue', + double_tap_action: { + action: 'toggle', + }, + }; + } } export default ValveCard; diff --git a/src/chips/ClimateChip.ts b/src/chips/ClimateChip.ts index fb1b4df..7420a7c 100644 --- a/src/chips/ClimateChip.ts +++ b/src/chips/ClimateChip.ts @@ -10,6 +10,17 @@ import AbstractChip from './AbstractChip'; * Used to create a chip configuration to indicate how many climates are operating. */ class ClimateChip extends AbstractChip { + /** + * Class Constructor. + * + * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. + */ + constructor(customConfiguration?: TemplateChipConfig) { + super(); + + this.configuration = { ...this.configuration, ...ClimateChip.getDefaultConfig(), ...customConfiguration }; + } + /** Returns the default configuration object for the chip. */ static getDefaultConfig(): TemplateChipConfig { return { @@ -26,17 +37,6 @@ class ClimateChip extends AbstractChip { }, }; } - - /** - * Class Constructor. - * - * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. - */ - constructor(customConfiguration?: TemplateChipConfig) { - super(); - - this.configuration = { ...this.configuration, ...ClimateChip.getDefaultConfig(), ...customConfiguration }; - } } export default ClimateChip; diff --git a/src/chips/CoverChip.ts b/src/chips/CoverChip.ts index 96b1f4c..608da95 100644 --- a/src/chips/CoverChip.ts +++ b/src/chips/CoverChip.ts @@ -10,6 +10,17 @@ import AbstractChip from './AbstractChip'; * Used to create a chip configuration to indicate how many covers aren't closed. */ class CoverChip extends AbstractChip { + /** + * Class Constructor. + * + * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. + */ + constructor(customConfiguration?: TemplateChipConfig) { + super(); + + this.configuration = { ...this.configuration, ...CoverChip.getDefaultConfig(), ...customConfiguration }; + } + /** Returns the default configuration object for the chip. */ static getDefaultConfig(): TemplateChipConfig { return { @@ -26,17 +37,6 @@ class CoverChip extends AbstractChip { }, }; } - - /** - * Class Constructor. - * - * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. - */ - constructor(customConfiguration?: TemplateChipConfig) { - super(); - - this.configuration = { ...this.configuration, ...CoverChip.getDefaultConfig(), ...customConfiguration }; - } } export default CoverChip; diff --git a/src/chips/FanChip.ts b/src/chips/FanChip.ts index bfcc616..f472107 100644 --- a/src/chips/FanChip.ts +++ b/src/chips/FanChip.ts @@ -11,6 +11,17 @@ import RegistryFilter from '../utilities/RegistryFilter'; * Used to create a chip to indicate how many fans are on and to switch them all off. */ class FanChip extends AbstractChip { + /** + * Class Constructor. + * + * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. + */ + constructor(customConfiguration?: TemplateChipConfig) { + super(); + + this.configuration = { ...this.configuration, ...FanChip.getDefaultConfig(), ...customConfiguration }; + } + /** Returns the default configuration object for the chip. */ static getDefaultConfig(): TemplateChipConfig { return { @@ -33,17 +44,6 @@ class FanChip extends AbstractChip { }, }; } - - /** - * Class Constructor. - * - * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. - */ - constructor(customConfiguration?: TemplateChipConfig) { - super(); - - this.configuration = { ...this.configuration, ...FanChip.getDefaultConfig(), ...customConfiguration }; - } } export default FanChip; diff --git a/src/chips/LightChip.ts b/src/chips/LightChip.ts index b70e0e1..96bba9d 100644 --- a/src/chips/LightChip.ts +++ b/src/chips/LightChip.ts @@ -11,6 +11,17 @@ import RegistryFilter from '../utilities/RegistryFilter'; * Used to create a chip configuration to indicate how many lights are on and to switch them all off. */ class LightChip extends AbstractChip { + /** + * Class Constructor. + * + * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. + */ + constructor(customConfiguration?: TemplateChipConfig) { + super(); + + this.configuration = { ...this.configuration, ...LightChip.getDefaultConfig(), ...customConfiguration }; + } + /** Returns the default configuration object for the chip. */ static getDefaultConfig(): TemplateChipConfig { return { @@ -33,17 +44,6 @@ class LightChip extends AbstractChip { }, }; } - - /** - * Class Constructor. - * - * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. - */ - constructor(customConfiguration?: TemplateChipConfig) { - super(); - - this.configuration = { ...this.configuration, ...LightChip.getDefaultConfig(), ...customConfiguration }; - } } export default LightChip; diff --git a/src/chips/SwitchChip.ts b/src/chips/SwitchChip.ts index 7e341d1..fe6701f 100644 --- a/src/chips/SwitchChip.ts +++ b/src/chips/SwitchChip.ts @@ -11,6 +11,17 @@ import RegistryFilter from '../utilities/RegistryFilter'; * Used to create a chip configuration to indicate how many switches are on and to switch them all off. */ class SwitchChip extends AbstractChip { + /** + * Class Constructor. + * + * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. + */ + constructor(customConfiguration?: TemplateChipConfig) { + super(); + + this.configuration = { ...this.configuration, ...SwitchChip.getDefaultConfig(), ...customConfiguration }; + } + /** Returns the default configuration object for the chip. */ static getDefaultConfig(): TemplateChipConfig { return { @@ -33,17 +44,6 @@ class SwitchChip extends AbstractChip { }, }; } - - /** - * Class Constructor. - * - * @param {TemplateChipConfig} [customConfiguration] Custom chip configuration. - */ - constructor(customConfiguration?: TemplateChipConfig) { - super(); - - this.configuration = { ...this.configuration, ...SwitchChip.getDefaultConfig(), ...customConfiguration }; - } } export default SwitchChip; diff --git a/src/chips/WeatherChip.ts b/src/chips/WeatherChip.ts index 1cb5490..e87af56 100644 --- a/src/chips/WeatherChip.ts +++ b/src/chips/WeatherChip.ts @@ -9,16 +9,6 @@ import AbstractChip from './AbstractChip'; * Used to create a chip configuration to indicate the current weather. */ class WeatherChip extends AbstractChip { - /** Returns the default configuration object for the chip. */ - static getDefaultConfig(entityId: string): WeatherChipConfig { - return { - type: 'weather', - entity: entityId, - show_temperature: true, - show_conditions: true, - }; - } - /** * Class Constructor. * @@ -30,6 +20,16 @@ class WeatherChip extends AbstractChip { this.configuration = { ...this.configuration, ...WeatherChip.getDefaultConfig(entityId), ...customConfiguration }; } + + /** Returns the default configuration object for the chip. */ + static getDefaultConfig(entityId: string): WeatherChipConfig { + return { + type: 'weather', + entity: entityId, + show_temperature: true, + show_conditions: true, + }; + } } export default WeatherChip; diff --git a/src/generators/domainCardsGenerator.ts b/src/generators/domainCardsGenerator.ts index 91d761d..ffd683f 100644 --- a/src/generators/domainCardsGenerator.ts +++ b/src/generators/domainCardsGenerator.ts @@ -42,6 +42,13 @@ abstract class DomainCardsGenerator { this.domains = properties.domains; } + /** + * Creates a list of Lovelace card configurations. + * + * @returns A promise that resolves to a list of Lovelace card configurations. + */ + abstract getCards(): Promise; + /** * Creates Lovelace card configurations for devices. * diff --git a/src/types/homeassistant/data/entity_registry.ts b/src/types/homeassistant/data/entity_registry.ts index 7690255..3841e0b 100644 --- a/src/types/homeassistant/data/entity_registry.ts +++ b/src/types/homeassistant/data/entity_registry.ts @@ -46,9 +46,9 @@ export interface EntityRegistryDisplayEntry { * @property {string | null} device_id - The ID of the device linked to this entity. * @property {string | null} area_id - The ID of the area linked to this entity. * @property {string[]} labels - Labels associated with the entity. - * @property {"user" | "device" | "integration" | "config_entry" | null} disabled_by - Indicates what disabled this + * @property {'user' | 'device' | 'integration' | 'config_entry' | null} disabled_by - Indicates what disabled this * entity. - * @property {Exclude} hidden_by - Indicates what hidden this + * @property {Exclude} hidden_by - Indicates what hidden this * entity. * @property {EntityCategory | null} entity_category - The category of the entity. * @property {boolean} has_entity_name - Indicates if the entity has a name. diff --git a/src/types/homeassistant/panels/lovelace/cards/types.ts b/src/types/homeassistant/panels/lovelace/cards/types.ts index b0a3462..31c785a 100644 --- a/src/types/homeassistant/panels/lovelace/cards/types.ts +++ b/src/types/homeassistant/panels/lovelace/cards/types.ts @@ -7,7 +7,7 @@ import { LovelaceCardConfig } from '../../../data/lovelace/config/card'; * @property {string} area - The area associated with the card. * @property {string} [navigation_path] - Optional navigation path for the card. * @property {boolean} [show_camera] - Whether to show the camera view. - * @property {"live" | "auto"} [camera_view] - The camera view mode. + * @property {'live' | 'auto'} [camera_view] - The camera view mode. * @property {string} [aspect_ratio] - The aspect ratio of the card. * @see https://www.home-assistant.io/dashboards/area/ */ @@ -26,7 +26,7 @@ export interface AreaCardConfig extends LovelaceCardConfig { * @property {string} [name] - Overwrite entity name. * @property {string} [image] - URL of an image. * @property {string} [camera_image] - Camera entity_id to use. - * @property {"live" | "auto"} [camera_view] - The camera view mode. + * @property {'live' | 'auto'} [camera_view] - The camera view mode. * @property {Record} [state_image] - Map entity states to images. * @property {string[]} [state_filter] - State-based CSS filters. * @property {string} [aspect_ratio] - Forces the height of the image to be a ratio of the width. diff --git a/src/types/homeassistant/panels/lovelace/types.ts b/src/types/homeassistant/panels/lovelace/types.ts index 1bfba97..a1132cb 100644 --- a/src/types/homeassistant/panels/lovelace/types.ts +++ b/src/types/homeassistant/panels/lovelace/types.ts @@ -1,8 +1,8 @@ /** * Represents the layout options for Lovelace in Home Assistant. * - * @property {number | "full"} [grid_columns] - The number of grid columns or "full". - * @property {number | "auto"} [grid_rows] - The number of grid rows or "auto". + * @property {number | 'full'} [grid_columns] - The number of grid columns or "full". + * @property {number | 'auto'} [grid_rows] - The number of grid rows or "auto". * @property {number} [grid_max_columns] - The maximum number of grid columns. * @property {number} [grid_min_columns] - The minimum number of grid columns. * @property {number} [grid_min_rows] - The minimum number of grid rows. @@ -20,8 +20,8 @@ export interface LovelaceLayoutOptions { /** * Represents the grid options for Lovelace in Home Assistant. * - * @property {number | "full"} [columns] - The number of columns or "full". - * @property {number | "auto"} [rows] - The number of rows or "auto". + * @property {number | 'full'} [columns] - The number of columns or "full". + * @property {number | 'auto'} [rows] - The number of rows or "auto". * @property {number} [max_columns] - The maximum number of columns. * @property {number} [min_columns] - The minimum number of columns. * @property {number} [min_rows] - The minimum number of rows. diff --git a/src/types/lovelace-mushroom/utils/lovelace/chip/types.ts b/src/types/lovelace-mushroom/utils/lovelace/chip/types.ts index 4dc3a0f..c729462 100644 --- a/src/types/lovelace-mushroom/utils/lovelace/chip/types.ts +++ b/src/types/lovelace-mushroom/utils/lovelace/chip/types.ts @@ -4,7 +4,7 @@ import { Info } from '../../info'; /** * Action Chip Config * - * @property {"action"} type - Type of the chip. + * @property {'action'} type - Type of the chip. * @property {string} [icon] - Custom icon for the chip. * @property {string} [icon_color] - Custom color for the icon. * @property {ActionConfig} [tap_action] - Home Assistant action to perform on tap. @@ -23,7 +23,7 @@ export type ActionChipConfig = { /** * Alarm Control Panel Chip Config * - * @property {"alarm-control-panel"} type - Type of the chip. + * @property {'alarm-control-panel'} type - Type of the chip. * @property {string} [entity] - The entity ID associated with the chip. * @property {string} [name] - Custom name for the chip. * @property {Info} [content_info] - Custom content information. @@ -48,7 +48,7 @@ export type AlarmControlPanelChipConfig = { /** * Back Chip Config * - * @property {"back"} type - Type of the chip. + * @property {'back'} type - Type of the chip. * @property {string} [icon] - Custom icon for the chip. */ export type BackChipConfig = { @@ -59,7 +59,7 @@ export type BackChipConfig = { /** * Entity Chip Config * - * @property {"entity"} type - Type of the chip. + * @property {'entity'} type - Type of the chip. * @property {string} [entity] - The entity ID associated with the chip. * @property {string} [name] - Custom name for the chip. * @property {Info} [content_info] - Custom content information. @@ -86,7 +86,7 @@ export type EntityChipConfig = { /** * Menu Chip Config * - * @property {"menu"} type - Type of the chip. + * @property {'menu'} type - Type of the chip. * @property {string} [icon] - Custom icon for the chip. */ export type MenuChipConfig = { @@ -97,7 +97,7 @@ export type MenuChipConfig = { /** * Weather Chip Config * - * @property {"weather"} type - Type of the chip. + * @property {'weather'} type - Type of the chip. * @property {string} [entity] - The entity ID associated with the chip. * @property {ActionConfig} [tap_action] - Home Assistant action to perform on tap. * @property {ActionConfig} [hold_action] - Home Assistant action to perform on hold. @@ -118,7 +118,7 @@ export type WeatherChipConfig = { /** * Template Chip Config * - * @property {"template"} type - Type of the chip. + * @property {'template'} type - Type of the chip. * @property {string} [entity] - The entity ID associated with the chip. * @property {ActionConfig} [tap_action] - Home Assistant action to perform on tap. * @property {ActionConfig} [hold_action] - Home Assistant action to perform on hold. @@ -145,7 +145,7 @@ export type TemplateChipConfig = { /** * Conditional Chip Config * - * @property {"conditional"} type - Type of the chip. + * @property {'conditional'} type - Type of the chip. * @property {LovelaceChipConfig} [chip] - A chip configuration. * @property {[]} conditions - Conditions for the chip. */ @@ -158,7 +158,7 @@ export type ConditionalChipConfig = { /** * Light Chip Config * - * @property {"light"} type - Type of the chip. + * @property {'light'} type - Type of the chip. * @property {string} [entity] - The entity ID associated with the chip. * @property {string} [name] - Custom name for the chip. * @property {Info} [content_info] - Custom content information. @@ -183,7 +183,7 @@ export type LightChipConfig = { /** * Spacer Chip Config * - * @property {"spacer"} type - Type of the chip. + * @property {'spacer'} type - Type of the chip. */ export type SpacerChipConfig = { type: 'spacer'; diff --git a/src/views/AbstractView.ts b/src/views/AbstractView.ts index e6a3aa3..943227f 100644 --- a/src/views/AbstractView.ts +++ b/src/views/AbstractView.ts @@ -4,12 +4,12 @@ import { Registry } from '../Registry'; import { LovelaceCardConfig } from '../types/homeassistant/data/lovelace/config/card'; import { LovelaceViewConfig } from '../types/homeassistant/data/lovelace/config/view'; import { StackCardConfig } from '../types/homeassistant/panels/lovelace/cards/types'; -import { AbstractCardConfig, CustomHeaderCardConfig, StrategyHeaderCardConfig } from '../types/strategy/strategy-cards'; import { SupportedDomains } from '../types/strategy/strategy-generics'; import { ViewConfig, ViewConstructor } from '../types/strategy/strategy-views'; import { sanitizeClassName } from '../utilities/auxiliaries'; import { logMessage, lvlFatal } from '../utilities/debug'; import RegistryFilter from '../utilities/RegistryFilter'; +import { AbstractCardConfig, HeaderCardConfig } from '../types/strategy/strategy-cards'; /** * Abstract View Class. @@ -33,10 +33,6 @@ abstract class AbstractView { type: '', }; - protected get domain(): SupportedDomains | 'home' { - return (this.constructor as unknown as ViewConstructor).domain; - } - /** * Class constructor. * @@ -49,6 +45,22 @@ abstract class AbstractView { } } + protected get domain(): SupportedDomains | 'home' { + return (this.constructor as unknown as ViewConstructor).domain; + } + + /** + * Get a view configuration. + * + * The configuration includes the card configurations which are created by createCardConfigurations(). + */ + async getView(): Promise { + return { + ...this.baseConfiguration, + cards: await this.createCardConfigurations(), + }; + } + /** * Create the configuration of the cards to include in the view. */ @@ -90,7 +102,7 @@ abstract class AbstractView { // Create and insert a Header card. const areaHeaderCardOptions = ( 'headerCardConfiguration' in this.baseConfiguration ? this.baseConfiguration.headerCardConfiguration : {} - ) as CustomHeaderCardConfig; + ) as HeaderCardConfig; areaCards.unshift(new HeaderCard(target, { title: area.name, ...areaHeaderCardOptions }).createCard()); @@ -107,15 +119,25 @@ abstract class AbstractView { } /** - * Get a view configuration. + * Initialize the view configuration with defaults and custom settings. * - * The configuration includes the card configurations which are created by createCardConfigurations(). + * @param viewConfiguration The view's default configuration for the view. + * @param customConfiguration The view's custom configuration to apply. + * @param headerCardConfig The view's Header card configuration. */ - async getView(): Promise { - return { - ...this.baseConfiguration, - cards: await this.createCardConfigurations(), - }; + protected initializeViewConfig( + viewConfiguration: ViewConfig, + customConfiguration: ViewConfig = {}, + headerCardConfig: HeaderCardConfig, + ): void { + this.baseConfiguration = { ...this.baseConfiguration, ...viewConfiguration, ...customConfiguration }; + + this.viewHeaderCardConfiguration = new HeaderCard(this.getDomainTargets(), { + ...(('headerCardConfiguration' in this.baseConfiguration + ? this.baseConfiguration.headerCardConfiguration + : {}) as HeaderCardConfig), + ...headerCardConfig, + }).createCard(); } /** @@ -128,28 +150,6 @@ abstract class AbstractView { .map((entity) => entity.entity_id), }; } - - /** - * Initialize the view configuration with defaults and custom settings. - * - * @param viewConfiguration The view's default configuration for the view. - * @param customConfiguration The view's custom configuration to apply. - * @param headerCardConfig The view's Header card configuration. - */ - protected initializeViewConfig( - viewConfiguration: ViewConfig, - customConfiguration: ViewConfig = {}, - headerCardConfig: CustomHeaderCardConfig, - ): void { - this.baseConfiguration = { ...this.baseConfiguration, ...viewConfiguration, ...customConfiguration }; - - this.viewHeaderCardConfiguration = new HeaderCard(this.getDomainTargets(), { - ...(('headerCardConfiguration' in this.baseConfiguration - ? this.baseConfiguration.headerCardConfiguration - : {}) as StrategyHeaderCardConfig), - ...headerCardConfig, - }).createCard(); - } } export default AbstractView; diff --git a/src/views/HomeView.ts b/src/views/HomeView.ts index ce39b76..4ee444e 100644 --- a/src/views/HomeView.ts +++ b/src/views/HomeView.ts @@ -253,7 +253,6 @@ class HomeView extends AbstractView { cardConfigurations.push(new AreaCard(area).getCard()); } - // FIXME: The columns are too narrow when having HASS area cards. return { type: 'vertical-stack', title: (Registry.strategyOptions.home_view.hidden as HomeViewSections[]).includes('areasTitle') diff --git a/src/views/LightView.ts b/src/views/LightView.ts index e989900..3f45693 100644 --- a/src/views/LightView.ts +++ b/src/views/LightView.ts @@ -19,6 +19,12 @@ class LightView extends AbstractView { /** The domain of the entities that the view is representing. */ static readonly domain = 'light' as const; + constructor(customConfiguration?: ViewConfig) { + super(); + + this.initializeViewConfig(LightView.getDefaultConfig(), customConfiguration, LightView.getViewHeaderCardConfig()); + } + /** Returns the default configuration object for the view. */ static getDefaultConfig(): ViewConfig { const domainConfig = Registry.strategyOptions.domains[LightView.domain] as SingleDomainConfig; @@ -45,12 +51,6 @@ class LightView extends AbstractView { localize('generic.on'), }; } - - constructor(customConfiguration?: ViewConfig) { - super(); - - this.initializeViewConfig(LightView.getDefaultConfig(), customConfiguration, LightView.getViewHeaderCardConfig()); - } } export default LightView; diff --git a/src/views/VacuumView.ts b/src/views/VacuumView.ts index 4aea269..4faeb9b 100644 --- a/src/views/VacuumView.ts +++ b/src/views/VacuumView.ts @@ -16,6 +16,17 @@ class VacuumView extends AbstractView { /** The domain of the entities that the view is representing. */ static readonly domain = 'vacuum' as const; + /** + * Class constructor. + * + * @param {ViewConfig} [customConfiguration] Custom view configuration. + */ + constructor(customConfiguration?: ViewConfig) { + super(); + + this.initializeViewConfig(VacuumView.getDefaultConfig(), customConfiguration, VacuumView.getViewHeaderCardConfig()); + } + /** Returns the default configuration object for the view. */ static getDefaultConfig(): ViewConfig { const domainConfig = Registry.strategyOptions.domains[VacuumView.domain] as SingleDomainConfig; @@ -42,17 +53,6 @@ class VacuumView extends AbstractView { localize('generic.busy'), }; } - - /** - * Class constructor. - * - * @param {ViewConfig} [customConfiguration] Custom view configuration. - */ - constructor(customConfiguration?: ViewConfig) { - super(); - - this.initializeViewConfig(VacuumView.getDefaultConfig(), customConfiguration, VacuumView.getViewHeaderCardConfig()); - } } export default VacuumView;