Пример #1
0
def retry_action_to_code(config, action_id, template_arg, args):
    max_retries = config[c.CONF_MAX_RETRIES]
    text = "if(sendaction->get_send_attempts() < {}) " \
        "{{sendaction->stop(); sendaction->send(); return true;}} " \
        "else " \
        "{{return false;}}".format(max_retries)
    lambda_ = yield cg.process_lambda(Lambda(text), args, return_type=cg.bool_)
    yield cg.new_Pvariable(action_id, template_arg, lambda_)
Пример #2
0
async def logger_log_action_to_code(config, action_id, template_arg, args):
    esp_log = LOG_LEVEL_TO_ESP_LOG[config[CONF_LEVEL]]
    args_ = [cg.RawExpression(str(x)) for x in config[CONF_ARGS]]

    text = str(cg.statement(esp_log(config[CONF_TAG], config[CONF_FORMAT], *args_)))

    lambda_ = await cg.process_lambda(Lambda(text), args, return_type=cg.void)
    return cg.new_Pvariable(action_id, template_arg, lambda_)
Пример #3
0
async def logger_log_action_to_code(config, action_id, template_arg, args):
    args_ = [cg.RawExpression(str(x)) for x in config[CONF_ARGS]]

    text = str(
        cg.statement(
            GLOBAL_BLE_CONTROLLER_VAR.send_command_result(
                config[CONF_FORMAT], *args_)))

    lambda_ = await cg.process_lambda(Lambda(text), args, return_type=cg.void)
    return cg.new_Pvariable(action_id, template_arg, lambda_)
Пример #4
0
def logger_log_action_to_code(config, action_id, template_arg, args):
    esp_log = LOG_LEVEL_TO_ESP_LOG[config[CONF_LEVEL]]
    args_ = [RawExpression(text_type(x)) for x in config[CONF_ARGS]]

    text = text_type(
        statement(esp_log(config[CONF_TAG], config[CONF_FORMAT], *args_)))

    for lambda_ in process_lambda(Lambda(text), args, return_type=void):
        yield None
    rhs = LambdaAction.new(template_arg, lambda_)
    type = LambdaAction.template(template_arg)
    yield Pvariable(action_id, rhs, type=type)
Пример #5
0
def lambda_(value):
    """Coerce this configuration option to a lambda."""
    if not isinstance(value, Lambda):
        value = Lambda(string_strict(value))
    entity_id_parts = re.split(LAMBDA_ENTITY_ID_PROG, value.value)
    if len(entity_id_parts) != 1:
        entity_ids = ' '.join("'{}'".format(entity_id_parts[i])
                              for i in range(1, len(entity_id_parts), 2))
        raise Invalid("Lambda contains reference to entity-id-style ID {}. "
                      "The id() wrapper only works for ESPHome-internal types. For importing "
                      "states from Home Assistant use the 'homeassistant' sensor platforms."
                      "".format(entity_ids))
    return value
Пример #6
0
def lambda_(value):
    """Coerce this configuration option to a lambda."""
    if not isinstance(value, Lambda):
        start_mark = None
        if isinstance(value, ESPHomeDataBase) and value.esp_range is not None:
            start_mark = DocumentLocation.copy(value.esp_range.start_mark)
            start_mark.line += value.content_offset
        value = Lambda(string_strict(value), start_mark)
    entity_id_parts = re.split(LAMBDA_ENTITY_ID_PROG, value.value)
    if len(entity_id_parts) != 1:
        entity_ids = ' '.join("'{}'".format(entity_id_parts[i])
                              for i in range(1, len(entity_id_parts), 2))
        raise Invalid(
            "Lambda contains reference to entity-id-style ID {}. "
            "The id() wrapper only works for ESPHome-internal types. For importing "
            "states from Home Assistant use the 'homeassistant' sensor platforms."
            "".format(entity_ids))
    return value
def test_check_not_templatable__invalid():
    with pytest.raises(Invalid, match="This option is not templatable!"):
        config_validation.check_not_templatable(Lambda(""))
Пример #8
0
def _lambda(loader, node):
    return Lambda(text_type(node.value))
Пример #9
0
 def construct_lambda(self, node):
     return Lambda(str(node.value))
Пример #10
0
 def construct_lambda(self, node):
     return Lambda(text_type(node.value))
def lambda_(value):
    if isinstance(value, Lambda):
        return value
    return Lambda(string_strict(value))
Пример #12
0
 def construct_lambda(self, node):
     start_mark = DocumentLocation.from_mark(node.start_mark)
     if node.style is not None and node.style in '|>':
         start_mark.line += 1
     return Lambda(str(node.value), start_mark)
Пример #13
0
def abort_action_to_code(config, action_id, template_arg, args):
    text = "sendaction->stop(); return true;"
    lambda_ = yield cg.process_lambda(Lambda(text), args, return_type=cg.bool_)
    yield cg.new_Pvariable(action_id, template_arg, lambda_)