mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Improve totalconnect config flow user experience (#47926)
This commit is contained in:
parent
67536b52c4
commit
22dd7df66c
@ -65,10 +65,10 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
if self.usercodes[location_id] is None:
|
if self.usercodes[location_id] is None:
|
||||||
valid = await self.hass.async_add_executor_job(
|
valid = await self.hass.async_add_executor_job(
|
||||||
self.client.locations[location_id].set_usercode,
|
self.client.locations[location_id].set_usercode,
|
||||||
user_entry[CONF_LOCATION],
|
user_entry[CONF_USERCODES],
|
||||||
)
|
)
|
||||||
if valid:
|
if valid:
|
||||||
self.usercodes[location_id] = user_entry[CONF_LOCATION]
|
self.usercodes[location_id] = user_entry[CONF_USERCODES]
|
||||||
else:
|
else:
|
||||||
errors[CONF_LOCATION] = "usercode"
|
errors[CONF_LOCATION] = "usercode"
|
||||||
break
|
break
|
||||||
@ -93,12 +93,14 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
# show the next location that needs a usercode
|
# show the next location that needs a usercode
|
||||||
location_codes = {}
|
location_codes = {}
|
||||||
|
location_for_user = ""
|
||||||
for location_id in self.usercodes:
|
for location_id in self.usercodes:
|
||||||
if self.usercodes[location_id] is None:
|
if self.usercodes[location_id] is None:
|
||||||
|
location_for_user = location_id
|
||||||
location_codes[
|
location_codes[
|
||||||
vol.Required(
|
vol.Required(
|
||||||
CONF_LOCATION,
|
CONF_USERCODES,
|
||||||
default=location_id,
|
default="0000",
|
||||||
)
|
)
|
||||||
] = str
|
] = str
|
||||||
break
|
break
|
||||||
@ -108,7 +110,7 @@ class TotalConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
step_id="locations",
|
step_id="locations",
|
||||||
data_schema=data_schema,
|
data_schema=data_schema,
|
||||||
errors=errors,
|
errors=errors,
|
||||||
description_placeholders={"base": "description"},
|
description_placeholders={"location_id": location_for_user},
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_reauth(self, config):
|
async def async_step_reauth(self, config):
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
},
|
},
|
||||||
"locations": {
|
"locations": {
|
||||||
"title": "Location Usercodes",
|
"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": {
|
"data": {
|
||||||
"location": "[%key:common::config_flow::data::location%]"
|
"usercode": "Usercode"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"reauth_confirm": {
|
"reauth_confirm": {
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
"step": {
|
"step": {
|
||||||
"locations": {
|
"locations": {
|
||||||
"data": {
|
"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"
|
"title": "Location Usercodes"
|
||||||
},
|
},
|
||||||
"reauth_confirm": {
|
"reauth_confirm": {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
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.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||||
from homeassistant.const import CONF_PASSWORD
|
from homeassistant.const import CONF_PASSWORD
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ async def test_user_show_locations(hass):
|
|||||||
# user enters an invalid usercode
|
# user enters an invalid usercode
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input={CONF_LOCATION: "bad"},
|
user_input={CONF_USERCODES: "bad"},
|
||||||
)
|
)
|
||||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result2["step_id"] == "locations"
|
assert result2["step_id"] == "locations"
|
||||||
@ -77,7 +77,7 @@ async def test_user_show_locations(hass):
|
|||||||
# user enters a valid usercode
|
# user enters a valid usercode
|
||||||
result3 = await hass.config_entries.flow.async_configure(
|
result3 = await hass.config_entries.flow.async_configure(
|
||||||
result2["flow_id"],
|
result2["flow_id"],
|
||||||
user_input={CONF_LOCATION: "7890"},
|
user_input={CONF_USERCODES: "7890"},
|
||||||
)
|
)
|
||||||
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
# client should have sent another request to validate usercode
|
# client should have sent another request to validate usercode
|
||||||
|
Loading…
x
Reference in New Issue
Block a user