mirror of
https://github.com/esphome/esphome.git
synced 2026-09-23 21:14:03 +00:00
[core] Pack entity flags into configure_entity_() and protect setters (#14564)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
9547a54fac
commit
d0285cdc41
@@ -1,14 +1,6 @@
|
||||
"""Tests for the text 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))
|
||||
from tests.component_tests.helpers import INTERNAL_BIT, extract_packed_value
|
||||
|
||||
|
||||
def test_text_sensor_is_setup(generate_main):
|
||||
@@ -49,9 +41,9 @@ def test_text_sensor_config_value_internal_set(generate_main):
|
||||
# When
|
||||
main_cpp = generate_main("tests/component_tests/text_sensor/test_text_sensor.yaml")
|
||||
|
||||
# Then
|
||||
assert "ts_2->set_internal(true);" in main_cpp
|
||||
assert "ts_3->set_internal(false);" in main_cpp
|
||||
# Then: ts_2 has internal: true, ts_3 has internal: false
|
||||
assert extract_packed_value(main_cpp, "ts_2") & INTERNAL_BIT != 0
|
||||
assert extract_packed_value(main_cpp, "ts_3") & INTERNAL_BIT == 0
|
||||
|
||||
|
||||
def test_text_sensor_device_class_set(generate_main):
|
||||
@@ -65,7 +57,7 @@ def test_text_sensor_device_class_set(generate_main):
|
||||
|
||||
# Then: ts_2 has device_class: timestamp, ts_3 has device_class: date
|
||||
# so their packed values must be non-zero
|
||||
packed_ts_2 = _extract_packed_value(main_cpp, "ts_2")
|
||||
packed_ts_2 = extract_packed_value(main_cpp, "ts_2")
|
||||
assert packed_ts_2 != 0
|
||||
packed_ts_3 = _extract_packed_value(main_cpp, "ts_3")
|
||||
packed_ts_3 = extract_packed_value(main_cpp, "ts_3")
|
||||
assert packed_ts_3 != 0
|
||||
|
||||
Reference in New Issue
Block a user