2021-03-07 20:03:16 +01:00
|
|
|
"""Tests for the binary sensor component."""
|
2020-07-14 17:59:03 +02:00
|
|
|
|
|
|
|
|
2020-07-15 14:04:00 +02:00
|
|
|
def test_binary_sensor_is_setup(generate_main):
|
|
|
|
"""
|
|
|
|
When the binary sensor is set in the yaml file, it should be registered in main
|
|
|
|
"""
|
|
|
|
# Given
|
|
|
|
|
|
|
|
# When
|
2021-03-07 20:03:16 +01:00
|
|
|
main_cpp = generate_main(
|
|
|
|
"tests/component_tests/binary_sensor/test_binary_sensor.yaml"
|
|
|
|
)
|
2020-07-14 17:59:03 +02:00
|
|
|
|
2020-07-15 14:04:00 +02:00
|
|
|
# Then
|
|
|
|
assert "new gpio::GPIOBinarySensor();" in main_cpp
|
|
|
|
assert "App.register_binary_sensor" in main_cpp
|
|
|
|
|
|
|
|
|
|
|
|
def test_binary_sensor_sets_mandatory_fields(generate_main):
|
2020-07-14 17:59:03 +02:00
|
|
|
"""
|
2020-07-15 14:04:00 +02:00
|
|
|
When the mandatory fields are set in the yaml, they should be set in main
|
2020-07-14 17:59:03 +02:00
|
|
|
"""
|
|
|
|
# Given
|
|
|
|
|
|
|
|
# When
|
2021-03-07 20:03:16 +01:00
|
|
|
main_cpp = generate_main(
|
|
|
|
"tests/component_tests/binary_sensor/test_binary_sensor.yaml"
|
|
|
|
)
|
2020-07-14 17:59:03 +02:00
|
|
|
|
|
|
|
# Then
|
2021-03-07 20:03:16 +01:00
|
|
|
assert 'bs_1->set_name("test bs1");' in main_cpp
|
2021-09-20 11:47:51 +02:00
|
|
|
assert "bs_1->set_pin(" in main_cpp
|
2020-07-14 17:59:03 +02:00
|
|
|
|
2020-07-15 14:04:00 +02:00
|
|
|
|
|
|
|
def test_binary_sensor_config_value_internal_set(generate_main):
|
|
|
|
"""
|
|
|
|
Test that the "internal" config value is correctly set
|
|
|
|
"""
|
|
|
|
# Given
|
|
|
|
|
|
|
|
# When
|
2021-03-07 20:03:16 +01:00
|
|
|
main_cpp = generate_main(
|
|
|
|
"tests/component_tests/binary_sensor/test_binary_sensor.yaml"
|
|
|
|
)
|
2020-07-15 14:04:00 +02:00
|
|
|
|
|
|
|
# Then
|
|
|
|
assert "bs_1->set_internal(true);" in main_cpp
|
|
|
|
assert "bs_2->set_internal(false);" in main_cpp
|