Files
esphome/tests/component_tests/deep_sleep/test_deep_sleep.py
J. Nick Koston f926978f61 [core] Make register_component protected, remove runtime checks
Instead of runtime null, duplicate, and capacity checks in
register_component_, make the method unreachable from outside
codegen by removing the public template wrapper and granting
friend access to the codegen-generated ::setup() function.

Since ESPHOME_COMPONENT_COUNT is set to exactly
len(CORE.component_ids) at codegen time, the StaticVector is
always correctly sized and the runtime capacity check cannot
trigger from codegen. External components that bypassed codegen
to call App.register_component() directly will now get a
compile error, forcing them to properly declare their components
in their config schema.

Co-Authored-By: J. Nick Koston <nick@koston.org>
2026-02-27 21:05:34 -10:00

45 lines
1.4 KiB
Python

"""Tests for the deep sleep component."""
def test_deep_sleep_setup(generate_main):
"""
When the deep sleep is set in the yaml file, it should be registered in main
"""
main_cpp = generate_main("tests/component_tests/deep_sleep/test_deep_sleep1.yaml")
assert "deepsleep = new deep_sleep::DeepSleepComponent();" in main_cpp
assert "App.register_component_(deepsleep);" in main_cpp
def test_deep_sleep_sleep_duration(generate_main):
"""
When deep sleep is configured with sleep duration, it should be set.
"""
main_cpp = generate_main("tests/component_tests/deep_sleep/test_deep_sleep1.yaml")
assert "deepsleep->set_sleep_duration(60000);" in main_cpp
def test_deep_sleep_run_duration_simple(generate_main):
"""
When deep sleep is configured with run duration, it should be set.
"""
main_cpp = generate_main("tests/component_tests/deep_sleep/test_deep_sleep1.yaml")
assert "deepsleep->set_run_duration(10000);" in main_cpp
def test_deep_sleep_run_duration_dictionary(generate_main):
"""
When deep sleep is configured with dictionary run duration, it should be set.
"""
main_cpp = generate_main("tests/component_tests/deep_sleep/test_deep_sleep2.yaml")
assert (
"deepsleep->set_run_duration(deep_sleep::WakeupCauseToRunDuration{\n"
" .default_cause = 10000,\n"
" .touch_cause = 10000,\n"
" .gpio_cause = 30000,\n"
"});"
) in main_cpp