I would like to use following Voluptuous schema in the config flow of an integration which I’m writing:
import voluptuous as vol
from voluptuous.validators import All
from homeassistant.helpers import config_validation as cv
from homeassistant.const import CONF_IP_ADDRESS
CONF_API_SECRET_KEY = "api_secret_key"
CONF_API_AUTH_KEY = "api_auth_key"
STEP_USER_SETTINGS_DEFAULT_SCHEMA = vol.Schema(
{
vol.Required(CONF_IP_ADDRESS): cv.matches_regex(r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"),
vol.Required(CONF_API_SECRET_KEY): All(vol.Upper, cv.matches_regex(r"[0-9A-Z]{64}")),
vol.Required(CONF_API_AUTH_KEY): All(vol.Upper, cv.matches_regex(r"[0-9A-Z]{64}"))
},
extra=REMOVE_EXTRA
)
When I want to show the form based on the schema above using following code snippet, Home Assistant raises the error bellow for which I can’t find the reason:
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the user step."""
errors = {}
# ...
return self.async_show_form(
step_id="user_settings_default", data_schema=STEP_USER_SETTINGS_DEFAULT_SCHEMA, errors=errors
)
2021-10-17 10:51:13 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/root/Development/GitHub/ivgg-me/home-assistant-core/venv/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
resp = await self._request_handler(request)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/venv/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
resp = await handler(request)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/venv/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/components/http/security_filter.py", line 56, in security_filter_middleware
return await handler(request)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
return await handler(request)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/components/http/ban.py", line 74, in ban_middleware
return await handler(request)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/components/http/auth.py", line 135, in auth_middleware
return await handler(request)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/components/http/view.py", line 131, in handle
result = await result
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/components/config/config_entries.py", line 128, in post
return await super().post(request)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/components/http/data_validator.py", line 63, in wrapper
result = await method(view, request, *args, **kwargs)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/helpers/data_entry_flow.py", line 84, in post
result = self._prepare_result_json(result)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/components/config/config_entries.py", line 132, in _prepare_result_json
return _prepare_config_flow_result_json(result, super()._prepare_result_json)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/components/config/config_entries.py", line 103, in _prepare_config_flow_result_json
return prepare_result_json(result)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/homeassistant/helpers/data_entry_flow.py", line 45, in _prepare_result_json
data["data_schema"] = voluptuous_serialize.convert(
File "/root/Development/GitHub/ivgg-me/home-assistant-core/venv/lib/python3.8/site-packages/voluptuous_serialize/__init__.py", line 39, in convert
pval = convert(value, custom_serializer=custom_serializer)
File "/root/Development/GitHub/ivgg-me/home-assistant-core/venv/lib/python3.8/site-packages/voluptuous_serialize/__init__.py", line 112, in convert
raise ValueError('Unable to convert schema: {}'.format(schema))
ValueError: Unable to convert schema: <function matches_regex.<locals>.validator at 0x7fdd0415c3a0>
Can someone explain the reason for the error. Thank you!