mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add extra failure exceptions during roborock setup (#134889)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
c533f63a87
commit
14d2f2c589
@ -9,7 +9,13 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
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.containers import DeviceData, HomeDataDevice, HomeDataProduct, UserData
|
||||||
from roborock.version_1_apis.roborock_mqtt_client_v1 import RoborockMqttClientV1
|
from roborock.version_1_apis.roborock_mqtt_client_v1 import RoborockMqttClientV1
|
||||||
from roborock.version_a01_apis import RoborockMqttClientA01
|
from roborock.version_a01_apis import RoborockMqttClientA01
|
||||||
@ -60,12 +66,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: RoborockConfigEntry) ->
|
|||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
translation_key="invalid_credentials",
|
translation_key="invalid_credentials",
|
||||||
) from err
|
) 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:
|
except RoborockException as err:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
"Failed to get Roborock home data",
|
"Failed to get Roborock home data",
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
translation_key="home_data_fail",
|
translation_key="home_data_fail",
|
||||||
) from err
|
) from err
|
||||||
|
|
||||||
_LOGGER.debug("Got home data %s", home_data)
|
_LOGGER.debug("Got home data %s", home_data)
|
||||||
all_devices: list[HomeDataDevice] = home_data.devices + home_data.received_devices
|
all_devices: list[HomeDataDevice] = home_data.devices + home_data.received_devices
|
||||||
device_map: dict[str, HomeDataDevice] = {
|
device_map: dict[str, HomeDataDevice] = {
|
||||||
|
@ -422,6 +422,12 @@
|
|||||||
},
|
},
|
||||||
"update_options_failed": {
|
"update_options_failed": {
|
||||||
"message": "Failed to update Roborock options"
|
"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": {
|
"services": {
|
||||||
|
@ -4,7 +4,12 @@ from copy import deepcopy
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from roborock import RoborockException, RoborockInvalidCredentials
|
from roborock import (
|
||||||
|
RoborockException,
|
||||||
|
RoborockInvalidCredentials,
|
||||||
|
RoborockInvalidUserAgreement,
|
||||||
|
RoborockNoUserAgreement,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.components.roborock.const import DOMAIN
|
from homeassistant.components.roborock.const import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
@ -194,3 +199,35 @@ async def test_not_supported_a01_device(
|
|||||||
await async_setup_component(hass, DOMAIN, {})
|
await async_setup_component(hass, DOMAIN, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert "The device you added is not yet supported" in caplog.text
|
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…
x
Reference in New Issue
Block a user