mirror of
https://github.com/DigiLive/mushroom-strategy.git
synced 2025-08-04 20:14:28 +02:00
Refactor type guard of service action configurations
Key `action` is extended with `perform-action` for future use. Key `service` is deprecated and replaced by `perform_action`.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||
import { LightCardConfig } from '../types/lovelace-mushroom/cards/light-card-config';
|
||||
import { isCallServiceActionConfig, isCallServiceActionTarget } from '../types/strategy/strategy-generics';
|
||||
import { isCallServiceActionConfig } from '../types/strategy/strategy-generics';
|
||||
import AbstractCard from './AbstractCard';
|
||||
|
||||
/**
|
||||
@@ -44,11 +44,8 @@ class LightCard extends AbstractCard {
|
||||
|
||||
const configuration = LightCard.getDefaultConfig();
|
||||
|
||||
if (
|
||||
isCallServiceActionConfig(configuration.double_tap_action) &&
|
||||
isCallServiceActionTarget(configuration.double_tap_action.target)
|
||||
) {
|
||||
configuration.double_tap_action.target.entity_id = entity.entity_id;
|
||||
if (isCallServiceActionConfig(configuration.double_tap_action)) {
|
||||
configuration.double_tap_action.target = { entity_id: entity.entity_id };
|
||||
}
|
||||
|
||||
this.configuration = { ...this.configuration, ...configuration, ...customConfiguration };
|
||||
|
@@ -297,7 +297,9 @@ export function isSortable(object: object): object is Sortable {
|
||||
* @returns {boolean} - True if the object represents a valid service action configuration.
|
||||
*/
|
||||
export function isCallServiceActionConfig(object?: ActionConfig): object is CallServiceActionConfig {
|
||||
return !!object && object.action === 'call-service' && ['action', 'service'].every((key) => key in object);
|
||||
return (
|
||||
!!object && (object.action === 'perform-action' || object.action === 'call-service') && 'perform_action' in object
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user