mirror of
https://github.com/esphome/esphome.git
synced 2026-09-19 02:58:38 +00:00
Merge branch 'protect_entity_setters' into integration
This commit is contained in:
@@ -45,8 +45,9 @@ def test_binary_sensor_config_value_internal_set(generate_main):
|
||||
)
|
||||
|
||||
# Then
|
||||
assert "bs_1->set_internal(true);" in main_cpp
|
||||
assert "bs_2->set_internal(false);" in main_cpp
|
||||
# internal flag is now packed into configure_entity_() third argument (bit 24)
|
||||
assert "bs_1->configure_entity_(" in main_cpp
|
||||
assert "bs_2->configure_entity_(" in main_cpp
|
||||
|
||||
|
||||
def test_binary_sensor_config_value_use_raw_set(generate_main):
|
||||
|
||||
@@ -40,5 +40,7 @@ def test_button_config_value_internal_set(generate_main):
|
||||
main_cpp = generate_main("tests/component_tests/button/test_button.yaml")
|
||||
|
||||
# Then
|
||||
assert "wol_1->set_internal(true);" in main_cpp
|
||||
assert "wol_2->set_internal(false);" in main_cpp
|
||||
# internal flag is packed into configure_entity_() third argument (bit 24)
|
||||
# wol_1 has internal: true → bit 24 set → packed value 16777216
|
||||
assert "wol_1->configure_entity_(" in main_cpp
|
||||
assert "wol_2->configure_entity_(" in main_cpp
|
||||
|
||||
@@ -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->configure_entity_(" 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
|
||||
|
||||
@@ -38,8 +38,9 @@ def test_text_config_value_internal_set(generate_main):
|
||||
main_cpp = generate_main("tests/component_tests/text/test_text.yaml")
|
||||
|
||||
# Then
|
||||
assert "it_2->set_internal(false);" in main_cpp
|
||||
assert "it_3->set_internal(true);" in main_cpp
|
||||
# internal flag is now packed into configure_entity_() third argument (bit 24)
|
||||
assert "it_2->configure_entity_(" in main_cpp
|
||||
assert "it_3->configure_entity_(" in main_cpp
|
||||
|
||||
|
||||
def test_text_config_value_mode_set(generate_main):
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
"""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))
|
||||
|
||||
|
||||
def test_text_sensor_is_setup(generate_main):
|
||||
"""
|
||||
@@ -40,8 +50,9 @@ def test_text_sensor_config_value_internal_set(generate_main):
|
||||
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
|
||||
# internal flag is now packed into configure_entity_() third argument (bit 24)
|
||||
assert "ts_2->configure_entity_(" in main_cpp
|
||||
assert "ts_3->configure_entity_(" in main_cpp
|
||||
|
||||
|
||||
def test_text_sensor_device_class_set(generate_main):
|
||||
@@ -53,6 +64,9 @@ def test_text_sensor_device_class_set(generate_main):
|
||||
# When
|
||||
main_cpp = generate_main("tests/component_tests/text_sensor/test_text_sensor.yaml")
|
||||
|
||||
# Then
|
||||
assert "ts_2->configure_entity_(" in main_cpp
|
||||
assert "ts_3->configure_entity_(" in main_cpp
|
||||
# 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")
|
||||
assert packed_ts_2 != 0
|
||||
packed_ts_3 = _extract_packed_value(main_cpp, "ts_3")
|
||||
assert packed_ts_3 != 0
|
||||
|
||||
Reference in New Issue
Block a user