core/homeassistant/components/plum_lightpad/config_flow.py

66 lines
2.1 KiB
Python
Raw Normal View History

Add Plum Lightpad config flow (#36802) * add support for config flow for Plum Lightpad integration * add support for config flow for Plum Lightpad integration (remove unintended change to requirements_test_all.txt) * add support for config flow for Plum Lightpad integration (fix lint issues) * add support for config flow for Plum Lightpad integration (PR feedback) * add support for config flow for Plum Lightpad integration (fix lint) * Update homeassistant/components/plum_lightpad/__init__.py use debug instead of info for logging Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use generated references instead of hard-coded strings Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use references instead of hard-coded string Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing translated title per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * remove unnecessary deepcopy * remove unnecessary logging warning, since ignoring is expected for configuration.yaml scenario * switch to hass.loop.create_task per PR feedback * show login errors when configuring integration via UI (PR feedback) * disable wrongly flag pylint violation * add except handler to handle connection errors when setting up config flow entry * address PR feedback regarding exception handling * Update homeassistant/components/plum_lightpad/config_flow.py use helper instead of custom code/message-id Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-06-24 03:40:11 +00:00
"""Config flow for Plum Lightpad."""
2021-03-18 12:21:46 +00:00
from __future__ import annotations
Add Plum Lightpad config flow (#36802) * add support for config flow for Plum Lightpad integration * add support for config flow for Plum Lightpad integration (remove unintended change to requirements_test_all.txt) * add support for config flow for Plum Lightpad integration (fix lint issues) * add support for config flow for Plum Lightpad integration (PR feedback) * add support for config flow for Plum Lightpad integration (fix lint) * Update homeassistant/components/plum_lightpad/__init__.py use debug instead of info for logging Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use generated references instead of hard-coded strings Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use references instead of hard-coded string Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing translated title per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * remove unnecessary deepcopy * remove unnecessary logging warning, since ignoring is expected for configuration.yaml scenario * switch to hass.loop.create_task per PR feedback * show login errors when configuring integration via UI (PR feedback) * disable wrongly flag pylint violation * add except handler to handle connection errors when setting up config flow entry * address PR feedback regarding exception handling * Update homeassistant/components/plum_lightpad/config_flow.py use helper instead of custom code/message-id Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-06-24 03:40:11 +00:00
import logging
from typing import Any
Add Plum Lightpad config flow (#36802) * add support for config flow for Plum Lightpad integration * add support for config flow for Plum Lightpad integration (remove unintended change to requirements_test_all.txt) * add support for config flow for Plum Lightpad integration (fix lint issues) * add support for config flow for Plum Lightpad integration (PR feedback) * add support for config flow for Plum Lightpad integration (fix lint) * Update homeassistant/components/plum_lightpad/__init__.py use debug instead of info for logging Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use generated references instead of hard-coded strings Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use references instead of hard-coded string Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing translated title per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * remove unnecessary deepcopy * remove unnecessary logging warning, since ignoring is expected for configuration.yaml scenario * switch to hass.loop.create_task per PR feedback * show login errors when configuring integration via UI (PR feedback) * disable wrongly flag pylint violation * add except handler to handle connection errors when setting up config flow entry * address PR feedback regarding exception handling * Update homeassistant/components/plum_lightpad/config_flow.py use helper instead of custom code/message-id Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-06-24 03:40:11 +00:00
from aiohttp import ContentTypeError
from requests.exceptions import ConnectTimeout, HTTPError
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.typing import ConfigType
Add Plum Lightpad config flow (#36802) * add support for config flow for Plum Lightpad integration * add support for config flow for Plum Lightpad integration (remove unintended change to requirements_test_all.txt) * add support for config flow for Plum Lightpad integration (fix lint issues) * add support for config flow for Plum Lightpad integration (PR feedback) * add support for config flow for Plum Lightpad integration (fix lint) * Update homeassistant/components/plum_lightpad/__init__.py use debug instead of info for logging Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use generated references instead of hard-coded strings Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use references instead of hard-coded string Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing translated title per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * remove unnecessary deepcopy * remove unnecessary logging warning, since ignoring is expected for configuration.yaml scenario * switch to hass.loop.create_task per PR feedback * show login errors when configuring integration via UI (PR feedback) * disable wrongly flag pylint violation * add except handler to handle connection errors when setting up config flow entry * address PR feedback regarding exception handling * Update homeassistant/components/plum_lightpad/config_flow.py use helper instead of custom code/message-id Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-06-24 03:40:11 +00:00
from .const import DOMAIN
Add Plum Lightpad config flow (#36802) * add support for config flow for Plum Lightpad integration * add support for config flow for Plum Lightpad integration (remove unintended change to requirements_test_all.txt) * add support for config flow for Plum Lightpad integration (fix lint issues) * add support for config flow for Plum Lightpad integration (PR feedback) * add support for config flow for Plum Lightpad integration (fix lint) * Update homeassistant/components/plum_lightpad/__init__.py use debug instead of info for logging Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use generated references instead of hard-coded strings Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use references instead of hard-coded string Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing translated title per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * remove unnecessary deepcopy * remove unnecessary logging warning, since ignoring is expected for configuration.yaml scenario * switch to hass.loop.create_task per PR feedback * show login errors when configuring integration via UI (PR feedback) * disable wrongly flag pylint violation * add except handler to handle connection errors when setting up config flow entry * address PR feedback regarding exception handling * Update homeassistant/components/plum_lightpad/config_flow.py use helper instead of custom code/message-id Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-06-24 03:40:11 +00:00
from .utils import load_plum
_LOGGER = logging.getLogger(__name__)
class PlumLightpadConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Config flow for Plum Lightpad integration."""
VERSION = 1
def _show_form(self, errors=None):
schema = {
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str,
}
return self.async_show_form(
2020-08-27 11:56:20 +00:00
step_id="user",
data_schema=vol.Schema(schema),
errors=errors or {},
Add Plum Lightpad config flow (#36802) * add support for config flow for Plum Lightpad integration * add support for config flow for Plum Lightpad integration (remove unintended change to requirements_test_all.txt) * add support for config flow for Plum Lightpad integration (fix lint issues) * add support for config flow for Plum Lightpad integration (PR feedback) * add support for config flow for Plum Lightpad integration (fix lint) * Update homeassistant/components/plum_lightpad/__init__.py use debug instead of info for logging Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use generated references instead of hard-coded strings Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use references instead of hard-coded string Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing translated title per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * remove unnecessary deepcopy * remove unnecessary logging warning, since ignoring is expected for configuration.yaml scenario * switch to hass.loop.create_task per PR feedback * show login errors when configuring integration via UI (PR feedback) * disable wrongly flag pylint violation * add except handler to handle connection errors when setting up config flow entry * address PR feedback regarding exception handling * Update homeassistant/components/plum_lightpad/config_flow.py use helper instead of custom code/message-id Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-06-24 03:40:11 +00:00
)
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
Add Plum Lightpad config flow (#36802) * add support for config flow for Plum Lightpad integration * add support for config flow for Plum Lightpad integration (remove unintended change to requirements_test_all.txt) * add support for config flow for Plum Lightpad integration (fix lint issues) * add support for config flow for Plum Lightpad integration (PR feedback) * add support for config flow for Plum Lightpad integration (fix lint) * Update homeassistant/components/plum_lightpad/__init__.py use debug instead of info for logging Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use generated references instead of hard-coded strings Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use references instead of hard-coded string Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing translated title per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * remove unnecessary deepcopy * remove unnecessary logging warning, since ignoring is expected for configuration.yaml scenario * switch to hass.loop.create_task per PR feedback * show login errors when configuring integration via UI (PR feedback) * disable wrongly flag pylint violation * add except handler to handle connection errors when setting up config flow entry * address PR feedback regarding exception handling * Update homeassistant/components/plum_lightpad/config_flow.py use helper instead of custom code/message-id Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-06-24 03:40:11 +00:00
"""Handle a flow initialized by the user or redirected to by import."""
if not user_input:
return self._show_form()
username = user_input[CONF_USERNAME]
password = user_input[CONF_PASSWORD]
# load Plum just so we know username/password work
try:
await load_plum(username, password, self.hass)
except (ContentTypeError, ConnectTimeout, HTTPError) as ex:
_LOGGER.error("Unable to connect/authenticate to Plum cloud: %s", str(ex))
return self._show_form({"base": "cannot_connect"})
await self.async_set_unique_id(username)
self._abort_if_unique_id_configured()
return self.async_create_entry(
title=username, data={CONF_USERNAME: username, CONF_PASSWORD: password}
)
async def async_step_import(self, import_config: ConfigType | None) -> FlowResult:
Add Plum Lightpad config flow (#36802) * add support for config flow for Plum Lightpad integration * add support for config flow for Plum Lightpad integration (remove unintended change to requirements_test_all.txt) * add support for config flow for Plum Lightpad integration (fix lint issues) * add support for config flow for Plum Lightpad integration (PR feedback) * add support for config flow for Plum Lightpad integration (fix lint) * Update homeassistant/components/plum_lightpad/__init__.py use debug instead of info for logging Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use generated references instead of hard-coded strings Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json switch to use references instead of hard-coded string Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing translated title per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/plum_lightpad/strings.json removing per suggestion Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * remove unnecessary deepcopy * remove unnecessary logging warning, since ignoring is expected for configuration.yaml scenario * switch to hass.loop.create_task per PR feedback * show login errors when configuring integration via UI (PR feedback) * disable wrongly flag pylint violation * add except handler to handle connection errors when setting up config flow entry * address PR feedback regarding exception handling * Update homeassistant/components/plum_lightpad/config_flow.py use helper instead of custom code/message-id Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-06-24 03:40:11 +00:00
"""Import a config entry from configuration.yaml."""
return await self.async_step_user(import_config)