Improve config flow type hints in cast (#124861)

This commit is contained in:
epenet 2024-08-31 16:38:06 +02:00 committed by GitHub
parent 65f007ace7
commit 9da5dd0090
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 14 deletions

View File

@ -63,7 +63,9 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
return await self.async_step_confirm()
async def async_step_config(self, user_input=None):
async def async_step_config(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Confirm the setup."""
errors = {}
data = {CONF_KNOWN_HOSTS: self._known_hosts}
@ -90,7 +92,9 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
step_id="config", data_schema=vol.Schema(fields), errors=errors
)
async def async_step_confirm(self, user_input=None):
async def async_step_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Confirm the setup."""
data = self._get_data()
@ -116,13 +120,15 @@ class CastOptionsFlowHandler(OptionsFlow):
self.config_entry = config_entry
self.updated_config: dict[str, Any] = {}
async def async_step_init(self, user_input=None):
async def async_step_init(self, user_input: None = None) -> ConfigFlowResult:
"""Manage the Google Cast options."""
return await self.async_step_basic_options()
async def async_step_basic_options(self, user_input=None):
async def async_step_basic_options(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Manage the Google Cast options."""
errors = {}
errors: dict[str, str] = {}
current_config = self.config_entry.data
if user_input is not None:
bad_hosts, known_hosts = _string_to_list(
@ -139,9 +145,9 @@ class CastOptionsFlowHandler(OptionsFlow):
self.hass.config_entries.async_update_entry(
self.config_entry, data=self.updated_config
)
return self.async_create_entry(title="", data=None)
return self.async_create_entry(title="", data={})
fields = {}
fields: dict[vol.Marker, type[str]] = {}
suggested_value = _list_to_string(current_config.get(CONF_KNOWN_HOSTS))
_add_with_suggestion(fields, CONF_KNOWN_HOSTS, suggested_value)
@ -152,9 +158,11 @@ class CastOptionsFlowHandler(OptionsFlow):
last_step=not self.show_advanced_options,
)
async def async_step_advanced_options(self, user_input=None):
async def async_step_advanced_options(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Manage the Google Cast options."""
errors = {}
errors: dict[str, str] = {}
if user_input is not None:
bad_cec, ignore_cec = _string_to_list(
user_input.get(CONF_IGNORE_CEC, ""), IGNORE_CEC_SCHEMA
@ -169,9 +177,9 @@ class CastOptionsFlowHandler(OptionsFlow):
self.hass.config_entries.async_update_entry(
self.config_entry, data=self.updated_config
)
return self.async_create_entry(title="", data=None)
return self.async_create_entry(title="", data={})
fields = {}
fields: dict[vol.Marker, type[str]] = {}
current_config = self.config_entry.data
suggested_value = _list_to_string(current_config.get(CONF_UUID))
_add_with_suggestion(fields, CONF_UUID, suggested_value)
@ -204,5 +212,7 @@ def _string_to_list(string, schema):
return invalid, items
def _add_with_suggestion(fields, key, suggested_value):
def _add_with_suggestion(
fields: dict[vol.Marker, type[str]], key: str, suggested_value: str
) -> None:
fields[vol.Optional(key, description={"suggested_value": suggested_value})] = str

View File

@ -250,7 +250,7 @@ async def test_option_flow(hass: HomeAssistant, parameter_data) -> None:
user_input=user_input_dict,
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] is None
assert result["data"] == {}
for other_param in advanced_parameters:
if other_param == parameter:
continue
@ -264,7 +264,7 @@ async def test_option_flow(hass: HomeAssistant, parameter_data) -> None:
user_input={"known_hosts": ""},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] is None
assert result["data"] == {}
expected_data = {**orig_data, "known_hosts": []}
if parameter in advanced_parameters:
expected_data[parameter] = updated