fixed state
This commit is contained in:
1 parent
649ee0f31e
commit
fd35938fcb
3 files changed
+22
-4
No files matched your search
@@ -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<C extends AutomationCondition>
|
||||
extends FC<{
|
||||
@@ -213,10 +215,17 @@ export const LogicViewer: Editor<LogicCondition> = ({
|
||||
export const StateEditor: Editor<StateCondition> = ({
|
||||
onChange,
|
||||
condition,
|
||||
ha,
|
||||
}) => {
|
||||
const restrictToDomain =
|
||||
!condition.entity_id || condition.entity_id.length === 0
|
||||
? undefined
|
||||
: getEntityDomains(condition.entity_id);
|
||||
|
||||
return (
|
||||
<>
|
||||
<InputEntity
|
||||
restrictToDomain={restrictToDomain}
|
||||
value={condition.entity_id}
|
||||
multiple
|
||||
onChange={(entity_id) =>
|
||||
@@ -226,19 +235,24 @@ export const StateEditor: Editor<StateCondition> = ({
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputText
|
||||
<InputAutoComplete
|
||||
label="Attribute"
|
||||
value={condition.attribute ?? ""}
|
||||
options={ha.entities.getAttributes(condition.entity_id)}
|
||||
multiple={false}
|
||||
onChange={(attribute) =>
|
||||
onChange({
|
||||
...condition,
|
||||
attribute,
|
||||
attribute: attribute ?? undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputText
|
||||
label="State"
|
||||
value={String(condition.state)}
|
||||
placeholder={ha.entities
|
||||
.getStates(condition.entity_id, condition.attribute)
|
||||
.join(" or ")}
|
||||
onChange={(state) =>
|
||||
onChange({
|
||||
...condition,
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in new issue
Block a user