mirror of
https://github.com/esphome/esphome.git
synced 2024-12-04 04:28:19 +01:00
[template/text] Fix lambda config (#6655)
Co-authored-by: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com>
This commit is contained in:
parent
c007593f72
commit
73bb4aa4d5
4 changed files with 38 additions and 1 deletions
|
@ -28,7 +28,7 @@ def validate(config):
|
||||||
raise cv.Invalid("optimistic cannot be used with lambda")
|
raise cv.Invalid("optimistic cannot be used with lambda")
|
||||||
if CONF_INITIAL_VALUE in config:
|
if CONF_INITIAL_VALUE in config:
|
||||||
raise cv.Invalid("initial_value cannot be used with lambda")
|
raise cv.Invalid("initial_value cannot be used with lambda")
|
||||||
if CONF_RESTORE_VALUE in config:
|
if config[CONF_RESTORE_VALUE]:
|
||||||
raise cv.Invalid("restore_value cannot be used with lambda")
|
raise cv.Invalid("restore_value cannot be used with lambda")
|
||||||
elif CONF_INITIAL_VALUE not in config:
|
elif CONF_INITIAL_VALUE not in config:
|
||||||
config[CONF_INITIAL_VALUE] = ""
|
config[CONF_INITIAL_VALUE] = ""
|
||||||
|
|
|
@ -54,3 +54,17 @@ def test_text_config_value_mode_set(generate_main):
|
||||||
# Then
|
# Then
|
||||||
assert "it_1->traits.set_mode(text::TEXT_MODE_TEXT);" in main_cpp
|
assert "it_1->traits.set_mode(text::TEXT_MODE_TEXT);" in main_cpp
|
||||||
assert "it_3->traits.set_mode(text::TEXT_MODE_PASSWORD);" in main_cpp
|
assert "it_3->traits.set_mode(text::TEXT_MODE_PASSWORD);" in main_cpp
|
||||||
|
|
||||||
|
|
||||||
|
def test_text_config_lamda_is_set(generate_main):
|
||||||
|
"""
|
||||||
|
Test if lambda is set for lambda mode
|
||||||
|
"""
|
||||||
|
# Given
|
||||||
|
|
||||||
|
# When
|
||||||
|
main_cpp = generate_main("tests/component_tests/text/test_text.yaml")
|
||||||
|
|
||||||
|
# Then
|
||||||
|
assert "it_4->set_template([=]() -> optional<std::string> {" in main_cpp
|
||||||
|
assert 'return std::string{"Hello"};' in main_cpp
|
||||||
|
|
|
@ -31,3 +31,15 @@ text:
|
||||||
optimistic: true
|
optimistic: true
|
||||||
internal: true
|
internal: true
|
||||||
max_length: 255
|
max_length: 255
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
name: "test 4 key"
|
||||||
|
id: "it_4"
|
||||||
|
mode: text
|
||||||
|
set_action:
|
||||||
|
- then:
|
||||||
|
- logger.log:
|
||||||
|
format: Template text set to %s
|
||||||
|
args: ["x.c_str()"]
|
||||||
|
lambda: |
|
||||||
|
return std::string{"Hello"};
|
||||||
|
|
|
@ -149,6 +149,17 @@ text:
|
||||||
min_length: 0
|
min_length: 0
|
||||||
max_length: 100
|
max_length: 100
|
||||||
mode: text
|
mode: text
|
||||||
|
- platform: template
|
||||||
|
name: "Template text lambda"
|
||||||
|
mode: text
|
||||||
|
update_interval: 1s
|
||||||
|
lambda: |
|
||||||
|
return std::string{"Hello!"};
|
||||||
|
set_action:
|
||||||
|
then:
|
||||||
|
- logger.log:
|
||||||
|
format: Template Text set to %s
|
||||||
|
args: ["x.c_str()"]
|
||||||
|
|
||||||
alarm_control_panel:
|
alarm_control_panel:
|
||||||
- platform: template
|
- platform: template
|
||||||
|
|
Loading…
Reference in a new issue