-
-
Notifications
You must be signed in to change notification settings - Fork 37.1k
Config flow for Velux integration #49348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
bramstroker
wants to merge
15
commits into
home-assistant:dev
from
bramstroker:feature/velux-config-flow2
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c1dc20f
First draft implementing config flow for velux
bramstroker 45fc39c
Rename config flow, add string and translations
bramstroker 0cf4ece
Import configuration from yaml
bramstroker b0b09dc
Fix linting
bramstroker cd98275
Fix config is imported only once for the same host
bramstroker eb3a78e
Update homeassistant/components/velux/config_flow.py
bramstroker 17c7e42
Remove translation files from git
bramstroker 2400cf2
Merge branch 'feature/velux-config-flow2' of github.com:bramstroker/c…
bramstroker e937327
Fix typo
bramstroker 702ded2
Extend exception handling
bramstroker 9be4604
Extend exception handling
bramstroker 0c5a66d
Remove unused declaration
bramstroker b5f294a
Remove unnessary constant. Register a veluxModule per config entry in…
bramstroker 8e041d5
Re-add config schema
bramstroker 6f87d8e
Prevent setting up integration for same host twice
bramstroker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """Config flow for velux integration.""" | ||
| import logging | ||
|
|
||
| from pyvlx import PyVLX, PyVLXException | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant import config_entries | ||
| from homeassistant.const import CONF_HOST, CONF_PASSWORD | ||
|
|
||
| from .const import DOMAIN | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| DATA_SCHEMA = vol.Schema( | ||
| {vol.Required(CONF_HOST): str, vol.Required(CONF_PASSWORD): str} | ||
| ) | ||
|
|
||
|
|
||
| class VeluxConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | ||
| """Handle a config flow for velux.""" | ||
|
|
||
| VERSION = 1 | ||
| CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL | ||
|
|
||
| async def async_step_user(self, user_input=None): | ||
| """Handle the initial step.""" | ||
| errors = {} | ||
| if user_input is not None: | ||
| try: | ||
bramstroker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| host = user_input[CONF_HOST] | ||
| password = user_input[CONF_PASSWORD] | ||
|
|
||
| await self.async_set_unique_id(host) | ||
| self._abort_if_unique_id_configured() | ||
|
|
||
| pyvlx = PyVLX(host=host, password=password) | ||
| await pyvlx.connect() | ||
|
|
||
| await pyvlx.disconnect() | ||
|
|
||
| return self.async_create_entry( | ||
| title=host, | ||
| data=user_input, | ||
| ) | ||
| except PyVLXException as ex: | ||
| _LOGGER.exception("Unable to connect to Velux gateway: %s", ex) | ||
| errors["base"] = "invalid_auth" | ||
bramstroker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| except Exception as ex: # pylint: disable=broad-except | ||
| _LOGGER.exception("Unable to connect to Velux gateway: %s", ex) | ||
| errors["base"] = "unknown" | ||
|
|
||
| return self.async_show_form( | ||
| step_id="user", data_schema=DATA_SCHEMA, errors=errors | ||
| ) | ||
|
|
||
| async def async_step_import(self, import_config): | ||
| """Import config from configuration.yaml.""" | ||
| self._async_abort_entries_match({CONF_HOST: import_config[CONF_HOST]}) | ||
|
|
||
| return await self.async_step_user(import_config) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| """Const for Velux.""" | ||
|
|
||
| DOMAIN = "velux" | ||
| CONFIG_KEY_MODULE = "velux_module" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "config": { | ||
| "step": { | ||
| "user": { | ||
| "title": "Setup your Velux KLF 200", | ||
| "data": { | ||
| "host": "[%key:common::config_flow::data::host%]", | ||
| "password": "[%key:common::config_flow::data::password%]" | ||
| } | ||
| } | ||
| }, | ||
| "error": { | ||
| "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]" | ||
| } | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No newline at end of file. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,6 +256,7 @@ | |
| "upcloud", | ||
| "upnp", | ||
| "velbus", | ||
| "velux", | ||
| "vera", | ||
| "verisure", | ||
| "vesync", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Tests for the Velux Component.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """Test the Velux config flow.""" | ||
| from unittest.mock import patch | ||
|
|
||
| from pyvlx import PyVLXException | ||
|
|
||
| from homeassistant import config_entries, setup | ||
| from homeassistant.components.velux import DOMAIN | ||
| from homeassistant.const import CONF_HOST, CONF_PASSWORD | ||
|
|
||
| CONFIG = {DOMAIN: {CONF_HOST: "192.168.0.20", CONF_PASSWORD: "password"}} | ||
|
|
||
|
|
||
| async def test_form(hass): | ||
| """Test we get the form.""" | ||
| return | ||
| await setup.async_setup_component(hass, "persistent_notification", {}) | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, context={"source": config_entries.SOURCE_USER} | ||
| ) | ||
| assert result["type"] == "form" | ||
| assert result["errors"] == {} | ||
|
|
||
|
|
||
| async def test_gateway_connect_exception(hass): | ||
| """Test a error message is displayed when connection to KLF gateway fails.""" | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, context={"source": config_entries.SOURCE_USER} | ||
| ) | ||
|
|
||
| with patch( | ||
| "pyvlx.PyVLX.connect", | ||
| side_effect=PyVLXException("Login to KLF 200 failed, check credentials"), | ||
| ): | ||
| result2 = await hass.config_entries.flow.async_configure( | ||
| result["flow_id"], CONFIG[DOMAIN] | ||
| ) | ||
|
|
||
| assert result2["type"] == "form" | ||
| assert result2["errors"] == {"base": "invalid_auth"} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async_start()may fail (see #34844), in which case you should raise ConfigEntryNotReady. That would really resolve #34844, I guess. The issue was closed due to inactivity.