mirror of
https://github.com/DigiLive/mushroom-strategy.git
synced 2025-08-03 19:44:27 +02:00
Fix target override of chip tap action
As an addition to the fix for issue #177. Although the fix for #177 targets the entities, they were still overridden by `setTapActionTarget()` after instantiation of the chip. This statement is now removed. Removing the statement, makes `setTapActionTarget()` and typeguards obsolete, so they are removed also.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { HassServiceTarget } from 'home-assistant-js-websocket';
|
||||
import { Registry } from '../Registry';
|
||||
import { LovelaceChipConfig } from '../types/lovelace-mushroom/utils/lovelace/chip/types';
|
||||
import { isCallServiceActionConfig, isTargetableChip } from '../types/strategy/strategy-generics';
|
||||
import { logMessage, lvlFatal, lvlWarn } from '../utilities/debug';
|
||||
import { logMessage, lvlFatal } from '../utilities/debug';
|
||||
|
||||
abstract class AbstractChip {
|
||||
/**
|
||||
@@ -45,21 +43,6 @@ abstract class AbstractChip {
|
||||
getChipConfiguration(): LovelaceChipConfig {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target for the tap action.
|
||||
*
|
||||
* @param {HassServiceTarget} target Target of the tap action.
|
||||
*/
|
||||
setTapActionTarget(target: HassServiceTarget) {
|
||||
if (isTargetableChip(this.configuration) && isCallServiceActionConfig(this.configuration.tap_action)) {
|
||||
this.configuration.tap_action.target = target;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
logMessage(lvlWarn, 'Target not set: Invalid target or tap action.');
|
||||
}
|
||||
}
|
||||
|
||||
export default AbstractChip;
|
||||
|
@@ -306,28 +306,6 @@ export function isCallServiceActionConfig(object?: ActionConfig): object is Call
|
||||
!!object && (object.action === 'perform-action' || object.action === 'call-service') && 'perform_action' in object
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List of chip types that are not considered "targetable".
|
||||
* These chips do not support tap_action or similar targeting logic.
|
||||
*/
|
||||
const NON_TARGETABLE_CHIP_TYPES = ['back', 'menu', 'conditional', 'spacer'] as const;
|
||||
|
||||
/**
|
||||
* Type guard to check if a LovelaceChipConfig is "targetable".
|
||||
*
|
||||
* A targetable chip supports actions like tap_action.
|
||||
* This function excludes chips of type "back", "menu", "conditional", and "spacer".
|
||||
*
|
||||
* @param object - The chip configuration object to check.
|
||||
* @returns True if the chip is targetable; false otherwise.
|
||||
*/
|
||||
export function isTargetableChip(
|
||||
object: LovelaceChipConfig,
|
||||
): object is Exclude<LovelaceChipConfig, BackChipConfig | MenuChipConfig | ConditionalChipConfig | SpacerChipConfig> {
|
||||
return !NON_TARGETABLE_CHIP_TYPES.includes(object.type as (typeof NON_TARGETABLE_CHIP_TYPES)[number]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if a given identifier exists in a list of supported identifiers.
|
||||
*
|
||||
|
@@ -130,7 +130,6 @@ class HomeView extends AbstractView {
|
||||
|
||||
const chipConfigurations: LovelaceChipConfig[] = [];
|
||||
const exposedChips = Registry.getExposedNames('chip');
|
||||
const areaIds = Registry.areas.map((area) => area.area_id ?? '');
|
||||
|
||||
let Chip;
|
||||
|
||||
@@ -164,7 +163,6 @@ class HomeView extends AbstractView {
|
||||
Chip = (await import(`../chips/${moduleName}`)).default;
|
||||
const currentChip = new Chip();
|
||||
|
||||
currentChip.setTapActionTarget({ area_id: areaIds });
|
||||
chipConfigurations.push(currentChip.getChipConfiguration());
|
||||
} catch (e) {
|
||||
logMessage(lvlError, `Error creating the configuration for chip ${chipName}!`, e);
|
||||
|
Reference in New Issue
Block a user