mirror of
https://github.com/esphome/esphome.git
synced 2026-05-26 11:17:00 +08:00
[core] Merge set_name + set_entity_strings into configure_entity_ (#14444)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
"""Tests for the sensor component."""
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def _extract_packed_value(main_cpp, var_name):
|
||||
"""Extract the third (packed) argument from a configure_entity_ call."""
|
||||
pattern = rf"{re.escape(var_name)}->configure_entity_\([^,]+,\s*\w+,\s*(\d+)\)"
|
||||
match = re.search(pattern, main_cpp)
|
||||
assert match, f"configure_entity_ call not found for {var_name}"
|
||||
return int(match.group(1))
|
||||
|
||||
|
||||
def test_sensor_device_class_set(generate_main):
|
||||
"""
|
||||
@@ -10,5 +20,6 @@ def test_sensor_device_class_set(generate_main):
|
||||
# When
|
||||
main_cpp = generate_main("tests/component_tests/sensor/test_sensor.yaml")
|
||||
|
||||
# Then
|
||||
assert "s_1->set_entity_strings(" in main_cpp
|
||||
# Then: device_class: voltage means packed value must be non-zero
|
||||
packed = _extract_packed_value(main_cpp, "s_1")
|
||||
assert packed != 0
|
||||
|
||||
Reference in New Issue
Block a user