update for total_connect_client changes

This commit is contained in:
Austin Mroczek
2021-10-30 23:56:22 +00:00
parent 9597227967
commit 3a1f7b7c4d
5 changed files with 18 additions and 19 deletions

View File

@@ -38,7 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
TotalConnectClient, username, password, usercodes TotalConnectClient, username, password, usercodes
) )
if not client.is_valid_credentials(): if not client.is_logged_in():
raise ConfigEntryAuthFailed("TotalConnect authentication failed") raise ConfigEntryAuthFailed("TotalConnect authentication failed")
coordinator = TotalConnectDataUpdateCoordinator(hass, client) coordinator = TotalConnectDataUpdateCoordinator(hass, client)

View File

@@ -40,7 +40,7 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
TotalConnectClient, username, password, None TotalConnectClient, username, password, None
) )
if client.is_valid_credentials(): if client.is_logged_in():
# username/password valid so show user locations # username/password valid so show user locations
self.username = username self.username = username
self.password = password self.password = password
@@ -136,7 +136,7 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self.usercodes, self.usercodes,
) )
if not client.is_valid_credentials(): if not client.is_logged_in():
errors["base"] = "invalid_auth" errors["base"] = "invalid_auth"
return self.async_show_form( return self.async_show_form(
step_id="reauth_confirm", step_id="reauth_confirm",

View File

@@ -1,8 +1,7 @@
"""Common methods used across tests for TotalConnect.""" """Common methods used across tests for TotalConnect."""
from unittest.mock import patch from unittest.mock import patch
from total_connect_client.client import TotalConnectClient from total_connect_client.const import ArmingState, _ResultCode
from total_connect_client.const import ArmingState
from total_connect_client.zone import ZoneStatus, ZoneType from total_connect_client.zone import ZoneStatus, ZoneType
from homeassistant.components.totalconnect.const import CONF_USERCODES, DOMAIN from homeassistant.components.totalconnect.const import CONF_USERCODES, DOMAIN
@@ -44,7 +43,7 @@ USER = {
} }
RESPONSE_AUTHENTICATE = { RESPONSE_AUTHENTICATE = {
"ResultCode": TotalConnectClient.SUCCESS, "ResultCode": _ResultCode.SUCCESS.value,
"SessionID": 1, "SessionID": 1,
"Locations": LOCATIONS, "Locations": LOCATIONS,
"ModuleFlags": MODULE_FLAGS, "ModuleFlags": MODULE_FLAGS,
@@ -52,7 +51,7 @@ RESPONSE_AUTHENTICATE = {
} }
RESPONSE_AUTHENTICATE_FAILED = { RESPONSE_AUTHENTICATE_FAILED = {
"ResultCode": TotalConnectClient.BAD_USER_OR_PASSWORD, "ResultCode": _ResultCode.BAD_USER_OR_PASSWORD.value,
"ResultData": "test bad authentication", "ResultData": "test bad authentication",
} }
@@ -255,18 +254,18 @@ RESPONSE_UNKNOWN = {
"ArmingState": ArmingState.DISARMED, "ArmingState": ArmingState.DISARMED,
} }
RESPONSE_ARM_SUCCESS = {"ResultCode": TotalConnectClient.ARM_SUCCESS} RESPONSE_ARM_SUCCESS = {"ResultCode": _ResultCode.ARM_SUCCESS.value}
RESPONSE_ARM_FAILURE = {"ResultCode": TotalConnectClient.COMMAND_FAILED} RESPONSE_ARM_FAILURE = {"ResultCode": _ResultCode.COMMAND_FAILED.value}
RESPONSE_DISARM_SUCCESS = {"ResultCode": TotalConnectClient.DISARM_SUCCESS} RESPONSE_DISARM_SUCCESS = {"ResultCode": _ResultCode.DISARM_SUCCESS.value}
RESPONSE_DISARM_FAILURE = { RESPONSE_DISARM_FAILURE = {
"ResultCode": TotalConnectClient.COMMAND_FAILED, "ResultCode": _ResultCode.COMMAND_FAILED.value,
"ResultData": "Command Failed", "ResultData": "Command Failed",
} }
RESPONSE_USER_CODE_INVALID = { RESPONSE_USER_CODE_INVALID = {
"ResultCode": TotalConnectClient.USER_CODE_INVALID, "ResultCode": _ResultCode.USER_CODE_INVALID.value,
"ResultData": "testing user code invalid", "ResultData": "testing user code invalid",
} }
RESPONSE_SUCCESS = {"ResultCode": TotalConnectClient.SUCCESS} RESPONSE_SUCCESS = {"ResultCode": _ResultCode.SUCCESS.value}
USERNAME = "username@me.com" USERNAME = "username@me.com"
PASSWORD = "password" PASSWORD = "password"
@@ -292,7 +291,7 @@ PARTITION_DETAILS_2 = {
PARTITION_DETAILS = {"PartitionDetails": [PARTITION_DETAILS_1, PARTITION_DETAILS_2]} PARTITION_DETAILS = {"PartitionDetails": [PARTITION_DETAILS_1, PARTITION_DETAILS_2]}
RESPONSE_PARTITION_DETAILS = { RESPONSE_PARTITION_DETAILS = {
"ResultCode": TotalConnectClient.SUCCESS, "ResultCode": _ResultCode.SUCCESS.value,
"ResultData": "testing partition details", "ResultData": "testing partition details",
"PartitionsInfoList": PARTITION_DETAILS, "PartitionsInfoList": PARTITION_DETAILS,
} }

View File

@@ -95,7 +95,7 @@ async def test_abort_if_already_setup(hass):
with patch( with patch(
"homeassistant.components.totalconnect.config_flow.TotalConnectClient" "homeassistant.components.totalconnect.config_flow.TotalConnectClient"
) as client_mock: ) 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( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": SOURCE_USER}, context={"source": SOURCE_USER},
@@ -111,7 +111,7 @@ async def test_login_failed(hass):
with patch( with patch(
"homeassistant.components.totalconnect.config_flow.TotalConnectClient" "homeassistant.components.totalconnect.config_flow.TotalConnectClient"
) as client_mock: ) 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( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": SOURCE_USER}, context={"source": SOURCE_USER},
@@ -143,7 +143,7 @@ async def test_reauth(hass):
"homeassistant.components.totalconnect.async_setup_entry", return_value=True "homeassistant.components.totalconnect.async_setup_entry", return_value=True
): ):
# first test with an invalid password # 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 = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_PASSWORD: "password"} result["flow_id"], user_input={CONF_PASSWORD: "password"}
@@ -153,7 +153,7 @@ async def test_reauth(hass):
assert result["errors"] == {"base": "invalid_auth"} assert result["errors"] == {"base": "invalid_auth"}
# now test with the password valid # 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 = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_PASSWORD: "password"} result["flow_id"], user_input={CONF_PASSWORD: "password"}

View File

@@ -22,7 +22,7 @@ async def test_reauth_started(hass):
"homeassistant.components.totalconnect.TotalConnectClient", "homeassistant.components.totalconnect.TotalConnectClient",
autospec=True, autospec=True,
) as mock_client: ) 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, {}) assert await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done() await hass.async_block_till_done()