mirror of
https://github.com/DigiLive/mushroom-strategy.git
synced 2025-08-04 20:14:28 +02:00
Add support for Stateful scenes
Add changing the icon color of the Scene Card depending on the related stateful scene entity, if available. The default color will now be `disabled`. Closes #190
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { Registry } from '../Registry';
|
||||
import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||
import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config';
|
||||
import { TemplateCardConfig } from '../types/lovelace-mushroom/cards/template-card-config';
|
||||
import { isCallServiceActionConfig, isCallServiceActionTarget } from '../types/strategy/strategy-generics';
|
||||
import AbstractCard from './AbstractCard';
|
||||
|
||||
@@ -13,11 +14,11 @@ import AbstractCard from './AbstractCard';
|
||||
*/
|
||||
class SceneCard extends AbstractCard {
|
||||
/** Returns the default configuration object for the card. */
|
||||
static getDefaultConfig(): EntityCardConfig {
|
||||
static getDefaultConfig(): TemplateCardConfig {
|
||||
return {
|
||||
type: 'custom:mushroom-entity-card',
|
||||
type: 'custom:mushroom-template-card',
|
||||
icon: 'mdi:palette',
|
||||
icon_color: 'blue',
|
||||
icon_color: 'disabled',
|
||||
tap_action: {
|
||||
action: 'call-service',
|
||||
perform_action: 'scene.turn_on',
|
||||
@@ -37,8 +38,12 @@ class SceneCard extends AbstractCard {
|
||||
constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) {
|
||||
super(entity);
|
||||
|
||||
const sceneName = entity.entity_id.split('.').pop();
|
||||
const configuration = SceneCard.getDefaultConfig();
|
||||
|
||||
// Initialize the default configuration.
|
||||
configuration.primary = entity.name ?? entity.original_name ?? '?';
|
||||
|
||||
if (
|
||||
isCallServiceActionConfig(configuration.tap_action) &&
|
||||
isCallServiceActionTarget(configuration.tap_action.target)
|
||||
@@ -47,6 +52,16 @@ class SceneCard extends AbstractCard {
|
||||
}
|
||||
configuration.icon = Registry.hassStates[entity.entity_id]?.attributes.icon ?? configuration.icon;
|
||||
|
||||
// Stateful Scenes support. (https://github.com/hugobloem/stateful_scenes)
|
||||
configuration.icon_color = `
|
||||
{% set state = states('switch.${sceneName}_stateful_scene') %}
|
||||
{% if state == 'on' %}
|
||||
blue
|
||||
{% else %}
|
||||
disabled
|
||||
{% endif %}
|
||||
`;
|
||||
|
||||
this.configuration = { ...this.configuration, ...configuration, ...customConfiguration };
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user