From bc9afe3432f5fdb4ea3396e9de22608128713fcc Mon Sep 17 00:00:00 2001 From: Miro <77541423+mirobotur@users.noreply.github.com> Date: Thu, 26 Feb 2026 13:26:44 +0100 Subject: [PATCH] fix: handle empty messages in login error and warn about special characters When login fails with an empty messages array, the integration crashed with IndexError. This now handles that gracefully and provides a helpful error message suggesting the user check for special characters in their password, which Rohlik.cz may not handle correctly on the server side. Also adds a note to the README about this known limitation. Closes #63 Co-Authored-By: Claude Opus 4.6 --- custom_components/rohlikcz/rohlik_api.py | 16 ++++++++++++++-- readme.md | 5 ++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/custom_components/rohlikcz/rohlik_api.py b/custom_components/rohlikcz/rohlik_api.py index 4cad2e3..5520d95 100644 --- a/custom_components/rohlikcz/rohlik_api.py +++ b/custom_components/rohlikcz/rohlik_api.py @@ -128,10 +128,22 @@ async def login(self, session): login_response: dict = login_response.json() if login_response["status"] != 200: + messages = login_response.get("messages", []) + error_detail = messages[0]["content"] if messages else None + _LOGGER.error(f"Login failed with status {login_response['status']}. Response: {mask_data(login_response)}") if login_response["status"] == 401: - raise InvalidCredentialsError(login_response["messages"][0]["content"]) + if error_detail: + raise InvalidCredentialsError(error_detail) + raise InvalidCredentialsError( + "Login failed. Please check your credentials. " + "If your password contains special characters (e.g. `, $, +, etc.), " + "try changing it to use only standard characters — " + "Rohlik.cz may not handle them correctly." + ) else: - raise RohlikczError(f"Unknown error occurred during login: {login_response["messages"][0]["content"]}") + if not error_detail: + error_detail = f"status code {login_response['status']}" + raise RohlikczError(f"Unknown error occurred during login: {error_detail}") if not self._user_id: self._user_id = login_response.get("data", {}).get("user", {}).get("id", None) diff --git a/readme.md b/readme.md index cf8b009..4937d28 100644 --- a/readme.md +++ b/readme.md @@ -36,10 +36,13 @@ From the Home Assistant front page go to **Configuration** and then select **Int Use the "plus" button in the bottom right to add a new integration called **Rohlik.cz**. Fill in: - + - Email (your Rohlik.cz account email) - Password (your Rohlik.cz account password) +> [!NOTE] +> If your password contains special characters (e.g. `` ` ``, `$`, `+`), login may fail due to a Rohlik.cz server-side limitation. If you experience login issues, try changing your Rohlik.cz password to use only standard alphanumeric characters and common symbols. + The integration will connect to your Rohlik.cz account and set up the entities. ## Features