Files
esphome/tests/component_tests/button/test_button.py
T
J. Nick Koston 7117ded6b6 [core] Pack entity flags into configure_entity_() and protect setters
Move set_internal(), set_disabled_by_default(), set_entity_category(),
and set_device() to protected on EntityBase. These were codegen-only
setters never intended for runtime use.

internal, disabled_by_default, and entity_category are now packed into
the existing configure_entity_() uint32 parameter alongside string
indices, eliminating up to 3 separate function calls per entity.

set_device() is renamed to set_device_() per protected naming convention
and remains a separate call (pointer can't be packed).

Entity category integer mapping is derived from cv.ENTITY_CATEGORIES
to stay in sync with the C++ enum automatically.
2026-03-06 09:35:30 -10:00

47 lines
1.3 KiB
Python

"""Tests for the button component"""
def test_button_is_setup(generate_main):
"""
When the button is set in the yaml file if should be registered in main
"""
# Given
# When
main_cpp = generate_main("tests/component_tests/button/test_button.yaml")
# Then
assert "new wake_on_lan::WakeOnLanButton();" in main_cpp
assert "App.register_button" in main_cpp
assert "App.register_component" in main_cpp
def test_button_sets_mandatory_fields(generate_main):
"""
When the mandatory fields are set in the yaml, they should be set in main
"""
# Given
# When
main_cpp = generate_main("tests/component_tests/button/test_button.yaml")
# Then
assert 'wol_1->configure_entity_("wol_test_1",' in main_cpp
assert "wol_2->set_macaddr(18, 52, 86, 120, 144, 171);" in main_cpp
def test_button_config_value_internal_set(generate_main):
"""
Test that the "internal" config value is correctly set
"""
# Given
# When
main_cpp = generate_main("tests/component_tests/button/test_button.yaml")
# Then
# 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