mirror of
https://github.com/DigiLive/mushroom-strategy.git
synced 2025-09-26 13:10:54 +02:00
Add confirmation to Switch chip tap action
This prevents accidental actions by requiring user confirmation before turning off switches.
This commit is contained in:
@@ -4,6 +4,7 @@ import { Registry } from '../Registry';
|
|||||||
import { TemplateChipConfig } from '../types/lovelace-mushroom/utils/lovelace/chip/types';
|
import { TemplateChipConfig } from '../types/lovelace-mushroom/utils/lovelace/chip/types';
|
||||||
import AbstractChip from './AbstractChip';
|
import AbstractChip from './AbstractChip';
|
||||||
import RegistryFilter from '../utilities/RegistryFilter';
|
import RegistryFilter from '../utilities/RegistryFilter';
|
||||||
|
import { localize } from '../utilities/localize';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch Chip class.
|
* Switch Chip class.
|
||||||
@@ -11,6 +12,17 @@ import RegistryFilter from '../utilities/RegistryFilter';
|
|||||||
* Used to create a chip configuration to indicate how many switches are on and to switch them all off.
|
* Used to create a chip configuration to indicate how many switches are on and to switch them all off.
|
||||||
*/
|
*/
|
||||||
class SwitchChip extends AbstractChip {
|
class SwitchChip extends AbstractChip {
|
||||||
|
/**
|
||||||
|
* Class Constructor.
|
||||||
|
*
|
||||||
|
* @param {TemplateChipConfig} [customConfiguration] Custom chip configuration.
|
||||||
|
*/
|
||||||
|
constructor(customConfiguration?: TemplateChipConfig) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.configuration = { ...this.configuration, ...SwitchChip.getDefaultConfig(), ...customConfiguration };
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the default configuration object for the chip. */
|
/** Returns the default configuration object for the chip. */
|
||||||
static getDefaultConfig(): TemplateChipConfig {
|
static getDefaultConfig(): TemplateChipConfig {
|
||||||
return {
|
return {
|
||||||
@@ -20,6 +32,9 @@ class SwitchChip extends AbstractChip {
|
|||||||
content: Registry.getCountTemplate('switch', 'eq', 'on'),
|
content: Registry.getCountTemplate('switch', 'eq', 'on'),
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: 'perform-action',
|
action: 'perform-action',
|
||||||
|
confirmation: {
|
||||||
|
text: localize('switch.chip_confirmation'),
|
||||||
|
},
|
||||||
perform_action: 'switch.turn_off',
|
perform_action: 'switch.turn_off',
|
||||||
target: {
|
target: {
|
||||||
entity_id: new RegistryFilter(Registry.entities)
|
entity_id: new RegistryFilter(Registry.entities)
|
||||||
@@ -33,17 +48,6 @@ class SwitchChip extends AbstractChip {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Constructor.
|
|
||||||
*
|
|
||||||
* @param {TemplateChipConfig} [customConfiguration] Custom chip configuration.
|
|
||||||
*/
|
|
||||||
constructor(customConfiguration?: TemplateChipConfig) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.configuration = { ...this.configuration, ...SwitchChip.getDefaultConfig(), ...customConfiguration };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SwitchChip;
|
export default SwitchChip;
|
||||||
|
Reference in New Issue
Block a user