fix: Expand templates in stock elements (#2199)

- Related: #2193
This commit is contained in:
Dermot Duffy
2025-10-06 21:14:29 -07:00
committed by GitHub
parent af53c66cd5
commit 9f479f8b4f
5 changed files with 89 additions and 44 deletions
+11 -4
View File
@@ -91,7 +91,7 @@ export class ActionsManager implements ActionsExecutor {
/**
* This method is called when an ll-custom event is fired. This is used by
* cards to fire custom actions. This card itself should not call this, but
* embedded elements may.
* embedded picture elements may.
*/
public handleCustomActionEvent = async (
ev: Event | CustomEvent<ActionConfig>,
@@ -111,7 +111,11 @@ export class ActionsManager implements ActionsExecutor {
return;
}
await this.executeActions({ actions: action });
await this.executeActions(
{ actions: action },
// Elements rendered by this card will already have rendered templates.
true,
);
};
/**
@@ -129,10 +133,13 @@ export class ActionsManager implements ActionsExecutor {
await allPromises(this._actionsInFlight, (actionSet) => actionSet.stop());
}
public async executeActions(request: ActionsExecutionRequest): Promise<void> {
public async executeActions(
request: ActionsExecutionRequest,
renderTemplates = true,
): Promise<void> {
const hass = this._api.getHASSManager().getHASS();
const renderedAction: ActionConfig | ActionConfig[] =
hass && this._templateRenderer
renderTemplates && hass && this._templateRenderer
? (this._templateRenderer.renderRecursively(hass, request.actions, {
conditionState: this._api.getConditionStateManager().getState(),
triggerData: request?.triggerData,
+10 -10
View File
@@ -20,15 +20,17 @@ interface TemplateContext {
acc: TemplateContextInternal;
}
interface TemplateRenderOptions {
conditionState?: ConditionState;
triggerData?: ConditionsTriggerData;
mediaData?: TemplateMediaData;
}
export class TemplateRenderer {
public renderRecursively = (
hass: HomeAssistant,
data: unknown,
options?: {
conditionState?: ConditionState;
triggerData?: ConditionsTriggerData;
mediaData?: TemplateMediaData;
},
options?: TemplateRenderOptions,
): unknown => {
return this._renderTemplateRecursively(
hass,
@@ -37,11 +39,9 @@ export class TemplateRenderer {
);
};
protected _generateTemplateContext(options?: {
conditionState?: ConditionState;
triggerData?: ConditionsTriggerData;
mediaData?: TemplateMediaData;
}): TemplateContext | undefined {
protected _generateTemplateContext(
options?: TemplateRenderOptions,
): TemplateContext | undefined {
if (
!options?.conditionState?.camera &&
!options?.conditionState?.view &&