From efec50c8f079b8172a58973d52d2d9987894b2b5 Mon Sep 17 00:00:00 2001 From: Luke Date: Thu, 27 Apr 2023 15:10:34 -0400 Subject: [PATCH] Bump roborock to 0.8.1 for beta fixes (#92131) * bump to 0.8.1 * add tests for new config flow errors * removed logs for known errors --- .../components/roborock/config_flow.py | 20 ++++++++++++++++--- .../components/roborock/coordinator.py | 10 ++++------ .../components/roborock/manifest.json | 2 +- homeassistant/components/roborock/models.py | 4 ++-- .../components/roborock/strings.json | 3 +++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/roborock/mock_data.py | 4 ++-- tests/components/roborock/test_config_flow.py | 16 ++++++++++++--- 9 files changed, 44 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/roborock/config_flow.py b/homeassistant/components/roborock/config_flow.py index d0c2147c1ee..fcfad6e8cd3 100644 --- a/homeassistant/components/roborock/config_flow.py +++ b/homeassistant/components/roborock/config_flow.py @@ -6,7 +6,13 @@ from typing import Any from roborock.api import RoborockApiClient from roborock.containers import UserData -from roborock.exceptions import RoborockException +from roborock.exceptions import ( + RoborockAccountDoesNotExist, + RoborockException, + RoborockInvalidCode, + RoborockInvalidEmail, + RoborockUrlException, +) import voluptuous as vol from homeassistant import config_entries @@ -43,9 +49,15 @@ class RoborockFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self._client = RoborockApiClient(username) try: await self._client.request_code() + except RoborockAccountDoesNotExist: + errors["base"] = "invalid_email" + except RoborockUrlException: + errors["base"] = "unknown_url" + except RoborockInvalidEmail: + errors["base"] = "invalid_email_format" except RoborockException as ex: _LOGGER.exception(ex) - errors["base"] = "invalid_email" + errors["base"] = "unknown_roborock" except Exception as ex: # pylint: disable=broad-except _LOGGER.exception(ex) errors["base"] = "unknown" @@ -70,9 +82,11 @@ class RoborockFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): _LOGGER.debug("Logging into Roborock account using email provided code") try: login_data = await self._client.code_login(code) + except RoborockInvalidCode: + errors["base"] = "invalid_code" except RoborockException as ex: _LOGGER.exception(ex) - errors["base"] = "invalid_code" + errors["base"] = "unknown_roborock" except Exception as ex: # pylint: disable=broad-except _LOGGER.exception(ex) errors["base"] = "unknown" diff --git a/homeassistant/components/roborock/coordinator.py b/homeassistant/components/roborock/coordinator.py index 997c0a6acb8..433b46d2899 100644 --- a/homeassistant/components/roborock/coordinator.py +++ b/homeassistant/components/roborock/coordinator.py @@ -13,7 +13,7 @@ from roborock.containers import ( ) from roborock.exceptions import RoborockException from roborock.local_api import RoborockLocalClient -from roborock.typing import RoborockDeviceProp +from roborock.typing import DeviceProp from homeassistant.core import HomeAssistant from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -26,9 +26,7 @@ SCAN_INTERVAL = timedelta(seconds=30) _LOGGER = logging.getLogger(__name__) -class RoborockDataUpdateCoordinator( - DataUpdateCoordinator[dict[str, RoborockDeviceProp]] -): +class RoborockDataUpdateCoordinator(DataUpdateCoordinator[dict[str, DeviceProp]]): """Class to manage fetching data from the API.""" def __init__( @@ -50,7 +48,7 @@ class RoborockDataUpdateCoordinator( device, networking, product_info[device.product_id], - RoborockDeviceProp(), + DeviceProp(), ) local_devices_info[device.duid] = RoborockLocalDeviceInfo( device, networking @@ -71,7 +69,7 @@ class RoborockDataUpdateCoordinator( else: device_info.props = device_prop - async def _async_update_data(self) -> dict[str, RoborockDeviceProp]: + async def _async_update_data(self) -> dict[str, DeviceProp]: """Update data via library.""" try: await asyncio.gather( diff --git a/homeassistant/components/roborock/manifest.json b/homeassistant/components/roborock/manifest.json index 20dee34db05..f433aee25c4 100644 --- a/homeassistant/components/roborock/manifest.json +++ b/homeassistant/components/roborock/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/roborock", "iot_class": "local_polling", "loggers": ["roborock"], - "requirements": ["python-roborock==0.6.5"] + "requirements": ["python-roborock==0.8.1"] } diff --git a/homeassistant/components/roborock/models.py b/homeassistant/components/roborock/models.py index ae0adb4ad7d..0377cebd425 100644 --- a/homeassistant/components/roborock/models.py +++ b/homeassistant/components/roborock/models.py @@ -2,7 +2,7 @@ from dataclasses import dataclass from roborock.containers import HomeDataDevice, HomeDataProduct, NetworkInfo -from roborock.typing import RoborockDeviceProp +from roborock.typing import DeviceProp @dataclass @@ -12,4 +12,4 @@ class RoborockHassDeviceInfo: device: HomeDataDevice network_info: NetworkInfo product: HomeDataProduct - props: RoborockDeviceProp + props: DeviceProp diff --git a/homeassistant/components/roborock/strings.json b/homeassistant/components/roborock/strings.json index 7e755a0c41f..6bd19787d20 100644 --- a/homeassistant/components/roborock/strings.json +++ b/homeassistant/components/roborock/strings.json @@ -17,6 +17,9 @@ "error": { "invalid_code": "The code you entered was incorrect, please check it and try again.", "invalid_email": "There is no account associated with the email you entered, please try again.", + "invalid_email_format": "There is an issue with the formatting of your email - please try again.", + "unknown_roborock": "There was an unknown roborock exception - please check your logs.", + "unknown_url": "There was an issue determining the correct url for your roborock account - please check your logs.", "unknown": "[%key:common::config_flow::error::unknown%]" }, "abort": { diff --git a/requirements_all.txt b/requirements_all.txt index 9672ed19c9a..d1523565445 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2108,7 +2108,7 @@ python-qbittorrent==0.4.2 python-ripple-api==0.0.3 # homeassistant.components.roborock -python-roborock==0.6.5 +python-roborock==0.8.1 # homeassistant.components.smarttub python-smarttub==0.0.33 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f1049c0ad30..6a91880a6d0 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1516,7 +1516,7 @@ python-picnic-api==1.1.0 python-qbittorrent==0.4.2 # homeassistant.components.roborock -python-roborock==0.6.5 +python-roborock==0.8.1 # homeassistant.components.smarttub python-smarttub==0.0.33 diff --git a/tests/components/roborock/mock_data.py b/tests/components/roborock/mock_data.py index d6afff440f7..cbd5ef379e8 100644 --- a/tests/components/roborock/mock_data.py +++ b/tests/components/roborock/mock_data.py @@ -10,7 +10,7 @@ from roborock.containers import ( Status, UserData, ) -from roborock.typing import RoborockDeviceProp +from roborock.typing import DeviceProp # All data is based on a U.S. customer with a Roborock S7 MaxV Ultra USER_EMAIL = "user@domain.com" @@ -367,4 +367,4 @@ STATUS = Status.from_dict( } ) -PROP = RoborockDeviceProp(STATUS, DND_TIMER, CLEAN_SUMMARY, CONSUMABLE, CLEAN_RECORD) +PROP = DeviceProp(STATUS, DND_TIMER, CLEAN_SUMMARY, CONSUMABLE, CLEAN_RECORD) diff --git a/tests/components/roborock/test_config_flow.py b/tests/components/roborock/test_config_flow.py index d319f0e165d..2f297135d15 100644 --- a/tests/components/roborock/test_config_flow.py +++ b/tests/components/roborock/test_config_flow.py @@ -2,7 +2,13 @@ from unittest.mock import patch import pytest -from roborock.exceptions import RoborockException +from roborock.exceptions import ( + RoborockAccountDoesNotExist, + RoborockException, + RoborockInvalidCode, + RoborockInvalidEmail, + RoborockUrlException, +) from homeassistant import config_entries, data_entry_flow from homeassistant.components.roborock.const import CONF_ENTRY_CODE, DOMAIN @@ -55,7 +61,10 @@ async def test_config_flow_success( "request_code_errors", ), [ - (RoborockException(), {"base": "invalid_email"}), + (RoborockException(), {"base": "unknown_roborock"}), + (RoborockAccountDoesNotExist(), {"base": "invalid_email"}), + (RoborockInvalidEmail(), {"base": "invalid_email_format"}), + (RoborockUrlException(), {"base": "unknown_url"}), (Exception(), {"base": "unknown"}), ], ) @@ -115,7 +124,8 @@ async def test_config_flow_failures_request_code( "code_login_errors", ), [ - (RoborockException(), {"base": "invalid_code"}), + (RoborockException(), {"base": "unknown_roborock"}), + (RoborockInvalidCode(), {"base": "invalid_code"}), (Exception(), {"base": "unknown"}), ], )