@@ -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,
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user