From fd35938fcbc09e3aca139257c34a24bf5bed1162 Mon Sep 17 00:00:00 2001 From: Ari Date: Tue, 19 Jul 2022 21:13:19 -0400 Subject: [PATCH] fixed state --- .../ConditionEditor/editorRender.tsx | 18 ++++++++++++++++-- webapp/src/haService/index.ts | 6 +++++- webapp/src/utils/formatting.tsx | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/webapp/src/components/ConditionEditor/editorRender.tsx b/webapp/src/components/ConditionEditor/editorRender.tsx index ff0ac38..0c7c273 100644 --- a/webapp/src/components/ConditionEditor/editorRender.tsx +++ b/webapp/src/components/ConditionEditor/editorRender.tsx @@ -24,6 +24,8 @@ import { HAService } from "haService"; import { DeviceEditor } from "components/DeviceEditor"; import { ButtonIcon } from "components/Icons/ButtonIcons"; import AddIcon from "@mui/icons-material/Add"; +import { getEntityDomains } from "utils/automations"; +import { InputAutoComplete } from "components/Inputs/InputAutoComplete"; interface Editor extends FC<{ @@ -213,10 +215,17 @@ export const LogicViewer: Editor = ({ export const StateEditor: Editor = ({ onChange, condition, + ha, }) => { + const restrictToDomain = + !condition.entity_id || condition.entity_id.length === 0 + ? undefined + : getEntityDomains(condition.entity_id); + return ( <> @@ -226,19 +235,24 @@ export const StateEditor: Editor = ({ }) } /> - onChange({ ...condition, - attribute, + attribute: attribute ?? undefined, }) } /> onChange({ ...condition, diff --git a/webapp/src/haService/index.ts b/webapp/src/haService/index.ts index 7ab32b4..9983d45 100644 --- a/webapp/src/haService/index.ts +++ b/webapp/src/haService/index.ts @@ -209,10 +209,14 @@ export const useHA = () => { }, getEntityName(entity_id, maxEntities = 1) { if (Array.isArray(entity_id)) { - return entity_id + const out = entity_id .slice(0, maxEntities) .map(entities.getLabel) .join(", "); + if (entity_id.length > maxEntities) { + return out + " and more"; + } + return out; } return entities.getLabel(entity_id); }, diff --git a/webapp/src/utils/formatting.tsx b/webapp/src/utils/formatting.tsx index 466e1f0..b419654 100644 --- a/webapp/src/utils/formatting.tsx +++ b/webapp/src/utils/formatting.tsx @@ -110,7 +110,7 @@ export const getDescriptionFromAutomationNode = < } return "Numeric State Condition"; case "state": - return `${namer.getEntityName(node.entity_id)} is '${node.state}'`; + return `${namer.getEntityName(node.entity_id, 2)} is '${node.state}'`; case "template": return node.value_template; case "device":