-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Add Totalconnect config flow #32126
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
Merged
bdraco
merged 111 commits into
home-assistant:dev
from
austinmroczek:totalconnect-config-flow
Apr 13, 2020
Merged
Add Totalconnect config flow #32126
Changes from all commits
Commits
Show all changes
111 commits
Select commit
Hold shift + click to select a range
54dbdd6
Merge pull request #1 from home-assistant/dev
austinmroczek 90483d2
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
austinmroczek 51aa773
Bump skybellpy to 0.4.0
austinmroczek e18b4d2
Bump skybellpy to 0.4.0 in requirements_all.txt
austinmroczek d74156a
Added extra states for STATE_ALARM_TRIGGERED to allow users to know if
austinmroczek ad1cdb3
Merge branch 'dev' of https://github.com/austinmroczek/home-assistant…
austinmroczek 5c5c052
Merge pull request #2 from home-assistant/dev
austinmroczek abcc85a
Fix const import
austinmroczek d303091
Fix const import
austinmroczek 73f38eb
Fix const imports
austinmroczek 5bec7e4
Bump total-connect-client to 0.26.
austinmroczek 4862ff5
Catch details of alarm trigger in state attributes.
austinmroczek 5068345
Merge branch 'dev' of
austinmroczek e7a13d4
Change state_attributes() to device_state_attributes()
austinmroczek 53f20fb
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek 4bee662
Merge branch 'dev' of https://github.com/austinmroczek/home-assistant…
austinmroczek 6a50e80
Move totalconnect component toward being a multi-platform integration…
austinmroczek 37c34cf
Merge pull request #4 from home-assistant/dev
austinmroczek ad4c4c9
add missing total-connect alarm state mappings
austinmroczek e589317
Made recommended changes of MartinHjelmare at
austinmroczek aa22440
Update __init__.py
austinmroczek 5cbfc98
Updates per MartinHjelmare comments
austinmroczek eb440cc
flake8/pydocstyle fixes
austinmroczek 69425d7
Merge branch 'dev' of https://github.com/austinmroczek/home-assistant…
austinmroczek 117ed1b
removed . at end of log message
austinmroczek 14d3e2e
added blank line between logging and voluptuous
austinmroczek cd2b563
more fixes
austinmroczek 2295b7c
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek db6336b
Adding totalconnect zones as HA binary_sensors
austinmroczek e9a0e69
fix manifest.json
austinmroczek 1bc164d
flake8/pydocstyle fixes. Added codeowner.
austinmroczek 932e5b0
Update formatting per @springstan guidance.
austinmroczek bf7be02
Fixed pylint
austinmroczek f855154
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek fcadf80
Add zone ID to log message for easier troubleshooting
austinmroczek a68576e
Account for bypassed zones in update()
austinmroczek a15b4de
More status handling fixes.
austinmroczek ea1510f
Fixed flake8 error
austinmroczek 7f7ec1c
Another attempt at black/isort fixes.
austinmroczek 4de1bcf
Bump total-connect-client to 0.50. Simplify code using new functions in
austinmroczek b66ba1f
Fix manifest file
austinmroczek 4027382
Another manifest fix
austinmroczek 656e88d
one more manifest fix
austinmroczek eca1045
more manifest changes.
austinmroczek 750fc0b
sync up
austinmroczek fd927a3
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek 10f1642
Merge branch 'dev' of https://github.com/austinmroczek/home-assistant…
austinmroczek 25f530b
fix indent
austinmroczek d9700f8
one more pylint fix
austinmroczek 81f4cef
Hopefully the last pylint fix
austinmroczek 6f0e779
make variable names understandable
austinmroczek c654941
create and fill dict in one step
austinmroczek 1c32671
Fix name and attributes
austinmroczek 35d3085
rename to logical variable in alarm_control_panel
austinmroczek c9b208d
Remove location_name from alarm_control_panel attributes since it is
austinmroczek 10b555e
Multiple fixes to improve code per @springstan suggestions
austinmroczek 19b0c63
Update homeassistant/components/totalconnect/binary_sensor.py
austinmroczek 471b01a
Multiple changes per @MartinHjelmare review
austinmroczek ef06453
simplify alarm adding
austinmroczek 0c1234e
Fix binary_sensor.py is_on
austinmroczek 26f0bcd
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek f9e6a69
Move DOMAIN to .const in line with examples.
austinmroczek 464f3f8
Move to async_setup
austinmroczek 28f4bd4
Simplify code using new features of total-connect-client 0.51
austinmroczek d3c8d24
First crack at config flow for totalconnect
austinmroczek 0260a34
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek c798549
bump totalconnect to 0.52
austinmroczek e37fb88
use client.is_logged_in() to avoid total-connect-client details.
austinmroczek 97590a0
updated generated/config_flow.py
austinmroczek 6c192e4
use is_logged_in()
austinmroczek 139c4f5
Hopefully final touches for config flow
austinmroczek 425b890
Add tests for config flow
austinmroczek bcdc060
Updated requirements for test
austinmroczek b612388
Fixes to test_config_flow
austinmroczek 15ab17f
Merge remote-tracking branch 'upstream/dev' into totalconnect-config-…
austinmroczek e6e8325
Removed leftover comments and code
austinmroczek 1feab1e
fix const.py flake8 error
austinmroczek 736e800
Simplify text per @Kane610 https://github.com/home-assistant/home-ass…
austinmroczek 8ae81b2
Remove .get() to speed things up since the required items should always
austinmroczek 2c21b3a
Merge branch 'totalconnect-config-flow' of https://github.com/austinm…
austinmroczek 825cd86
Move CONF_USERNAME and CONF_PASSWORD into .const to eliminate extra I/O
austinmroczek 7793619
Merge branch 'totalconnect-config-flow' of https://github.com/austinm…
austinmroczek 0eb730e
Fix I/O async issues
austinmroczek dc541e5
Fix flake8 and black errors
austinmroczek ecf3881
Mock the I/O in tests.
austinmroczek 74e65d7
Fix isort error
austinmroczek 9f06454
Empty commit to re-start azure pipelines (per discord)
austinmroczek 9bcd05f
bump total-connect-client to 0.53
austinmroczek a5c4c56
Update homeassistant/components/totalconnect/__init__.py
austinmroczek a93bfef
Update homeassistant/components/totalconnect/config_flow.py
austinmroczek 4e7e98c
Fixes per @balloob comments
austinmroczek 75ab1ae
Fix imports
austinmroczek 9ed27ad
fix isort error
austinmroczek 872130b
Fix async_unload_entry
austinmroczek 234d805
Added async_setup so not breaking change. Fixed imports.
austinmroczek 9e3a9a6
Update tests/components/totalconnect/test_config_flow.py
austinmroczek f5d1af5
Remove TotalConnectSystem() per @MartinHjelmare suggestion
austinmroczek bd20b20
Moved from is_logged_in() to is_valid_credentials()
austinmroczek 0fe927c
Fix import in test
austinmroczek 70ecea5
remove commented code and decorator
austinmroczek 2b4ba2e
Update tests/components/totalconnect/test_config_flow.py
austinmroczek 3396859
fix test_config_flow.py
austinmroczek 85a7ec4
Merge remote-tracking branch 'upstream/dev' into totalconnect-config-…
austinmroczek f9afffc
bump total-connect-client to 0.54
austinmroczek dd62347
remove un-needed import of mock_coro
austinmroczek 1115ec9
bump to total-connect-client 0.54.1
austinmroczek 110f39c
Merge branch 'totalconnect-config-flow' of https://github.com/austinm…
austinmroczek c5f4ddf
re-add CONFIG_SCHEMA
austinmroczek ae483af
disable pylint on line 10 to avoid pylint bug
austinmroczek a99c112
Merge branch 'dev' into totalconnect-config-flow
austinmroczek 8e29221
Merge branch 'dev' into totalconnect-config-flow
austinmroczek 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
20 changes: 20 additions & 0 deletions
20
homeassistant/components/totalconnect/.translations/en.json
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,20 @@ | ||
| { | ||
| "config": { | ||
| "abort": { | ||
| "already_configured": "Account already configured" | ||
| }, | ||
| "error": { | ||
| "login": "Login error: please check your username & password" | ||
| }, | ||
| "step": { | ||
| "user": { | ||
| "data": { | ||
| "password": "Password", | ||
| "username": "Username" | ||
| }, | ||
| "title": "Total Connect" | ||
| } | ||
| }, | ||
| "title": "Total Connect" | ||
| } | ||
| } |
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,60 @@ | ||
| """Config flow for the Total Connect component.""" | ||
| import logging | ||
|
|
||
| from total_connect_client import TotalConnectClient | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant import config_entries | ||
| from homeassistant.const import CONF_PASSWORD, CONF_USERNAME | ||
|
|
||
| from .const import DOMAIN # pylint: disable=unused-import | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | ||
| """Total Connect config flow.""" | ||
|
|
||
| VERSION = 1 | ||
|
|
||
| async def async_step_user(self, user_input=None): | ||
| """Handle a flow initiated by the user.""" | ||
| errors = {} | ||
|
|
||
| if user_input is not None: | ||
| # Validate user input | ||
| username = user_input[CONF_USERNAME] | ||
| password = user_input[CONF_PASSWORD] | ||
|
|
||
| await self.async_set_unique_id(username) | ||
| self._abort_if_unique_id_configured() | ||
|
|
||
| valid = await self.is_valid(username, password) | ||
|
|
||
| if valid: | ||
| # authentication success / valid | ||
| return self.async_create_entry( | ||
| title="Total Connect", | ||
|
austinmroczek marked this conversation as resolved.
|
||
| data={CONF_USERNAME: username, CONF_PASSWORD: password}, | ||
| ) | ||
| # authentication failed / invalid | ||
| errors["base"] = "login" | ||
|
|
||
| data_schema = vol.Schema( | ||
| {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str} | ||
| ) | ||
|
|
||
| return self.async_show_form( | ||
| step_id="user", data_schema=data_schema, errors=errors | ||
| ) | ||
|
|
||
| async def async_step_import(self, user_input): | ||
|
austinmroczek marked this conversation as resolved.
|
||
| """Import a config entry.""" | ||
| return await self.async_step_user(user_input) | ||
|
|
||
| async def is_valid(self, username="", password=""): | ||
| """Return true if the given username and password are valid.""" | ||
| client = await self.hass.async_add_executor_job( | ||
| TotalConnectClient.TotalConnectClient, username, password | ||
| ) | ||
| return client.is_valid_credentials() | ||
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,20 @@ | ||
| { | ||
| "config": { | ||
| "title": "Total Connect", | ||
| "step": { | ||
| "user": { | ||
| "title": "Total Connect", | ||
| "data": { | ||
| "username": "Username", | ||
| "password": "Password" | ||
| } | ||
| } | ||
| }, | ||
| "error": { | ||
| "login": "Login error: please check your username & password" | ||
| }, | ||
| "abort": { | ||
| "already_configured": "Account already configured" | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -113,6 +113,7 @@ | |
| "tellduslive", | ||
| "tesla", | ||
| "toon", | ||
| "totalconnect", | ||
| "tplink", | ||
| "traccar", | ||
| "tradfri", | ||
|
|
||
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 totalconnect 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,104 @@ | ||
| """Tests for the iCloud config flow.""" | ||
| from unittest.mock import patch | ||
|
|
||
| from homeassistant import data_entry_flow | ||
| from homeassistant.components.totalconnect.const import DOMAIN | ||
| from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER | ||
| from homeassistant.const import CONF_PASSWORD, CONF_USERNAME | ||
|
|
||
| from tests.common import MockConfigEntry | ||
|
|
||
| USERNAME = "username@me.com" | ||
| PASSWORD = "password" | ||
|
|
||
|
|
||
| async def test_user(hass): | ||
| """Test user config.""" | ||
| # no data provided so show the form | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, context={"source": SOURCE_USER} | ||
| ) | ||
|
|
||
| assert result["type"] == data_entry_flow.RESULT_TYPE_FORM | ||
| assert result["step_id"] == "user" | ||
|
|
||
| # now data is provided, so check if login is correct and create the entry | ||
| with patch( | ||
| "homeassistant.components.totalconnect.config_flow.TotalConnectClient.TotalConnectClient" | ||
| ) as client_mock: | ||
| client_mock.return_value.is_valid_credentials.return_value = True | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, | ||
| context={"source": SOURCE_USER}, | ||
| data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD}, | ||
| ) | ||
|
|
||
| assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY | ||
|
|
||
|
|
||
| async def test_import(hass): | ||
| """Test import step with good username and password.""" | ||
| with patch( | ||
| "homeassistant.components.totalconnect.config_flow.TotalConnectClient.TotalConnectClient" | ||
| ) as client_mock: | ||
| client_mock.return_value.is_valid_credentials.return_value = True | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, | ||
| context={"source": SOURCE_IMPORT}, | ||
| data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD}, | ||
| ) | ||
|
|
||
| assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY | ||
|
|
||
|
|
||
| async def test_abort_if_already_setup(hass): | ||
| """Test abort if the account is already setup.""" | ||
| MockConfigEntry( | ||
| domain=DOMAIN, | ||
| data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD}, | ||
| unique_id=USERNAME, | ||
| ).add_to_hass(hass) | ||
|
|
||
| # Should fail, same USERNAME (import) | ||
| with patch( | ||
| "homeassistant.components.totalconnect.config_flow.TotalConnectClient.TotalConnectClient" | ||
| ) as client_mock: | ||
| client_mock.return_value.is_valid_credentials.return_value = True | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, | ||
| context={"source": SOURCE_IMPORT}, | ||
| data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD}, | ||
| ) | ||
|
|
||
| assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT | ||
| assert result["reason"] == "already_configured" | ||
|
|
||
| # Should fail, same USERNAME (flow) | ||
| with patch( | ||
| "homeassistant.components.totalconnect.config_flow.TotalConnectClient.TotalConnectClient" | ||
| ) as client_mock: | ||
| client_mock.return_value.is_valid_credentials.return_value = True | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, | ||
| context={"source": SOURCE_USER}, | ||
| data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD}, | ||
| ) | ||
|
|
||
| assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT | ||
| assert result["reason"] == "already_configured" | ||
|
|
||
|
|
||
| async def test_login_failed(hass): | ||
| """Test when we have errors during login.""" | ||
| with patch( | ||
| "homeassistant.components.totalconnect.config_flow.TotalConnectClient.TotalConnectClient" | ||
| ) as client_mock: | ||
| client_mock.return_value.is_valid_credentials.return_value = False | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, | ||
| context={"source": SOURCE_USER}, | ||
| data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD}, | ||
| ) | ||
|
|
||
| assert result["type"] == data_entry_flow.RESULT_TYPE_FORM | ||
| assert result["errors"] == {"base": "login"} |
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.
Uh oh!
There was an error while loading. Please reload this page.