Modernize RainMachine config flow (#32131)
* Modernize RainMachine config flow * Update strings
This commit is contained in:
parent
f7e336eaa6
commit
edf44f4158
4 changed files with 46 additions and 16 deletions
|
@ -1,7 +1,4 @@
|
|||
"""Config flow to configure the RainMachine component."""
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
from regenmaschine import login
|
||||
from regenmaschine.errors import RainMachineError
|
||||
import voluptuous as vol
|
||||
|
@ -29,8 +26,7 @@ def configured_instances(hass):
|
|||
)
|
||||
|
||||
|
||||
@config_entries.HANDLERS.register(DOMAIN)
|
||||
class RainMachineFlowHandler(config_entries.ConfigFlow):
|
||||
class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a RainMachine config flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
@ -38,16 +34,19 @@ class RainMachineFlowHandler(config_entries.ConfigFlow):
|
|||
|
||||
def __init__(self):
|
||||
"""Initialize the config flow."""
|
||||
self.data_schema = OrderedDict()
|
||||
self.data_schema[vol.Required(CONF_IP_ADDRESS)] = str
|
||||
self.data_schema[vol.Required(CONF_PASSWORD)] = str
|
||||
self.data_schema[vol.Optional(CONF_PORT, default=DEFAULT_PORT)] = int
|
||||
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=vol.Schema(self.data_schema),
|
||||
data_schema=self.data_schema,
|
||||
errors=errors if errors else {},
|
||||
)
|
||||
|
||||
|
@ -57,12 +56,11 @@ class RainMachineFlowHandler(config_entries.ConfigFlow):
|
|||
|
||||
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()
|
||||
|
||||
if user_input[CONF_IP_ADDRESS] in configured_instances(self.hass):
|
||||
return await self._show_form({CONF_IP_ADDRESS: "identifier_exists"})
|
||||
await self.async_set_unique_id(user_input[CONF_IP_ADDRESS])
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
websession = aiohttp_client.async_get_clientsession(self.hass)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue