Improve totalconnect config flow user experience (#47926)
This commit is contained in:
parent
67536b52c4
commit
22dd7df66c
4 changed files with 14 additions and 12 deletions
|
@ -65,10 +65,10 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
if self.usercodes[location_id] is None:
|
||||
valid = await self.hass.async_add_executor_job(
|
||||
self.client.locations[location_id].set_usercode,
|
||||
user_entry[CONF_LOCATION],
|
||||
user_entry[CONF_USERCODES],
|
||||
)
|
||||
if valid:
|
||||
self.usercodes[location_id] = user_entry[CONF_LOCATION]
|
||||
self.usercodes[location_id] = user_entry[CONF_USERCODES]
|
||||
else:
|
||||
errors[CONF_LOCATION] = "usercode"
|
||||
break
|
||||
|
@ -93,12 +93,14 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
# show the next location that needs a usercode
|
||||
location_codes = {}
|
||||
location_for_user = ""
|
||||
for location_id in self.usercodes:
|
||||
if self.usercodes[location_id] is None:
|
||||
location_for_user = location_id
|
||||
location_codes[
|
||||
vol.Required(
|
||||
CONF_LOCATION,
|
||||
default=location_id,
|
||||
CONF_USERCODES,
|
||||
default="0000",
|
||||
)
|
||||
] = str
|
||||
break
|
||||
|
@ -108,7 +110,7 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="locations",
|
||||
data_schema=data_schema,
|
||||
errors=errors,
|
||||
description_placeholders={"base": "description"},
|
||||
description_placeholders={"location_id": location_for_user},
|
||||
)
|
||||
|
||||
async def async_step_reauth(self, config):
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
},
|
||||
"locations": {
|
||||
"title": "Location Usercodes",
|
||||
"description": "Enter the usercode for this user at this location",
|
||||
"description": "Enter the usercode for this user at location {location_id}",
|
||||
"data": {
|
||||
"location": "[%key:common::config_flow::data::location%]"
|
||||
"usercode": "Usercode"
|
||||
}
|
||||
},
|
||||
"reauth_confirm": {
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
"step": {
|
||||
"locations": {
|
||||
"data": {
|
||||
"location": "Location"
|
||||
"usercode": "Usercode"
|
||||
},
|
||||
"description": "Enter the usercode for this user at this location",
|
||||
"description": "Enter the usercode for this user at location {location_id}",
|
||||
"title": "Location Usercodes"
|
||||
},
|
||||
"reauth_confirm": {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.totalconnect.const import CONF_LOCATION, DOMAIN
|
||||
from homeassistant.components.totalconnect.const import CONF_USERCODES, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_PASSWORD
|
||||
|
||||
|
@ -67,7 +67,7 @@ async def test_user_show_locations(hass):
|
|||
# user enters an invalid usercode
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_LOCATION: "bad"},
|
||||
user_input={CONF_USERCODES: "bad"},
|
||||
)
|
||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result2["step_id"] == "locations"
|
||||
|
@ -77,7 +77,7 @@ async def test_user_show_locations(hass):
|
|||
# user enters a valid usercode
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
user_input={CONF_LOCATION: "7890"},
|
||||
user_input={CONF_USERCODES: "7890"},
|
||||
)
|
||||
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
# client should have sent another request to validate usercode
|
||||
|
|
Loading…
Add table
Reference in a new issue