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:
DigiLive
2025-05-02 07:26:51 +02:00
parent 1558bf6843
commit e6c2a76b96
3 changed files with 1 additions and 42 deletions

View File

@@ -1,8 +1,6 @@
import { HassServiceTarget } from 'home-assistant-js-websocket';
import { Registry } from '../Registry'; import { Registry } from '../Registry';
import { LovelaceChipConfig } from '../types/lovelace-mushroom/utils/lovelace/chip/types'; import { LovelaceChipConfig } from '../types/lovelace-mushroom/utils/lovelace/chip/types';
import { isCallServiceActionConfig, isTargetableChip } from '../types/strategy/strategy-generics'; import { logMessage, lvlFatal } from '../utilities/debug';
import { logMessage, lvlFatal, lvlWarn } from '../utilities/debug';
abstract class AbstractChip { abstract class AbstractChip {
/** /**
@@ -45,21 +43,6 @@ abstract class AbstractChip {
getChipConfiguration(): LovelaceChipConfig { getChipConfiguration(): LovelaceChipConfig {
return this.configuration; 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; export default AbstractChip;

View File

@@ -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 !!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. * Type guard to check if a given identifier exists in a list of supported identifiers.
* *

View File

@@ -130,7 +130,6 @@ class HomeView extends AbstractView {
const chipConfigurations: LovelaceChipConfig[] = []; const chipConfigurations: LovelaceChipConfig[] = [];
const exposedChips = Registry.getExposedNames('chip'); const exposedChips = Registry.getExposedNames('chip');
const areaIds = Registry.areas.map((area) => area.area_id ?? '');
let Chip; let Chip;
@@ -164,7 +163,6 @@ class HomeView extends AbstractView {
Chip = (await import(`../chips/${moduleName}`)).default; Chip = (await import(`../chips/${moduleName}`)).default;
const currentChip = new Chip(); const currentChip = new Chip();
currentChip.setTapActionTarget({ area_id: areaIds });
chipConfigurations.push(currentChip.getChipConfiguration()); chipConfigurations.push(currentChip.getChipConfiguration());
} catch (e) { } catch (e) {
logMessage(lvlError, `Error creating the configuration for chip ${chipName}!`, e); logMessage(lvlError, `Error creating the configuration for chip ${chipName}!`, e);