Add Mill config flow (#35136)
* Mill config, wip * add tests * fix merge * update tests * unique id * Mill strings * mill config flow * mill config flow * test import * test import * req * ccoverage * Apply suggestions from code review Co-authored-by: J. Nick Koston <nick@koston.org> * style * Apply suggestions from code review Co-authored-by: Paulus Schoutsen <balloob@gmail.com> * update strings * add test Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
8050d8555e
commit
f302c6fd65
9 changed files with 213 additions and 11 deletions
55
homeassistant/components/mill/config_flow.py
Normal file
55
homeassistant/components/mill/config_flow.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
"""Adds config flow for Mill integration."""
|
||||
import logging
|
||||
|
||||
from mill import Mill
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DOMAIN # pylint:disable=unused-import
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DATA_SCHEMA = vol.Schema(
|
||||
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
|
||||
)
|
||||
|
||||
|
||||
class MillConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Mill integration."""
|
||||
|
||||
VERSION = 1
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle the initial step."""
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=DATA_SCHEMA, errors={},
|
||||
)
|
||||
|
||||
username = user_input[CONF_USERNAME].replace(" ", "")
|
||||
password = user_input[CONF_PASSWORD].replace(" ", "")
|
||||
|
||||
mill_data_connection = Mill(
|
||||
username, password, websession=async_get_clientsession(self.hass),
|
||||
)
|
||||
|
||||
errors = {}
|
||||
|
||||
if not await mill_data_connection.connect():
|
||||
errors["connection_error"] = "connection_error"
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=DATA_SCHEMA, errors=errors,
|
||||
)
|
||||
|
||||
unique_id = username
|
||||
|
||||
await self.async_set_unique_id(unique_id)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return self.async_create_entry(
|
||||
title=unique_id, data={CONF_USERNAME: username, CONF_PASSWORD: password},
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue