From 0b5851e4039c4f5dcc5f66101b319521b658d18a Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Sun, 22 Nov 2020 06:22:47 -0700 Subject: [PATCH] Clean up RainMachine config entry (#43508) --- .../components/rainmachine/config_flow.py | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/rainmachine/config_flow.py b/homeassistant/components/rainmachine/config_flow.py index 49eba95d047..80540491ee7 100644 --- a/homeassistant/components/rainmachine/config_flow.py +++ b/homeassistant/components/rainmachine/config_flow.py @@ -15,6 +15,14 @@ from .const import ( # pylint: disable=unused-import DOMAIN, ) +DATA_SCHEMA = vol.Schema( + { + vol.Required(CONF_IP_ADDRESS): str, + vol.Required(CONF_PASSWORD): str, + vol.Optional(CONF_PORT, default=DEFAULT_PORT): int, + } +) + class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """Handle a RainMachine config flow.""" @@ -22,24 +30,6 @@ class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): VERSION = 1 CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL - def __init__(self): - """Initialize the config flow.""" - self.data_schema = vol.Schema( - { - vol.Required(CONF_IP_ADDRESS): str, - vol.Required(CONF_PASSWORD): str, - vol.Optional(CONF_PORT, default=DEFAULT_PORT): int, - } - ) - - async def _show_form(self, errors=None): - """Show the form to the user.""" - return self.async_show_form( - step_id="user", - data_schema=self.data_schema, - errors=errors if errors else {}, - ) - @staticmethod @callback def async_get_options_flow(config_entry): @@ -49,7 +39,9 @@ class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_user(self, user_input=None): """Handle the start of the config flow.""" if not user_input: - return await self._show_form() + return self.async_show_form( + step_id="user", data_schema=DATA_SCHEMA, errors={} + ) await self.async_set_unique_id(user_input[CONF_IP_ADDRESS]) self._abort_if_unique_id_configured() @@ -65,7 +57,11 @@ class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): ssl=user_input.get(CONF_SSL, True), ) except RainMachineError: - return await self._show_form({CONF_PASSWORD: "invalid_auth"}) + return self.async_show_form( + step_id="user", + data_schema=DATA_SCHEMA, + errors={CONF_PASSWORD: "invalid_auth"}, + ) # Unfortunately, RainMachine doesn't provide a way to refresh the # access token without using the IP address and password, so we have to