forked from DigiLive/mushroom-strategy
Adds: - Strategy: - SceneCard: Support for Stateful scenes. Closes #190. - ValveCard: A card to control an entity of the valve domain. Closes #192. - LockView: A view for entities of the lock domain. Closes #171. - Modules: - RegistryFilter: Advanced filtering and sorting of Home Assistant registries. - Auxiliaries: Generic utility functions. - Debug: Centralized logging and debug level management. - Tooling: - ESLint configuration for linting. - Prettier configuration for code formatting. Removes: - Redundant types and interface annotations. - Redundant legacy and unused modules. - Localization constant from the `Helper` module in favor of a new `localize` utility. Refactors: - References regarding change of repository owner. - Auxiliary functions are moved from the `Helper` module to `Auxiliaries` module. - `Helper` module is renamed to `Registry` for centralized state and registry management. - `ControllerCard` is renamed to `HeaderCard`. - Doc-blocks and comments are updated for clarity and consistency. - The file tree is restructured for improved clarity, modularity, and scalability. - Third party type definitions are updated and cleaned up. - Issue and Pull Request templates. Optimizations: - Parallelization of dynamic imports for views and cards. - Improved error handling and logging throughout the codebase. - Sanitization of HASS registries after import. - Enforced stricter and simplified types and interfaces. - Localization now available at global scope. Fixes: - Wrong type in configuration of `HeaderCard`. - Translation files: Resolved key inconsistencies. - Removed unnecessary namespaces from types. - Typos and Grammar. - Explicit use of `any` types. - Turn off all entities of a domain with a chip tap action. - Rendering too small HASS area cards. - Count of active vacuums. Bumps: - Mushroom Strategy - home-assistant-js-websocket - superstruct - ts-loader - ts-node - typescript - webpack - webpack-cli
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
// noinspection JSUnusedGlobalSymbols Class is dynamically imported.
|
|
|
|
import { Registry } from '../Registry';
|
|
import { TemplateChipConfig } from '../types/lovelace-mushroom/utils/lovelace/chip/types';
|
|
import AbstractChip from './AbstractChip';
|
|
import RegistryFilter from '../utilities/RegistryFilter';
|
|
|
|
/**
|
|
* Light Chip class.
|
|
*
|
|
* Used to create a chip configuration to indicate how many lights are on and to switch them all off.
|
|
*/
|
|
class LightChip extends AbstractChip {
|
|
/** Returns the default configuration object for the chip. */
|
|
static getDefaultConfig(): TemplateChipConfig {
|
|
return {
|
|
type: 'template',
|
|
icon: 'mdi:lightbulb-group',
|
|
icon_color: 'amber',
|
|
content: Registry.getCountTemplate('light', 'eq', 'on'),
|
|
tap_action: {
|
|
action: 'perform-action',
|
|
perform_action: 'light.turn_off',
|
|
target: {
|
|
entity_id: new RegistryFilter(Registry.entities)
|
|
.whereDomain('light')
|
|
.getValuesByProperty('entity_id') as string[],
|
|
},
|
|
},
|
|
hold_action: {
|
|
action: 'navigate',
|
|
navigation_path: 'lights',
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Class Constructor.
|
|
*
|
|
* @param {TemplateChipConfig} [customConfiguration] Custom chip configuration.
|
|
*/
|
|
constructor(customConfiguration?: TemplateChipConfig) {
|
|
super();
|
|
|
|
this.configuration = { ...this.configuration, ...LightChip.getDefaultConfig(), ...customConfiguration };
|
|
}
|
|
}
|
|
|
|
export default LightChip;
|