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 { Registry } from '../Registry';
|
||||||
import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||||
import { EntityCardConfig } from '../types/lovelace-mushroom/cards/entity-card-config';
|
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 { isCallServiceActionConfig, isCallServiceActionTarget } from '../types/strategy/strategy-generics';
|
||||||
import AbstractCard from './AbstractCard';
|
import AbstractCard from './AbstractCard';
|
||||||
|
|
||||||
@@ -13,11 +14,11 @@ import AbstractCard from './AbstractCard';
|
|||||||
*/
|
*/
|
||||||
class SceneCard extends AbstractCard {
|
class SceneCard extends AbstractCard {
|
||||||
/** Returns the default configuration object for the card. */
|
/** Returns the default configuration object for the card. */
|
||||||
static getDefaultConfig(): EntityCardConfig {
|
static getDefaultConfig(): TemplateCardConfig {
|
||||||
return {
|
return {
|
||||||
type: 'custom:mushroom-entity-card',
|
type: 'custom:mushroom-template-card',
|
||||||
icon: 'mdi:palette',
|
icon: 'mdi:palette',
|
||||||
icon_color: 'blue',
|
icon_color: 'disabled',
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: 'call-service',
|
action: 'call-service',
|
||||||
perform_action: 'scene.turn_on',
|
perform_action: 'scene.turn_on',
|
||||||
@@ -37,8 +38,12 @@ class SceneCard extends AbstractCard {
|
|||||||
constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) {
|
constructor(entity: EntityRegistryEntry, customConfiguration?: EntityCardConfig) {
|
||||||
super(entity);
|
super(entity);
|
||||||
|
|
||||||
|
const sceneName = entity.entity_id.split('.').pop();
|
||||||
const configuration = SceneCard.getDefaultConfig();
|
const configuration = SceneCard.getDefaultConfig();
|
||||||
|
|
||||||
|
// Initialize the default configuration.
|
||||||
|
configuration.primary = entity.name ?? entity.original_name ?? '?';
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isCallServiceActionConfig(configuration.tap_action) &&
|
isCallServiceActionConfig(configuration.tap_action) &&
|
||||||
isCallServiceActionTarget(configuration.tap_action.target)
|
isCallServiceActionTarget(configuration.tap_action.target)
|
||||||
@@ -47,6 +52,16 @@ class SceneCard extends AbstractCard {
|
|||||||
}
|
}
|
||||||
configuration.icon = Registry.hassStates[entity.entity_id]?.attributes.icon ?? configuration.icon;
|
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 };
|
this.configuration = { ...this.configuration, ...configuration, ...customConfiguration };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user