Address late review of 17track config flow (#114283)
* some fixes for 17track * remove await * fix test
This commit is contained in:
parent
6423501498
commit
69356300f0
4 changed files with 16 additions and 15 deletions
|
@ -67,7 +67,7 @@ class SeventeenTrackConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
errors = {}
|
||||
if user_input:
|
||||
client = await self._get_client()
|
||||
client = self._get_client()
|
||||
|
||||
try:
|
||||
if not await client.profile.login(
|
||||
|
@ -101,19 +101,17 @@ class SeventeenTrackConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
||||
"""Import 17Track config from configuration.yaml."""
|
||||
|
||||
client = await self._get_client()
|
||||
client = self._get_client()
|
||||
|
||||
try:
|
||||
login_result = await client.profile.login(
|
||||
import_data[CONF_USERNAME], import_data[CONF_PASSWORD]
|
||||
)
|
||||
except SeventeenTrackError as err:
|
||||
_LOGGER.error("There was an error while logging in: %s", err)
|
||||
except SeventeenTrackError:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
if not login_result:
|
||||
_LOGGER.error("Invalid username and password provided")
|
||||
return self.async_abort(reason="invalid_credentials")
|
||||
return self.async_abort(reason="invalid_auth")
|
||||
|
||||
account_id = client.profile.account_id
|
||||
|
||||
|
@ -132,6 +130,7 @@ class SeventeenTrackConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
},
|
||||
)
|
||||
|
||||
async def _get_client(self):
|
||||
@callback
|
||||
def _get_client(self):
|
||||
session = aiohttp_client.async_get_clientsession(self.hass)
|
||||
return SeventeenTrackClient(session=session)
|
||||
|
|
|
@ -94,12 +94,12 @@ async def async_setup_platform(
|
|||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
f"deprecated_yaml_import_issue_${result['reason']}",
|
||||
f"deprecated_yaml_import_issue_{result['reason']}",
|
||||
breaks_in_ha_version="2024.10.0",
|
||||
is_fixable=False,
|
||||
issue_domain=DOMAIN,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key=f"deprecated_yaml_import_issue_${result['reason']}",
|
||||
translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
|
||||
translation_placeholders=ISSUE_PLACEHOLDER,
|
||||
)
|
||||
|
||||
|
|
|
@ -9,11 +9,13 @@
|
|||
}
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
|
||||
},
|
||||
"error": {
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
|
@ -32,8 +34,8 @@
|
|||
"title": "The 17Track YAML configuration import cannot connect to server",
|
||||
"description": "Configuring 17Track using YAML is being removed but there was a connection error importing your YAML configuration.\n\nThings you can try:\nMake sure your home assistant can reach the web.\n\nThen restart Home Assistant to try importing this integration again.\n\nAlternatively, you may remove the 17Track configuration from your YAML configuration entirely, restart Home Assistant, and add the 17Track integration manually."
|
||||
},
|
||||
"deprecated_yaml_import_issue_invalid_credentials": {
|
||||
"title": "The 17Track YAML configuration import request failed due to invalid credentials",
|
||||
"deprecated_yaml_import_issue_invalid_auth": {
|
||||
"title": "The 17Track YAML configuration import request failed due to invalid authentication",
|
||||
"description": "Configuring 17Track using YAML is being removed but there were invalid credentials provided while importing your existing configuration.\nSetup will not proceed.\n\nVerify that your 17Track credentials are correct and restart Home Assistant to attempt the import again.\n\nAlternatively, you may remove the 17Track configuration from your YAML configuration entirely, restart Home Assistant, and add the 17Track integration manually."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ async def test_import_flow(hass: HomeAssistant, mock_seventeentrack: AsyncMock)
|
|||
(
|
||||
False,
|
||||
None,
|
||||
"invalid_credentials",
|
||||
"invalid_auth",
|
||||
),
|
||||
(
|
||||
True,
|
||||
|
|
Loading…
Add table
Reference in a new issue