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 { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry';
|
||||||
import { LightCardConfig } from '../types/lovelace-mushroom/cards/light-card-config';
|
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';
|
import AbstractCard from './AbstractCard';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,11 +44,8 @@ class LightCard extends AbstractCard {
|
|||||||
|
|
||||||
const configuration = LightCard.getDefaultConfig();
|
const configuration = LightCard.getDefaultConfig();
|
||||||
|
|
||||||
if (
|
if (isCallServiceActionConfig(configuration.double_tap_action)) {
|
||||||
isCallServiceActionConfig(configuration.double_tap_action) &&
|
configuration.double_tap_action.target = { entity_id: entity.entity_id };
|
||||||
isCallServiceActionTarget(configuration.double_tap_action.target)
|
|
||||||
) {
|
|
||||||
configuration.double_tap_action.target.entity_id = entity.entity_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.configuration = { ...this.configuration, ...configuration, ...customConfiguration };
|
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.
|
* @returns {boolean} - True if the object represents a valid service action configuration.
|
||||||
*/
|
*/
|
||||||
export function isCallServiceActionConfig(object?: ActionConfig): object is CallServiceActionConfig {
|
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