def if_or_condition(hass: HomeAssistant, variables: TemplateVarsType = None) -> bool: """Test or condition.""" errors = [] for index, check in enumerate(checks): try: with trace_path(["conditions", str(index)]): if check(hass, variables): return True except ConditionError as ex: errors.append( ConditionErrorIndex("or", index=index, total=len(checks), error=ex)) # Raise the errors if no check was true if errors: raise ConditionErrorContainer("or", errors=errors) return False
def if_state(hass: HomeAssistant, variables: TemplateVarsType = None) -> bool: """Test if condition.""" errors = [] for index, entity_id in enumerate(entity_ids): try: if not state(hass, entity_id, req_states, for_period, attribute): return False except ConditionError as ex: errors.append( ConditionErrorIndex("state", index=index, total=len(entity_ids), error=ex)) # Raise the errors if no check was false if errors: raise ConditionErrorContainer("state", errors=errors) return True
def if_action(variables=None): """AND all conditions.""" errors = [] for index, check in enumerate(checks): try: if not check(hass, variables): return False except ConditionError as ex: errors.append( ConditionErrorIndex("condition", index=index, total=len(checks), error=ex)) if errors: LOGGER.warning( "Error evaluating condition in '%s':\n%s", name, ConditionErrorContainer("condition", errors=errors), ) return False return True