From d3734aae9daf44181934f0d76405bfc65df73f46 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Fri, 9 Oct 2020 03:36:54 -0400 Subject: [PATCH] Allow custom_serializer to recognize cv.string and cv.boolean to make config schema more reusable (#41532) --- homeassistant/helpers/config_validation.py | 6 ++++++ tests/helpers/test_config_validation.py | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index ad514e044aa..0a65fa96354 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -828,6 +828,12 @@ def custom_serializer(schema: Any) -> Any: if schema is positive_time_period_dict: return {"type": "positive_time_period_dict"} + if schema is string: + return {"type": "string"} + + if schema is boolean: + return {"type": "boolean"} + if isinstance(schema, multi_select): return {"type": "multi_select", "options": schema.options} diff --git a/tests/helpers/test_config_validation.py b/tests/helpers/test_config_validation.py index f7d7acbb08e..d8956c143df 100644 --- a/tests/helpers/test_config_validation.py +++ b/tests/helpers/test_config_validation.py @@ -571,6 +571,27 @@ def test_multi_select_in_serializer(): } +def test_boolean_in_serializer(): + """Test boolean with custom_serializer.""" + assert cv.custom_serializer(cv.boolean) == { + "type": "boolean", + } + + +def test_string_in_serializer(): + """Test string with custom_serializer.""" + assert cv.custom_serializer(cv.string) == { + "type": "string", + } + + +def test_positive_time_period_dict_in_serializer(): + """Test positive_time_period_dict with custom_serializer.""" + assert cv.custom_serializer(cv.positive_time_period_dict) == { + "type": "positive_time_period_dict", + } + + @pytest.fixture def schema(): """Create a schema used for testing deprecation."""