mirror of
https://github.com/esphome/esphome.git
synced 2026-11-09 14:45:57 +00:00
[output] Let final_validate_unique_channel take the channel key
This commit is contained in:
2 files changed
+20
-3
No files matched your search
@@ -132,7 +132,7 @@ BINARY_OUTPUT_ACTION_SCHEMA = maybe_simple_id(
|
||||
|
||||
|
||||
def final_validate_unique_channel(
|
||||
*, platform: str, hub_key: str
|
||||
*, platform: str, hub_key: str, channel_key: str = CONF_CHANNEL
|
||||
) -> Callable[[ConfigType], ConfigType]:
|
||||
"""Reject a second output of platform on the same channel of one hub.
|
||||
|
||||
@@ -141,7 +141,7 @@ def final_validate_unique_channel(
|
||||
return fv.unique_platform_key(
|
||||
domain=DOMAIN,
|
||||
platform=platform,
|
||||
keys=(hub_key, CONF_CHANNEL),
|
||||
keys=(hub_key, channel_key),
|
||||
message="Channel '{1}' of '{0}' is already used by another output",
|
||||
)
|
||||
|
||||
|
||||
@@ -7,13 +7,14 @@ from types import ModuleType
|
||||
import pytest
|
||||
|
||||
from esphome import config_validation as cv
|
||||
from esphome.components import output
|
||||
from esphome.components.lp5562 import output as lp5562_output
|
||||
from esphome.components.mcp4461 import output as mcp4461_output
|
||||
from esphome.components.mcp4728 import output as mcp4728_output
|
||||
from esphome.components.pca9685 import output as pca9685_output
|
||||
from esphome.components.sm2135 import output as sm2135_output
|
||||
from esphome.config import Config, read_config
|
||||
from esphome.const import CONF_CHANNEL, CONF_PLATFORM, PlatformFramework
|
||||
from esphome.const import CONF_CHANNEL, CONF_PIN, CONF_PLATFORM, PlatformFramework
|
||||
from esphome.core import CORE, ID
|
||||
|
||||
from ..types import SetCoreConfigCallable
|
||||
@@ -92,3 +93,19 @@ def test_hub_channel_must_be_unique(
|
||||
module.FINAL_VALIDATE_SCHEMA(entry)
|
||||
with pytest.raises(cv.Invalid, match=f"Channel '{channel}' of 'a' is already used"):
|
||||
module.FINAL_VALIDATE_SCHEMA(entries[3])
|
||||
|
||||
|
||||
def test_hub_channel_key_can_be_renamed(set_core_config: SetCoreConfigCallable) -> None:
|
||||
"""A hub that names its channel `pin` passes channel_key and gets the same check."""
|
||||
validate = output.final_validate_unique_channel(
|
||||
platform="fake", hub_key="fake_id", channel_key=CONF_PIN
|
||||
)
|
||||
entries = [
|
||||
{CONF_PLATFORM: "fake", "fake_id": ID("a"), CONF_PIN: pin} for pin in (3, 4, 3)
|
||||
]
|
||||
full = Config()
|
||||
full["output"] = entries
|
||||
set_core_config(PlatformFramework.ESP32_IDF, full_config=full)
|
||||
validate(entries[1])
|
||||
with pytest.raises(cv.Invalid, match="Channel '3' of 'a' is already used"):
|
||||
validate(entries[2])
|
||||
Reference in new issue
Block a user