Files
mushroom-strategy/src/cards/AreaCard.ts
T
Ferry Cools a5ec18823d Release v2.3.0 (#195)
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
2025-05-13 07:01:26 +02:00

53 lines
1.7 KiB
TypeScript

import { AreaRegistryEntry } from '../types/homeassistant/data/area_registry';
import { TemplateCardConfig } from '../types/lovelace-mushroom/cards/template-card-config';
import AbstractCard from './AbstractCard';
/**
* Area Card Class
*
* 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.
*
* @param {AreaRegistryEntry} area The HASS area to create a card configuration for.
* @param {TemplateCardConfig} [customConfiguration] Custom card configuration.
*/
constructor(area: AreaRegistryEntry, customConfiguration?: TemplateCardConfig) {
super(area);
const configuration = AreaCard.getDefaultConfig();
let customConfig = customConfiguration;
configuration.primary = area.name;
configuration.icon = area.icon || configuration.icon;
if (configuration.tap_action && 'navigation_path' in configuration.tap_action) {
configuration.tap_action.navigation_path = area.area_id;
}
// Don't override the default card type if default is set in the strategy options.
if (customConfig && customConfig.type === 'default') {
customConfig = { ...customConfig, type: configuration.type };
}
this.configuration = { ...this.configuration, ...configuration, ...customConfig };
}
}
export default AreaCard;