esphome/tests/component_tests/deep_sleep/test_deep_sleep.py

45 lines
1.4 KiB
Python
Raw Permalink Normal View History

"""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
"""
2023-05-15 06:09:56 +02:00
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.
"""
2023-05-15 06:09:56 +02:00
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.
"""
2023-05-15 06:09:56 +02:00
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.
"""
2023-05-15 06:09:56 +02:00
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