From c150a296d264c9ede0975eeee9ba7ec4bfd9f306 Mon Sep 17 00:00:00 2001 From: Austin Mroczek Date: Sun, 7 Nov 2021 15:30:34 -0800 Subject: [PATCH] Bump total_connect_client to 2021.11.2 (#58818) * update total_connect_client to 2021.10 * update for total_connect_client changes * remove unused return value * bump total_connect_client to 2021.11.1 * bump total_connect_client to 2021.11.2 * Move to public ResultCode * load locations to prevent 'unknown error occurred' * add test for zero locations * Revert "load locations to prevent 'unknown error occurred'" This reverts commit 28b8984be5b1c8839fc8077d8d59bdba97eacc38. * Revert "add test for zero locations" This reverts commit 77bf7908d508d539d6165fc986930b041b13ca97. --- .../components/totalconnect/__init__.py | 4 +--- .../components/totalconnect/config_flow.py | 4 ++-- .../components/totalconnect/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/totalconnect/common.py | 22 +++++++++---------- .../totalconnect/test_config_flow.py | 8 +++---- tests/components/totalconnect/test_init.py | 2 +- 8 files changed, 21 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/totalconnect/__init__.py b/homeassistant/components/totalconnect/__init__.py index bd1f693fd07..8acc7801de8 100644 --- a/homeassistant/components/totalconnect/__init__.py +++ b/homeassistant/components/totalconnect/__init__.py @@ -38,7 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: TotalConnectClient, username, password, usercodes ) - if not client.is_valid_credentials(): + if not client.is_logged_in(): raise ConfigEntryAuthFailed("TotalConnect authentication failed") coordinator = TotalConnectDataUpdateCoordinator(hass, client) @@ -88,5 +88,3 @@ class TotalConnectDataUpdateCoordinator(DataUpdateCoordinator): raise UpdateFailed(exception) from exception except ValueError as exception: raise UpdateFailed("Unknown state from TotalConnect") from exception - - return True diff --git a/homeassistant/components/totalconnect/config_flow.py b/homeassistant/components/totalconnect/config_flow.py index 7ba96f11a1e..f3550722de5 100644 --- a/homeassistant/components/totalconnect/config_flow.py +++ b/homeassistant/components/totalconnect/config_flow.py @@ -40,7 +40,7 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): TotalConnectClient, username, password, None ) - if client.is_valid_credentials(): + if client.is_logged_in(): # username/password valid so show user locations self.username = username self.password = password @@ -136,7 +136,7 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self.usercodes, ) - if not client.is_valid_credentials(): + if not client.is_logged_in(): errors["base"] = "invalid_auth" return self.async_show_form( step_id="reauth_confirm", diff --git a/homeassistant/components/totalconnect/manifest.json b/homeassistant/components/totalconnect/manifest.json index 25fb2fd2c75..c70eafd9c31 100644 --- a/homeassistant/components/totalconnect/manifest.json +++ b/homeassistant/components/totalconnect/manifest.json @@ -2,7 +2,7 @@ "domain": "totalconnect", "name": "Total Connect", "documentation": "https://www.home-assistant.io/integrations/totalconnect", - "requirements": ["total_connect_client==2021.8.3"], + "requirements": ["total_connect_client==2021.11.2"], "dependencies": [], "codeowners": ["@austinmroczek"], "config_flow": true, diff --git a/requirements_all.txt b/requirements_all.txt index c5f93ad7251..452d5482578 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2314,7 +2314,7 @@ todoist-python==8.0.0 toonapi==0.2.1 # homeassistant.components.totalconnect -total_connect_client==2021.8.3 +total_connect_client==2021.11.2 # homeassistant.components.tplink_lte tp-connected==0.0.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index fdacbc25dd2..6a5231386b8 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1330,7 +1330,7 @@ tesla-powerwall==0.3.12 toonapi==0.2.1 # homeassistant.components.totalconnect -total_connect_client==2021.8.3 +total_connect_client==2021.11.2 # homeassistant.components.transmission transmissionrpc==0.11 diff --git a/tests/components/totalconnect/common.py b/tests/components/totalconnect/common.py index 29278d33273..ec0c182895f 100644 --- a/tests/components/totalconnect/common.py +++ b/tests/components/totalconnect/common.py @@ -1,9 +1,7 @@ """Common methods used across tests for TotalConnect.""" from unittest.mock import patch -from total_connect_client.client import TotalConnectClient -from total_connect_client.const import ArmingState -from total_connect_client.zone import ZoneStatus, ZoneType +from total_connect_client import ArmingState, ResultCode, ZoneStatus, ZoneType from homeassistant.components.totalconnect.const import CONF_USERCODES, DOMAIN from homeassistant.const import CONF_PASSWORD, CONF_USERNAME @@ -44,7 +42,7 @@ USER = { } RESPONSE_AUTHENTICATE = { - "ResultCode": TotalConnectClient.SUCCESS, + "ResultCode": ResultCode.SUCCESS.value, "SessionID": 1, "Locations": LOCATIONS, "ModuleFlags": MODULE_FLAGS, @@ -52,7 +50,7 @@ RESPONSE_AUTHENTICATE = { } RESPONSE_AUTHENTICATE_FAILED = { - "ResultCode": TotalConnectClient.BAD_USER_OR_PASSWORD, + "ResultCode": ResultCode.BAD_USER_OR_PASSWORD.value, "ResultData": "test bad authentication", } @@ -255,18 +253,18 @@ RESPONSE_UNKNOWN = { "ArmingState": ArmingState.DISARMED, } -RESPONSE_ARM_SUCCESS = {"ResultCode": TotalConnectClient.ARM_SUCCESS} -RESPONSE_ARM_FAILURE = {"ResultCode": TotalConnectClient.COMMAND_FAILED} -RESPONSE_DISARM_SUCCESS = {"ResultCode": TotalConnectClient.DISARM_SUCCESS} +RESPONSE_ARM_SUCCESS = {"ResultCode": ResultCode.ARM_SUCCESS.value} +RESPONSE_ARM_FAILURE = {"ResultCode": ResultCode.COMMAND_FAILED.value} +RESPONSE_DISARM_SUCCESS = {"ResultCode": ResultCode.DISARM_SUCCESS.value} RESPONSE_DISARM_FAILURE = { - "ResultCode": TotalConnectClient.COMMAND_FAILED, + "ResultCode": ResultCode.COMMAND_FAILED.value, "ResultData": "Command Failed", } RESPONSE_USER_CODE_INVALID = { - "ResultCode": TotalConnectClient.USER_CODE_INVALID, + "ResultCode": ResultCode.USER_CODE_INVALID.value, "ResultData": "testing user code invalid", } -RESPONSE_SUCCESS = {"ResultCode": TotalConnectClient.SUCCESS} +RESPONSE_SUCCESS = {"ResultCode": ResultCode.SUCCESS.value} USERNAME = "username@me.com" PASSWORD = "password" @@ -292,7 +290,7 @@ PARTITION_DETAILS_2 = { PARTITION_DETAILS = {"PartitionDetails": [PARTITION_DETAILS_1, PARTITION_DETAILS_2]} RESPONSE_PARTITION_DETAILS = { - "ResultCode": TotalConnectClient.SUCCESS, + "ResultCode": ResultCode.SUCCESS.value, "ResultData": "testing partition details", "PartitionsInfoList": PARTITION_DETAILS, } diff --git a/tests/components/totalconnect/test_config_flow.py b/tests/components/totalconnect/test_config_flow.py index 20497102c6d..a9debb26dd4 100644 --- a/tests/components/totalconnect/test_config_flow.py +++ b/tests/components/totalconnect/test_config_flow.py @@ -95,7 +95,7 @@ async def test_abort_if_already_setup(hass): with patch( "homeassistant.components.totalconnect.config_flow.TotalConnectClient" ) as client_mock: - client_mock.return_value.is_valid_credentials.return_value = True + client_mock.return_value.is_logged_in.return_value = True result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, @@ -111,7 +111,7 @@ async def test_login_failed(hass): with patch( "homeassistant.components.totalconnect.config_flow.TotalConnectClient" ) as client_mock: - client_mock.return_value.is_valid_credentials.return_value = False + client_mock.return_value.is_logged_in.return_value = False result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, @@ -143,7 +143,7 @@ async def test_reauth(hass): "homeassistant.components.totalconnect.async_setup_entry", return_value=True ): # first test with an invalid password - client_mock.return_value.is_valid_credentials.return_value = False + client_mock.return_value.is_logged_in.return_value = False result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={CONF_PASSWORD: "password"} @@ -153,7 +153,7 @@ async def test_reauth(hass): assert result["errors"] == {"base": "invalid_auth"} # now test with the password valid - client_mock.return_value.is_valid_credentials.return_value = True + client_mock.return_value.is_logged_in.return_value = True result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={CONF_PASSWORD: "password"} diff --git a/tests/components/totalconnect/test_init.py b/tests/components/totalconnect/test_init.py index 41cd8bbae90..f1797f840ab 100644 --- a/tests/components/totalconnect/test_init.py +++ b/tests/components/totalconnect/test_init.py @@ -22,7 +22,7 @@ async def test_reauth_started(hass): "homeassistant.components.totalconnect.TotalConnectClient", autospec=True, ) as mock_client: - mock_client.return_value.is_valid_credentials.return_value = False + mock_client.return_value.is_logged_in.return_value = False assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done()