diff --git a/custom_components/yandex_station_intents/config_flow.py b/custom_components/yandex_station_intents/config_flow.py index 12ea4bb..bc758b2 100644 --- a/custom_components/yandex_station_intents/config_flow.py +++ b/custom_components/yandex_station_intents/config_flow.py @@ -76,13 +76,12 @@ async def async_step_cookies(self, user_input: ConfigType) -> FlowResult: host = next(p["domain"] for p in raw if p["domain"].startswith(".yandex.")) cookies = {p["name"]: p["value"] for p in raw} except (TypeError, KeyError, json.decoder.JSONDecodeError): - return await self._show_form(AuthMethod.COOKIES, errors={"base": "cookies.invalid_format"}) + return await self._show_form(AuthMethod.COOKIES, error_code="cookies.invalid_format") try: response = await self._session.login_cookies(host, cookies) except AuthException as e: - _LOGGER.error(f"Ошибка авторизации: {e}") - return await self._show_form(AuthMethod.COOKIES, errors={"base": "auth.error"}) + return await self._show_form(AuthMethod.COOKIES, error_code="auth.error", error_description=str(e)) return await self._check_yandex_response(response, AuthMethod.COOKIES) @@ -90,10 +89,17 @@ async def async_step_token(self, user_input: ConfigType) -> FlowResult: response = await self._session.validate_token(user_input[AuthMethod.TOKEN]) return await self._check_yandex_response(response, AuthMethod.TOKEN) - async def _show_form(self, method: AuthMethod, errors: dict[str, str] | None = None) -> FlowResult: + async def _show_form( + self, method: AuthMethod, error_code: str | None = None, error_description: str | None = None + ) -> FlowResult: + errors = {} + if error_code: + errors["base"] = error_code + return self.async_show_form( step_id=str(method), errors=errors, + description_placeholders={"error_description": error_description}, data_schema=vol.Schema({vol.Required(str(method)): str}), ) @@ -103,7 +109,6 @@ async def _check_yandex_response(self, response: LoginResponse, method: AuthMeth return self.async_create_entry(title=response.display_login, data={CONF_X_TOKEN: response.x_token}) elif response.error: - _LOGGER.error(f"Ошибка авторизации: {response.error}") - return await self._show_form(method, errors={"base": "auth.error"}) + return await self._show_form(method, error_code="auth.error", error_description=response.error) raise NotImplementedError diff --git a/custom_components/yandex_station_intents/translations/en.json b/custom_components/yandex_station_intents/translations/en.json index f2abdd5..fc4e92b 100644 --- a/custom_components/yandex_station_intents/translations/en.json +++ b/custom_components/yandex_station_intents/translations/en.json @@ -5,7 +5,7 @@ }, "error": { "cookies.invalid_format": "Это не похоже на JSON из расширения Copy Cookies", - "auth.error": "Ошибка авторизации, проверьте журнал Home Assistant" + "auth.error": "Ошибка авторизации: {error_description}" }, "step": { "user": {