mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[template] Add regression tests for lambdas with captures (PR #11555)
This commit is contained in:
		| @@ -9,6 +9,27 @@ esphome: | ||||
|         id: template_sens | ||||
|         state: !lambda "return 42.0;" | ||||
|  | ||||
|     # Test C++ API: set_template() with stateless lambda (no captures) | ||||
|     - lambda: |- | ||||
|         id(template_sens).set_template([]() -> esphome::optional<float> { | ||||
|           return 123.0f; | ||||
|         }); | ||||
|  | ||||
|     # Test C++ API: set_template() with stateful lambda (with captures) | ||||
|     # This is the regression test for issue #11555 | ||||
|     - lambda: |- | ||||
|         float captured_value = 456.0f; | ||||
|         id(template_sens).set_template([captured_value]() -> esphome::optional<float> { | ||||
|           return captured_value; | ||||
|         }); | ||||
|  | ||||
|     # Test C++ API: set_template() with more complex capture | ||||
|     - lambda: |- | ||||
|         auto sensor_id = id(template_sens); | ||||
|         id(template_number).set_template([sensor_id]() -> esphome::optional<float> { | ||||
|           return sensor_id->state * 2.0f; | ||||
|         }); | ||||
|  | ||||
|     - datetime.date.set: | ||||
|         id: test_date | ||||
|         date: | ||||
| @@ -215,6 +236,7 @@ cover: | ||||
|  | ||||
| number: | ||||
|   - platform: template | ||||
|     id: template_number | ||||
|     name: "Template number" | ||||
|     optimistic: true | ||||
|     min_value: 0 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user