Raise ConditionError for state errors (#46244)
This commit is contained in:
parent
6a62ebb6a4
commit
f27066e773
3 changed files with 53 additions and 5 deletions
|
@ -314,11 +314,22 @@ def state(
|
|||
|
||||
Async friendly.
|
||||
"""
|
||||
if entity is None:
|
||||
raise ConditionError("No entity specified")
|
||||
|
||||
if isinstance(entity, str):
|
||||
entity_id = entity
|
||||
entity = hass.states.get(entity)
|
||||
|
||||
if entity is None or (attribute is not None and attribute not in entity.attributes):
|
||||
return False
|
||||
if entity is None:
|
||||
raise ConditionError(f"Unknown entity {entity_id}")
|
||||
else:
|
||||
entity_id = entity.entity_id
|
||||
|
||||
if attribute is not None and attribute not in entity.attributes:
|
||||
raise ConditionError(
|
||||
f"Attribute '{attribute}' (of entity {entity_id}) does not exist"
|
||||
)
|
||||
|
||||
assert isinstance(entity, State)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue