zone description
This commit is contained in:
1 parent
0088dd8448
commit
08f7ee2393
1 file changed
+24
@@ -5,6 +5,7 @@ import {
|
||||
AutomationDeviceState,
|
||||
AutomationTime,
|
||||
} from "types/automations/common";
|
||||
import { AutomationTriggerZone } from "types/automations/triggers";
|
||||
|
||||
export interface Namer {
|
||||
getEntityName(entity_id: string | string[], maxEntities?: number): string;
|
||||
@@ -51,6 +52,9 @@ export const getDescriptionFromAutomationNode = <
|
||||
if (node.platform === "tag") {
|
||||
return `Tag = ${node.tag_id}`;
|
||||
}
|
||||
if (node.platform === "zone") {
|
||||
return getDescriptionForZoneType(node as any, namer);
|
||||
}
|
||||
if (node.platform === "state") {
|
||||
let out = "";
|
||||
if (typeof node.entity_id === "string") {
|
||||
@@ -181,6 +185,26 @@ const getDescriptionForDeviceType = (
|
||||
return actionPort + " " + out;
|
||||
};
|
||||
|
||||
const getDescriptionForZoneType = (
|
||||
node: AutomationTriggerZone,
|
||||
namer: Namer
|
||||
) => {
|
||||
let out = "";
|
||||
let actionPort = "";
|
||||
if (node.event) {
|
||||
actionPort += node.event + " ";
|
||||
}
|
||||
if (node.zone) {
|
||||
actionPort += prettyName(namer.getEntityName(node.zone));
|
||||
}
|
||||
actionPort = actionPort.trim();
|
||||
if (node.entity_id) {
|
||||
out += namer.getEntityName(node.entity_id);
|
||||
}
|
||||
out = out.trim();
|
||||
return out + " " + actionPort;
|
||||
};
|
||||
|
||||
export const prettyName = (n: string) => {
|
||||
const clean = n.replaceAll(/[.\-_]/g, " ");
|
||||
return clean
|
||||
|
||||
Reference in new issue
Block a user