Use VolDictType to improve schema typing (#120417)

This commit is contained in:
Marc Mueller 2024-06-25 15:15:59 +02:00 committed by GitHub
parent aa05f73210
commit bcd1243686
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 54 additions and 37 deletions

View file

@ -22,6 +22,7 @@ from homeassistant.const import CONF_DEVICE
from homeassistant.core import callback
from homeassistant.helpers import selector
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import VolDictType
from .const import (
CONF_BAUD_RATE,
@ -153,7 +154,7 @@ class MySensorsConfigFlowHandler(ConfigFlow, domain=DOMAIN):
return self._async_create_entry(user_input)
user_input = user_input or {}
schema = {
schema: VolDictType = {
vol.Required(
CONF_DEVICE, default=user_input.get(CONF_DEVICE, "/dev/ttyACM0")
): str,
@ -164,9 +165,8 @@ class MySensorsConfigFlowHandler(ConfigFlow, domain=DOMAIN):
}
schema.update(_get_schema_common(user_input))
schema = vol.Schema(schema)
return self.async_show_form(
step_id="gw_serial", data_schema=schema, errors=errors
step_id="gw_serial", data_schema=vol.Schema(schema), errors=errors
)
async def async_step_gw_tcp(
@ -182,7 +182,7 @@ class MySensorsConfigFlowHandler(ConfigFlow, domain=DOMAIN):
return self._async_create_entry(user_input)
user_input = user_input or {}
schema = {
schema: VolDictType = {
vol.Required(
CONF_DEVICE, default=user_input.get(CONF_DEVICE, "127.0.0.1")
): str,
@ -192,8 +192,9 @@ class MySensorsConfigFlowHandler(ConfigFlow, domain=DOMAIN):
}
schema.update(_get_schema_common(user_input))
schema = vol.Schema(schema)
return self.async_show_form(step_id="gw_tcp", data_schema=schema, errors=errors)
return self.async_show_form(
step_id="gw_tcp", data_schema=vol.Schema(schema), errors=errors
)
def _check_topic_exists(self, topic: str) -> bool:
for other_config in self._async_current_entries():
@ -243,7 +244,7 @@ class MySensorsConfigFlowHandler(ConfigFlow, domain=DOMAIN):
return self._async_create_entry(user_input)
user_input = user_input or {}
schema = {
schema: VolDictType = {
vol.Required(
CONF_TOPIC_IN_PREFIX, default=user_input.get(CONF_TOPIC_IN_PREFIX, "")
): str,
@ -254,9 +255,8 @@ class MySensorsConfigFlowHandler(ConfigFlow, domain=DOMAIN):
}
schema.update(_get_schema_common(user_input))
schema = vol.Schema(schema)
return self.async_show_form(
step_id="gw_mqtt", data_schema=schema, errors=errors
step_id="gw_mqtt", data_schema=vol.Schema(schema), errors=errors
)
@callback