Files
esphome/tests/component_tests/i2s_audio/test_config.py
T

37 lines
1.0 KiB
Python

"""Exercise the I2S speaker keep_alive validation."""
from collections.abc import Callable
from pathlib import Path
import pytest
from esphome.config import read_config
from esphome.core import CORE
def test_keep_alive_generates_setter(
generate_main: Callable[[Path], str],
component_config_path: Callable[[str], Path],
) -> None:
source = generate_main(component_config_path("keep_alive.yaml"))
assert "set_keep_alive(true)" in source
@pytest.mark.parametrize(
("config_file", "message"),
[
("keep_alive_shared_bus.yaml", "needs its own I2S bus"),
("keep_alive_shared_mic.yaml", "needs its own I2S bus"),
("keep_alive_spdif.yaml", "SPDIF mode does not support 'keep_alive'"),
],
)
def test_keep_alive_rejected(
component_config_path: Callable[[str], Path],
capsys: pytest.CaptureFixture[str],
config_file: str,
message: str,
) -> None:
CORE.config_path = component_config_path(config_file)
assert read_config({}) is None
assert message in capsys.readouterr().out