forked from DigiLive/mushroom-strategy
Optimize Cards
- Make use of the debug module. - Make use of the Registry module. - Align code across the chip modules. - Make configurations immutable. - Make use of the refactored types.
This commit is contained in:
@@ -1,59 +1,59 @@
|
|||||||
import {Helper} from "../Helper";
|
import { Registry } from '../Registry';
|
||||||
import {EntityCardConfig} from "../types/lovelace-mushroom/cards/entity-card-config";
|
import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config';
|
||||||
import {cards} from "../types/strategy/cards";
|
import { AbstractCardConfig } from '../types/strategy/strategy-cards';
|
||||||
import {generic} from "../types/strategy/generic";
|
import { RegistryEntry } from '../types/strategy/strategy-generics';
|
||||||
|
import { logMessage, lvlFatal } from '../utilities/debug';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Card Class
|
* 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
|
* @remarks
|
||||||
* @abstract
|
* Before using this class, the Registry module must be initialized by calling {@link Registry.initialize}.
|
||||||
*/
|
*/
|
||||||
abstract class AbstractCard {
|
abstract class AbstractCard {
|
||||||
/**
|
/** The registry entry this card represents. */
|
||||||
* Entity to create the card for.
|
readonly entity: RegistryEntry;
|
||||||
*
|
|
||||||
* @type {generic.RegistryEntry}
|
|
||||||
*/
|
|
||||||
entity: generic.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 = {
|
configuration: EntityCardConfig = {
|
||||||
type: "custom:mushroom-entity-card",
|
type: 'custom:mushroom-entity-card',
|
||||||
icon: "mdi:help-circle",
|
icon: 'mdi:help-circle',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {generic.RegistryEntry} entity The hass entity to create a card for.
|
* @param {RegistryEntry} entity The registry entry to create a card configuration for.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
*
|
||||||
|
* @remarks
|
||||||
|
* Before this class can be used, the Registry module must be initialized by calling {@link Registry.initialize}.
|
||||||
*/
|
*/
|
||||||
protected constructor(entity: generic.RegistryEntry) {
|
protected constructor(entity: RegistryEntry) {
|
||||||
if (!Helper.isInitialized()) {
|
if (!Registry.initialized) {
|
||||||
throw new Error("The Helper module must be initialized before using this one.");
|
logMessage(lvlFatal, 'Registry not initialized!');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.entity = entity;
|
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 {
|
return {
|
||||||
...this.config,
|
...this.configuration,
|
||||||
entity: "entity_id" in this.entity ? this.entity.entity_id : undefined,
|
entity: 'entity_id' in this.entity ? this.entity.entity_id : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {AbstractCard};
|
export default AbstractCard;
|
||||||
|
@@ -1,68 +1,52 @@
|
|||||||
import {AbstractCard} from "./AbstractCard";
|
import { AreaRegistryEntry } from '../types/homeassistant/data/area_registry';
|
||||||
import {cards} from "../types/strategy/cards";
|
import { TemplateCardConfig } from '../types/lovelace-mushroom/cards/template-card-config';
|
||||||
import {AreaRegistryEntry} from "../types/homeassistant/data/area_registry";
|
import AbstractCard from './AbstractCard';
|
||||||
import {TemplateCardConfig} from "../types/lovelace-mushroom/cards/template-card-config";
|
|
||||||
|
|
||||||
// noinspection JSUnusedGlobalSymbols Class is dynamically imported.
|
|
||||||
/**
|
/**
|
||||||
* Area Card Class
|
* Area Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for an entity of the area domain.
|
* Used to create card configuration for an entry of the HASS area registry.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class AreaCard extends AbstractCard {
|
class AreaCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): TemplateCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {TemplateCardConfig}
|
type: 'custom:mushroom-template-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: TemplateCardConfig = {
|
|
||||||
type: "custom:mushroom-template-card",
|
|
||||||
primary: undefined,
|
primary: undefined,
|
||||||
icon: "mdi:floor-plan",
|
icon: 'mdi:floor-plan',
|
||||||
icon_color: "blue",
|
icon_color: 'blue',
|
||||||
tap_action: {
|
tap_action: { action: 'navigate', navigation_path: '' },
|
||||||
action: "navigate",
|
hold_action: { action: 'none' },
|
||||||
navigation_path: "",
|
|
||||||
},
|
|
||||||
hold_action: {
|
|
||||||
action: "none",
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {AreaRegistryEntry} area The area entity to create a card for.
|
* @param {AreaRegistryEntry} area The HASS area to create a card configuration for.
|
||||||
* @param {cards.TemplateCardOptions} [options={}] Options for the card.
|
* @param {TemplateCardConfig} [customConfiguration] Custom card configuration.
|
||||||
*
|
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(area: AreaRegistryEntry, options: cards.TemplateCardOptions = {}) {
|
constructor(area: AreaRegistryEntry, customConfiguration?: TemplateCardConfig) {
|
||||||
super(area);
|
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.
|
// Don't override the default card type if default is set in the strategy options.
|
||||||
if (options.type === "default") {
|
if (customConfig && customConfig.type === 'default') {
|
||||||
delete options.type;
|
customConfig = { ...customConfig, type: configuration.type };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the default configuration.
|
this.configuration = { ...this.configuration, ...configuration, ...customConfig };
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {AreaCard};
|
export default AreaCard;
|
||||||
|
@@ -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.
|
// 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
|
* Sensor Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the binary_sensor domain.
|
* Used to create a card configuration to control an entity of the binary_sensor domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends SensorCard
|
|
||||||
*/
|
*/
|
||||||
class BinarySensorCard extends SensorCard {
|
class BinarySensorCard extends SensorCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): EntityCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {EntityCardConfig}
|
type: 'custom:mushroom-entity-card',
|
||||||
* @private
|
icon: 'mdi:power-cycle',
|
||||||
*/
|
icon_color: 'green',
|
||||||
#defaultConfig: EntityCardConfig = {
|
|
||||||
type: "custom:mushroom-entity-card",
|
|
||||||
icon: "mdi:power-cycle",
|
|
||||||
icon_color: "green",
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.EntityCardOptions} [options={}] Options for the card.
|
* @param {EntityCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...BinarySensorCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {BinarySensorCard};
|
export default BinarySensorCard;
|
||||||
|
@@ -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.
|
// 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
|
* Camera Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the camera domain.
|
* Used to create a card configuration to control an entity of the camera domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class CameraCard extends AbstractCard {
|
class CameraCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): PictureEntityCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {PictureEntityCardConfig}
|
entity: '',
|
||||||
* @private
|
type: 'picture-entity',
|
||||||
*/
|
|
||||||
#defaultConfig: PictureEntityCardConfig = {
|
|
||||||
entity: "",
|
|
||||||
type: "picture-entity",
|
|
||||||
show_name: false,
|
show_name: false,
|
||||||
show_state: false,
|
show_state: false,
|
||||||
camera_view: "live",
|
camera_view: 'live',
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.PictureEntityCardOptions} [options={}] Options for the card.
|
* @param {PictureEntityCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.PictureEntityCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: PictureEntityCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...CameraCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {CameraCard};
|
export default CameraCard;
|
||||||
|
@@ -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.
|
// 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
|
* Climate Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the climate domain.
|
* Used to create a card configuration to control an entity of the climate domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class ClimateCard extends AbstractCard {
|
class ClimateCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): ClimateCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {ClimateCardConfig}
|
type: 'custom:mushroom-climate-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: ClimateCardConfig = {
|
|
||||||
type: "custom:mushroom-climate-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
hvac_modes: [
|
hvac_modes: ['off', 'cool', 'heat', 'fan_only'],
|
||||||
"off",
|
|
||||||
"cool",
|
|
||||||
"heat",
|
|
||||||
"fan_only",
|
|
||||||
],
|
|
||||||
show_temperature_control: true,
|
show_temperature_control: true,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.ClimateCardOptions} [options={}] Options for the card.
|
* @param {ClimateCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.ClimateCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: ClimateCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...ClimateCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {ClimateCard};
|
export default ClimateCard;
|
||||||
|
@@ -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.
|
// 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
|
* Cover Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the cover domain.
|
* Used to create a card configuration to control an entity of the cover domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class CoverCard extends AbstractCard {
|
class CoverCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): CoverCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {CoverCardConfig}
|
type: 'custom:mushroom-cover-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: CoverCardConfig = {
|
|
||||||
type: "custom:mushroom-cover-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
show_buttons_control: true,
|
show_buttons_control: true,
|
||||||
show_position_control: true,
|
show_position_control: true,
|
||||||
show_tilt_position_control: true,
|
show_tilt_position_control: true,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.CoverCardOptions} [options={}] Options for the card.
|
* @param {CoverCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.CoverCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: CoverCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...CoverCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {CoverCard};
|
export default CoverCard;
|
||||||
|
@@ -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.
|
// 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
|
* Fan Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the fan domain.
|
* Used to create a card configuration to control an entity of the fan domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class FanCard extends AbstractCard {
|
class FanCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): FanCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {FanCardConfig}
|
type: 'custom:mushroom-fan-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: FanCardConfig = {
|
|
||||||
type: "custom:mushroom-fan-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
show_percentage_control: true,
|
show_percentage_control: true,
|
||||||
show_oscillate_control: true,
|
show_oscillate_control: true,
|
||||||
icon_animation: true,
|
icon_animation: true,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.FanCardOptions} [options={}] Options for the card.
|
* @param {FanCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.FanCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: FanCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...FanCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {FanCard};
|
export default FanCard;
|
||||||
|
@@ -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.
|
// 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
|
* HA Area Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for an entity of the area domain using the built-in type 'area'.
|
* Used to create card configuration for an entry of the HASS area registry.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class AreaCard extends AbstractCard {
|
class AreaCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): AreaCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {AreaCardConfig}
|
type: 'area',
|
||||||
* @private
|
area: '',
|
||||||
*/
|
|
||||||
#defaultConfig: AreaCardConfig = {
|
|
||||||
type: "area",
|
|
||||||
area: "",
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {AreaRegistryEntry} area The area entity to create a card for.
|
* @param {AreaRegistryEntry} area The HASS entity to create a card configuration for.
|
||||||
* @param {cards.AreaCardOptions} [options={}] Options for the card.
|
* @param {AreaCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
|
constructor(area: AreaRegistryEntry, customConfiguration?: AreaCardConfig) {
|
||||||
constructor(area: AreaRegistryEntry, options: cards.AreaCardOptions = {}) {
|
|
||||||
super(area);
|
super(area);
|
||||||
|
|
||||||
// Initialize the default configuration.
|
// Initialize the default configuration.
|
||||||
this.#defaultConfig.area = area.area_id;
|
const configuration = AreaCard.getDefaultConfig();
|
||||||
this.#defaultConfig.navigation_path = this.#defaultConfig.area;
|
|
||||||
|
|
||||||
// Enforce the card type.
|
configuration.area = area.area_id;
|
||||||
delete options.type;
|
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;
|
||||||
|
@@ -1,41 +1,34 @@
|
|||||||
import {cards} from "../types/strategy/cards";
|
// 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 { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||||
import {SelectCard} from './SelectCard';
|
import { SelectCardConfig } from '../types/lovelace-mushroom/cards/select-card-config';
|
||||||
|
import SelectCard from './SelectCard';
|
||||||
|
|
||||||
// noinspection JSUnusedGlobalSymbols Class is dynamically imported
|
|
||||||
/**
|
/**
|
||||||
* InputSelect Card Class
|
* InputSelect Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the input_select domain.
|
* Used to create a card configuration to control an entity of the input_select domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class InputSelectCard extends SelectCard {
|
class InputSelectCard extends SelectCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): SelectCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {SelectCardConfig}
|
type: 'custom:mushroom-select-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: SelectCardConfig = {
|
|
||||||
type: "custom:mushroom-select-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.InputSelectCardOptions} [options={}] Options for the card.
|
* @param {SelectCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.InputSelectCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: SelectCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...InputSelectCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {InputSelectCard};
|
export default InputSelectCard;
|
||||||
|
@@ -1,38 +1,28 @@
|
|||||||
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.
|
// 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
|
* Light Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the light domain.
|
* Used to create a card configuration to control an entity of the light domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class LightCard extends AbstractCard {
|
class LightCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): LightCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {LightCardConfig}
|
type: 'custom:mushroom-light-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: LightCardConfig = {
|
|
||||||
type: "custom:mushroom-light-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
show_brightness_control: true,
|
show_brightness_control: true,
|
||||||
show_color_control: true,
|
show_color_control: true,
|
||||||
show_color_temp_control: true,
|
show_color_temp_control: true,
|
||||||
use_light_color: true,
|
use_light_color: true,
|
||||||
double_tap_action: {
|
double_tap_action: {
|
||||||
action: "call-service",
|
action: 'call-service',
|
||||||
service: "light.turn_on",
|
perform_action: 'light.turn_on',
|
||||||
target: {
|
target: {
|
||||||
entity_id: undefined,
|
entity_id: undefined,
|
||||||
},
|
},
|
||||||
@@ -41,27 +31,28 @@ class LightCard extends AbstractCard {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.LightCardOptions} [options={}] Options for the card.
|
* @param {LightCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.LightCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: LightCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
// Set the target for double-tap action.
|
const configuration = LightCard.getDefaultConfig();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isCallServiceActionConfig(this.#defaultConfig.double_tap_action)
|
isCallServiceActionConfig(configuration.double_tap_action) &&
|
||||||
&& isCallServiceActionTarget(this.#defaultConfig.double_tap_action.target)
|
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;
|
||||||
|
@@ -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.
|
// 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
|
* Lock Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the lock domain.
|
* Used to create a card configuration to control an entity of the lock domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class LockCard extends AbstractCard {
|
class LockCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): LockCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {LockCardConfig}
|
type: 'custom:mushroom-lock-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: LockCardConfig = {
|
|
||||||
type: "custom:mushroom-lock-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.LockCardOptions} [options={}] Options for the card.
|
* @param {LockCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.LockCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: LockCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...LockCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {LockCard};
|
export default LockCard;
|
||||||
|
@@ -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.
|
// 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
|
* Mediaplayer Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the media_player domain.
|
* Used to create a card configuration to control an entity of the media_player domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class MediaPlayerCard extends AbstractCard {
|
class MediaPlayerCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): MediaPlayerCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {MediaPlayerCardConfig}
|
type: 'custom:mushroom-media-player-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: MediaPlayerCardConfig = {
|
|
||||||
type: "custom:mushroom-media-player-card",
|
|
||||||
use_media_info: true,
|
use_media_info: true,
|
||||||
media_controls: [
|
media_controls: ['on_off', 'play_pause_stop'],
|
||||||
"on_off",
|
|
||||||
"play_pause_stop",
|
|
||||||
],
|
|
||||||
show_volume_level: true,
|
show_volume_level: true,
|
||||||
volume_controls: [
|
volume_controls: ['volume_mute', 'volume_set', 'volume_buttons'],
|
||||||
"volume_mute",
|
|
||||||
"volume_set",
|
|
||||||
"volume_buttons",
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.MediaPlayerCardOptions} [options={}] Options for the card.
|
* @param {MediaPlayerCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.MediaPlayerCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: MediaPlayerCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...MediaPlayerCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {MediaPlayerCard};
|
export default MediaPlayerCard;
|
||||||
|
@@ -1,40 +1,32 @@
|
|||||||
import {AbstractCard} from "./AbstractCard";
|
import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||||
import {cards} from "../types/strategy/cards";
|
import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config';
|
||||||
import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry";
|
import AbstractCard from './AbstractCard';
|
||||||
import {EntityCardConfig} from "../types/lovelace-mushroom/cards/entity-card-config";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Miscellaneous Card Class
|
* Miscellaneous Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card an entity of any domain.
|
* Used to create a card configuration to control an entity of any domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class MiscellaneousCard extends AbstractCard {
|
class MiscellaneousCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): EntityCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {EntityCardConfig}
|
type: 'custom:mushroom-entity-card',
|
||||||
* @private
|
icon_color: 'blue-grey',
|
||||||
*/
|
|
||||||
#defaultConfig: EntityCardConfig = {
|
|
||||||
type: "custom:mushroom-entity-card",
|
|
||||||
icon_color: "blue-grey",
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.EntityCardOptions} [options={}] Options for the card.
|
* @param {EntityCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...MiscellaneousCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {MiscellaneousCard};
|
export default MiscellaneousCard;
|
||||||
|
@@ -1,41 +1,34 @@
|
|||||||
import {AbstractCard} from "./AbstractCard";
|
// noinspection JSUnusedGlobalSymbols Class is dynamically imported.
|
||||||
import {cards} from "../types/strategy/cards";
|
|
||||||
import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry";
|
import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||||
import {NumberCardConfig} from "../types/lovelace-mushroom/cards/number-card-config";
|
import { NumberCardConfig } from '../types/lovelace-mushroom/cards/number-card-config';
|
||||||
|
import AbstractCard from './AbstractCard';
|
||||||
|
|
||||||
// noinspection JSUnusedGlobalSymbols Class is dynamically imported
|
|
||||||
/**
|
/**
|
||||||
* Number Card Class
|
* Number Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the number domain.
|
* Used to create a card configuration to control an entity of the number domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class NumberCard extends AbstractCard {
|
class NumberCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): NumberCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {NumberCardConfig}
|
type: 'custom:mushroom-number-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: NumberCardConfig = {
|
|
||||||
type: "custom:mushroom-number-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.NumberCardOptions} [options={}] Options for the card.
|
* @param {NumberCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.NumberCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: NumberCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...NumberCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {NumberCard};
|
export default NumberCard;
|
||||||
|
@@ -1,43 +1,35 @@
|
|||||||
import {AbstractCard} from "./AbstractCard";
|
import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||||
import {cards} from "../types/strategy/cards";
|
import { PersonCardConfig } from '../types/lovelace-mushroom/cards/person-card-config';
|
||||||
import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry";
|
import AbstractCard from './AbstractCard';
|
||||||
import {PersonCardConfig} from "../types/lovelace-mushroom/cards/person-card-config";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Person Card Class
|
* Person Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for an entity of the Person domain.
|
* Used to create a card configuration to control an entity of the person domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class PersonCard extends AbstractCard {
|
class PersonCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): PersonCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {PersonCardConfig}
|
type: 'custom:mushroom-person-card',
|
||||||
* @private
|
layout: 'vertical',
|
||||||
*/
|
primary_info: 'none',
|
||||||
#defaultConfig: PersonCardConfig = {
|
secondary_info: 'none',
|
||||||
type: "custom:mushroom-person-card",
|
icon_type: 'entity-picture',
|
||||||
layout: "vertical",
|
|
||||||
primary_info: "none",
|
|
||||||
secondary_info: "none",
|
|
||||||
icon_type: "entity-picture",
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.PersonCardOptions} [options={}] Options for the card.
|
* @param {PersonCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.PersonCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: PersonCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...PersonCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {PersonCard};
|
export default PersonCard;
|
||||||
|
@@ -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.
|
// 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
|
* Scene Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for an entity of the scene domain.
|
* Used to create a card configuration to control an entity of the scene domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class SceneCard extends AbstractCard {
|
class SceneCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): EntityCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {EntityCardConfig}
|
type: 'custom:mushroom-entity-card',
|
||||||
* @private
|
icon: 'mdi:palette',
|
||||||
*/
|
icon_color: 'blue',
|
||||||
#defaultConfig: EntityCardConfig = {
|
|
||||||
type: "custom:mushroom-entity-card",
|
|
||||||
icon: "mdi:palette",
|
|
||||||
icon_color: "blue",
|
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: 'call-service',
|
||||||
service: "scene.turn_on",
|
perform_action: 'scene.turn_on',
|
||||||
target: {
|
target: {
|
||||||
entity_id: undefined,
|
entity_id: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.EntityCardOptions} [options={}] Options for the card.
|
* @param {EntityCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
// Set the target for tap action.
|
const configuration = SceneCard.getDefaultConfig();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isCallServiceActionConfig(this.#defaultConfig.tap_action)
|
isCallServiceActionConfig(configuration.tap_action) &&
|
||||||
&& isCallServiceActionTarget(this.#defaultConfig.tap_action.target)
|
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.configuration = { ...this.configuration, ...configuration, ...customConfiguration };
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {SceneCard};
|
export default SceneCard;
|
||||||
|
@@ -1,41 +1,34 @@
|
|||||||
import {AbstractCard} from "./AbstractCard";
|
// noinspection JSUnusedGlobalSymbols Class is dynamically imported.
|
||||||
import {cards} from "../types/strategy/cards";
|
|
||||||
import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry";
|
import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||||
import {SelectCardConfig} from "../types/lovelace-mushroom/cards/select-card-config";
|
import { SelectCardConfig } from '../types/lovelace-mushroom/cards/select-card-config';
|
||||||
|
import AbstractCard from './AbstractCard';
|
||||||
|
|
||||||
// noinspection JSUnusedGlobalSymbols Class is dynamically imported
|
|
||||||
/**
|
/**
|
||||||
* Select Card Class
|
* Select Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the select domain.
|
* Used to create a card configuration to control an entity of the select domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class SelectCard extends AbstractCard {
|
class SelectCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): SelectCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {SelectCardConfig}
|
type: 'custom:mushroom-select-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: SelectCardConfig = {
|
|
||||||
type: "custom:mushroom-select-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.SelectCardOptions} [options={}] Options for the card.
|
* @param {SelectCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.SelectCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: SelectCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...SelectCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {SelectCard};
|
export default SelectCard;
|
||||||
|
@@ -1,42 +1,34 @@
|
|||||||
import {AbstractCard} from "./AbstractCard";
|
import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||||
import {cards} from "../types/strategy/cards";
|
import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config';
|
||||||
import {EntityRegistryEntry} from "../types/homeassistant/data/entity_registry";
|
import AbstractCard from './AbstractCard';
|
||||||
import {EntityCardConfig} from "../types/lovelace-mushroom/cards/entity-card-config";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sensor Card Class
|
* Sensor Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the sensor domain.
|
* Used to create a card for controlling an entity of the sensor domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class SensorCard extends AbstractCard {
|
class SensorCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): EntityCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {EntityCardConfig}
|
type: 'custom:mushroom-entity-card',
|
||||||
* @private
|
icon: 'mdi:information',
|
||||||
*/
|
|
||||||
#defaultConfig: EntityCardConfig = {
|
|
||||||
type: "custom:mushroom-entity-card",
|
|
||||||
icon: "mdi:information",
|
|
||||||
animate: true,
|
animate: true,
|
||||||
line_color: "green",
|
line_color: 'green',
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.EntityCardOptions} [options={}] Options for the card.
|
* @param {EntityCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...SensorCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {SensorCard};
|
export default SensorCard;
|
||||||
|
@@ -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.
|
// 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
|
* Switch Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the switch domain.
|
* Used to create a card configuration to control an entity of the switch domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class SwitchCard extends AbstractCard {
|
class SwitchCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): EntityCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {EntityCardConfig}
|
type: 'custom:mushroom-entity-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: EntityCardConfig = {
|
|
||||||
type: "custom:mushroom-entity-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "toggle",
|
action: 'toggle',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.EntityCardOptions} [options={}] Options for the card.
|
* @param {EntityCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.EntityCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...SwitchCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {SwitchCard};
|
export default SwitchCard;
|
||||||
|
@@ -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.
|
// 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
|
* Vacuum Card Class
|
||||||
*
|
*
|
||||||
* Used to create a card for controlling an entity of the vacuum domain.
|
* Used to create a card configuration to control an entity of the vacuum domain.
|
||||||
*
|
|
||||||
* @class
|
|
||||||
* @extends AbstractCard
|
|
||||||
*/
|
*/
|
||||||
class VacuumCard extends AbstractCard {
|
class VacuumCard extends AbstractCard {
|
||||||
/**
|
/** Returns the default configuration object for the card. */
|
||||||
* Default configuration of the card.
|
static getDefaultConfig(): VacuumCardConfig {
|
||||||
*
|
return {
|
||||||
* @type {VacuumCardConfig}
|
type: 'custom:mushroom-vacuum-card',
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
#defaultConfig: VacuumCardConfig = {
|
|
||||||
type: "custom:mushroom-vacuum-card",
|
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
icon_animation: true,
|
icon_animation: true,
|
||||||
commands: [...VACUUM_COMMANDS],
|
commands: [...VACUUM_COMMANDS],
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "more-info",
|
action: 'more-info',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*
|
*
|
||||||
* @param {EntityRegistryEntry} entity The hass entity to create a card for.
|
* @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for.
|
||||||
* @param {cards.VacuumCardOptions} [options={}] Options for the card.
|
* @param {VacuumCardConfig} [customConfiguration] Custom card configuration.
|
||||||
* @throws {Error} If the Helper module isn't initialized.
|
|
||||||
*/
|
*/
|
||||||
constructor(entity: EntityRegistryEntry, options: cards.VacuumCardOptions = {}) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: VacuumCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
this.config = Object.assign(this.config, this.#defaultConfig, options);
|
this.configuration = { ...this.configuration, ...VacuumCard.getDefaultConfig(), ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {VacuumCard};
|
export default VacuumCard;
|
||||||
|
Reference in New Issue
Block a user