mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Raise ConditionError for state errors (#46244)
This commit is contained in:
committed by
GitHub
parent
6a62ebb6a4
commit
f27066e773
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user