This commit is contained in:
DigiLive
2025-05-10 09:10:50 +02:00
parent f2ecdfe562
commit 737c6ece37
33 changed files with 316 additions and 311 deletions

View File

@@ -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.
*/

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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<LovelaceCardConfig[]>;
/**
* Creates Lovelace card configurations for devices.
*

View File

@@ -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<EntityRegistryEntry["disabled_by"], "config_entry">} hidden_by - Indicates what hidden this
* @property {Exclude<EntityRegistryEntry['disabled_by'], 'config_entry'>} 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.

View File

@@ -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<string, unknown>} [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.

View File

@@ -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.

View File

@@ -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';

View File

@@ -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<LovelaceViewConfig> {
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<LovelaceViewConfig> {
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;

View File

@@ -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')

View File

@@ -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;

View File

@@ -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;