diff --git a/esphome/yaml_util.py b/esphome/yaml_util.py index 19cb775a50..5355d03e9c 100644 --- a/esphome/yaml_util.py +++ b/esphome/yaml_util.py @@ -1013,7 +1013,7 @@ class ESPHomeDumper(yaml.SafeDumper): return self.represent_secret(value) return self.represent_scalar(tag="tag:yaml.org,2002:str", value=str(value)) - def represent_sensitive(self, value): + def represent_sensitive(self, value: SensitiveStr) -> yaml.ScalarNode: # ``!secret`` references win: keep the original representation so the # dumped YAML round-trips back to ``!secret name`` instead of leaking # the resolved value. diff --git a/tests/unit_tests/test_config_validation.py b/tests/unit_tests/test_config_validation.py index f45efeb20a..74d9a5047a 100644 --- a/tests/unit_tests/test_config_validation.py +++ b/tests/unit_tests/test_config_validation.py @@ -27,6 +27,7 @@ from esphome.const import ( SCHEDULER_DONT_RUN, ) from esphome.core import CORE, HexInt, Lambda +from esphome.yaml_util import SensitiveStr def test_check_not_templatable__invalid(): @@ -146,8 +147,6 @@ def test_sensitive__custom_inner_delegates_validation() -> None: def test_sensitive__wraps_string_result_in_sensitive_str() -> None: - from esphome.yaml_util import SensitiveStr - validator = config_validation.sensitive() result = validator("hunter2") @@ -157,8 +156,6 @@ def test_sensitive__wraps_string_result_in_sensitive_str() -> None: def test_sensitive__does_not_double_tag_already_sensitive() -> None: - from esphome.yaml_util import SensitiveStr - # If the inner validator already returns a SensitiveStr (e.g., nested # cv.sensitive wrappers), re-tagging is a no-op rather than a new # SensitiveStr around the same value.