mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-16 13:56:35 +00:00
Align has template functions (#8784)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
deca6f03ba
commit
8e3a7576ea
@ -1,4 +1,5 @@
|
|||||||
const isTemplateRegex = new RegExp("{%|{{|{#");
|
const isTemplateRegex = new RegExp("{%|{{");
|
||||||
|
|
||||||
export const isTemplate = (value: string): boolean =>
|
export const isTemplate = (value: string): boolean =>
|
||||||
isTemplateRegex.test(value);
|
isTemplateRegex.test(value);
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ export const hasTemplate = (value: unknown): boolean => {
|
|||||||
}
|
}
|
||||||
if (typeof value === "object") {
|
if (typeof value === "object") {
|
||||||
const values = Array.isArray(value) ? value : Object.values(value!);
|
const values = Array.isArray(value) ? value : Object.values(value!);
|
||||||
return values.some((val) => hasTemplate(val));
|
return values.some((val) => val && hasTemplate(val));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import secondsToDuration from "../common/datetime/seconds_to_duration";
|
import secondsToDuration from "../common/datetime/seconds_to_duration";
|
||||||
import { ensureArray } from "../common/ensure-array";
|
import { ensureArray } from "../common/ensure-array";
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
|
import { isTemplate } from "../common/string/has-template";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import { Condition } from "./automation";
|
import { Condition } from "./automation";
|
||||||
import { describeCondition, describeTrigger } from "./automation_i18n";
|
import { describeCondition, describeTrigger } from "./automation_i18n";
|
||||||
@ -14,7 +15,6 @@ import {
|
|||||||
VariablesAction,
|
VariablesAction,
|
||||||
EventAction,
|
EventAction,
|
||||||
} from "./script";
|
} from "./script";
|
||||||
import { isDynamicTemplate } from "./template";
|
|
||||||
|
|
||||||
export const describeAction = <T extends ActionType>(
|
export const describeAction = <T extends ActionType>(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -35,7 +35,7 @@ export const describeAction = <T extends ActionType>(
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
config.service_template ||
|
config.service_template ||
|
||||||
(config.service && isDynamicTemplate(config.service))
|
(config.service && isTemplate(config.service))
|
||||||
) {
|
) {
|
||||||
base = "Call a service based on a template";
|
base = "Call a service based on a template";
|
||||||
} else if (config.service) {
|
} else if (config.service) {
|
||||||
@ -63,7 +63,7 @@ export const describeAction = <T extends ActionType>(
|
|||||||
let renderValues = true;
|
let renderValues = true;
|
||||||
|
|
||||||
for (const targetThing of keyConf) {
|
for (const targetThing of keyConf) {
|
||||||
if (isDynamicTemplate(targetThing)) {
|
if (isTemplate(targetThing)) {
|
||||||
targets.push(`templated ${label}`);
|
targets.push(`templated ${label}`);
|
||||||
renderValues = false;
|
renderValues = false;
|
||||||
break;
|
break;
|
||||||
@ -92,7 +92,7 @@ export const describeAction = <T extends ActionType>(
|
|||||||
if (typeof config.delay === "number") {
|
if (typeof config.delay === "number") {
|
||||||
duration = `for ${secondsToDuration(config.delay)!}`;
|
duration = `for ${secondsToDuration(config.delay)!}`;
|
||||||
} else if (typeof config.delay === "string") {
|
} else if (typeof config.delay === "string") {
|
||||||
duration = isDynamicTemplate(config.delay)
|
duration = isTemplate(config.delay)
|
||||||
? "based on a template"
|
? "based on a template"
|
||||||
: `for ${config.delay}`;
|
: `for ${config.delay}`;
|
||||||
} else {
|
} else {
|
||||||
@ -124,7 +124,7 @@ export const describeAction = <T extends ActionType>(
|
|||||||
|
|
||||||
if (actionType === "fire_event") {
|
if (actionType === "fire_event") {
|
||||||
const config = action as EventAction;
|
const config = action as EventAction;
|
||||||
if (isDynamicTemplate(config.event)) {
|
if (isTemplate(config.event)) {
|
||||||
return "Fire event based on a template";
|
return "Fire event based on a template";
|
||||||
}
|
}
|
||||||
return `Fire event ${config.event}`;
|
return `Fire event ${config.event}`;
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export const isDynamicTemplate = (value: string) => value.includes("{{");
|
|
@ -286,7 +286,7 @@ class HaPanelDevService extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _checkUiSupported() {
|
private _checkUiSupported() {
|
||||||
if (hasTemplate(this._serviceData)) {
|
if (this._serviceData && hasTemplate(this._serviceData)) {
|
||||||
this._yamlMode = true;
|
this._yamlMode = true;
|
||||||
this._uiAvailable = false;
|
this._uiAvailable = false;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user