Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add extra failure exceptions during roborock setup #134889

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion homeassistant/components/roborock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
import logging
from typing import Any

from roborock import HomeDataRoom, RoborockException, RoborockInvalidCredentials
from roborock import (
HomeDataRoom,
RoborockException,
RoborockInvalidCredentials,
RoborockInvalidUserAgreement,
RoborockNoUserAgreement,
)
from roborock.containers import DeviceData, HomeDataDevice, HomeDataProduct, UserData
from roborock.version_1_apis.roborock_mqtt_client_v1 import RoborockMqttClientV1
from roborock.version_a01_apis import RoborockMqttClientA01
Expand Down Expand Up @@ -60,12 +66,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: RoborockConfigEntry) ->
translation_domain=DOMAIN,
translation_key="invalid_credentials",
) from err
except RoborockInvalidUserAgreement as err:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="invalid_user_agreement",
) from err
except RoborockNoUserAgreement as err:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="no_user_agreement",
) from err
except RoborockException as err:
raise ConfigEntryNotReady(
"Failed to get Roborock home data",
translation_domain=DOMAIN,
translation_key="home_data_fail",
) from err

_LOGGER.debug("Got home data %s", home_data)
all_devices: list[HomeDataDevice] = home_data.devices + home_data.received_devices
device_map: dict[str, HomeDataDevice] = {
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/roborock/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@
},
"update_options_failed": {
"message": "Failed to update Roborock options"
},
"invalid_user_agreement": {
"message": "User agreement must be accepted again. Open your Roborock app and accept the agreement."
},
"no_user_agreement": {
"message": "You have not valid user agreement. Open your Roborock app and accept the agreement."
}
},
"services": {
Expand Down
39 changes: 38 additions & 1 deletion tests/components/roborock/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from unittest.mock import patch

import pytest
from roborock import RoborockException, RoborockInvalidCredentials
from roborock import (
RoborockException,
RoborockInvalidCredentials,
RoborockInvalidUserAgreement,
RoborockNoUserAgreement,
)

from homeassistant.components.roborock.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
Expand Down Expand Up @@ -194,3 +199,35 @@ async def test_not_supported_a01_device(
await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
assert "The device you added is not yet supported" in caplog.text


async def test_invalid_user_agreement(
hass: HomeAssistant,
bypass_api_fixture,
mock_roborock_entry: MockConfigEntry,
) -> None:
"""Test that we fail setting up if the user agreement is out of date."""
with patch(
"homeassistant.components.roborock.RoborockApiClient.get_home_data_v2",
side_effect=RoborockInvalidUserAgreement(),
):
await hass.config_entries.async_setup(mock_roborock_entry.entry_id)
assert mock_roborock_entry.state is ConfigEntryState.SETUP_RETRY
assert (
mock_roborock_entry.error_reason_translation_key == "invalid_user_agreement"
)


async def test_no_user_agreement(
hass: HomeAssistant,
bypass_api_fixture,
mock_roborock_entry: MockConfigEntry,
) -> None:
"""Test that we fail setting up if the user has no agreement."""
with patch(
"homeassistant.components.roborock.RoborockApiClient.get_home_data_v2",
side_effect=RoborockNoUserAgreement(),
):
await hass.config_entries.async_setup(mock_roborock_entry.entry_id)
assert mock_roborock_entry.state is ConfigEntryState.SETUP_RETRY
assert mock_roborock_entry.error_reason_translation_key == "no_user_agreement"
Loading