mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
[ch423] Add CH423 I/O expander component (#13079)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
58
tests/unit_tests/components/test_ch423.py
Normal file
58
tests/unit_tests/components/test_ch423.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""Tests for ch423 component validation."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from esphome import config, yaml_util
|
||||
from esphome.core import CORE
|
||||
|
||||
|
||||
def test_ch423_mixed_gpio_modes_fails(tmp_path, capsys):
|
||||
"""Test that mixing input/output on GPIO pins 0-7 fails validation."""
|
||||
test_file = tmp_path / "test.yaml"
|
||||
test_file.write_text("""
|
||||
esphome:
|
||||
name: test
|
||||
|
||||
esp8266:
|
||||
board: esp01_1m
|
||||
|
||||
i2c:
|
||||
sda: GPIO4
|
||||
scl: GPIO5
|
||||
|
||||
ch423:
|
||||
- id: ch423_hub
|
||||
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
name: "CH423 Input 0"
|
||||
pin:
|
||||
ch423: ch423_hub
|
||||
number: 0
|
||||
mode: input
|
||||
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "CH423 Output 1"
|
||||
pin:
|
||||
ch423: ch423_hub
|
||||
number: 1
|
||||
mode: output
|
||||
""")
|
||||
|
||||
parsed_yaml = yaml_util.load_yaml(test_file)
|
||||
|
||||
with (
|
||||
patch.object(yaml_util, "load_yaml", return_value=parsed_yaml),
|
||||
patch.object(CORE, "config_path", test_file),
|
||||
):
|
||||
result = config.read_config({})
|
||||
|
||||
assert result is None, "Expected validation to fail with mixed GPIO modes"
|
||||
|
||||
# Check that the error message mentions the GPIO pin restriction
|
||||
captured = capsys.readouterr()
|
||||
assert (
|
||||
"GPIO pins (0-7) must all be configured as input or all as output"
|
||||
in captured.out
|
||||
)
|
||||
Reference in New Issue
Block a user