From 08f7ee2393089b2ab61076153f1c0ac8316d6775 Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 29 Jun 2022 16:42:03 -0400 Subject: [PATCH] zone description --- webapp/src/utils/formatting.tsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/webapp/src/utils/formatting.tsx b/webapp/src/utils/formatting.tsx index 015aa24..b5f968c 100644 --- a/webapp/src/utils/formatting.tsx +++ b/webapp/src/utils/formatting.tsx @@ -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