Exemple #1
0
def async_condition_from_config(
        config: ConfigType,
        config_validation: bool) -> condition.ConditionCheckerType:
    """Evaluate state based on configuration."""
    if config_validation:
        config = CONDITION_SCHEMA(config)
    numeric_state_config = {
        condition.CONF_CONDITION: "numeric_state",
        condition.CONF_ENTITY_ID: config[CONF_ENTITY_ID],
    }
    if CONF_ABOVE in config:
        numeric_state_config[condition.CONF_ABOVE] = config[CONF_ABOVE]
    if CONF_BELOW in config:
        numeric_state_config[condition.CONF_BELOW] = config[CONF_BELOW]

    return condition.async_numeric_state_from_config(numeric_state_config)
def async_condition_from_config(
        hass: HomeAssistant,
        config: ConfigType) -> condition.ConditionCheckerType:
    """Evaluate state based on configuration."""
    numeric_state_config = {
        CONF_CONDITION: "numeric_state",
        CONF_ENTITY_ID: config[CONF_ENTITY_ID],
    }
    if CONF_ABOVE in config:
        numeric_state_config[CONF_ABOVE] = config[CONF_ABOVE]
    if CONF_BELOW in config:
        numeric_state_config[CONF_BELOW] = config[CONF_BELOW]

    numeric_state_config = cv.NUMERIC_STATE_CONDITION_SCHEMA(
        numeric_state_config)
    numeric_state_config = condition.numeric_state_validate_config(
        hass, numeric_state_config)
    return condition.async_numeric_state_from_config(numeric_state_config)