diff --git a/homeassistant/components/roborock/__init__.py b/homeassistant/components/roborock/__init__.py index 5d67233f7bc..a63fa0e65c1 100644 --- a/homeassistant/components/roborock/__init__.py +++ b/homeassistant/components/roborock/__init__.py @@ -18,6 +18,7 @@ from roborock.data import UserData from roborock.devices.device import RoborockDevice from roborock.devices.device_manager import UserParams, create_device_manager from roborock.map.map_parser import MapParserConfig +from roborock.mqtt.session import MqttSessionUnauthorized from homeassistant.const import CONF_USERNAME, EVENT_HOMEASSISTANT_STOP from homeassistant.core import Event, HomeAssistant @@ -92,6 +93,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: RoborockConfigEntry) -> translation_domain=DOMAIN, translation_key="no_user_agreement", ) from err + except MqttSessionUnauthorized as err: + raise ConfigEntryAuthFailed( + translation_domain=DOMAIN, + translation_key="mqtt_unauthorized", + ) from err except RoborockException as err: _LOGGER.debug("Failed to get Roborock home data: %s", err) raise ConfigEntryNotReady( diff --git a/homeassistant/components/roborock/strings.json b/homeassistant/components/roborock/strings.json index 3c08b9e985d..23e9d9dd44b 100644 --- a/homeassistant/components/roborock/strings.json +++ b/homeassistant/components/roborock/strings.json @@ -424,6 +424,9 @@ "map_failure": { "message": "Something went wrong creating the map" }, + "mqtt_unauthorized": { + "message": "Roborock MQTT servers rejected the connection due to rate limiting or invalid credentials. You may either attempt to reauthenticate or wait and reload the integration." + }, "no_coordinators": { "message": "No devices were able to successfully setup" }, diff --git a/tests/components/roborock/test_init.py b/tests/components/roborock/test_init.py index 85d0983df04..8ed1ebaad16 100644 --- a/tests/components/roborock/test_init.py +++ b/tests/components/roborock/test_init.py @@ -13,6 +13,7 @@ from roborock import ( RoborockNoUserAgreement, ) from roborock.exceptions import RoborockException +from roborock.mqtt.session import MqttSessionUnauthorized from homeassistant.components.homeassistant import ( DOMAIN as HA_DOMAIN, @@ -70,13 +71,18 @@ async def test_home_assistant_stop( assert device_manager.close.called +@pytest.mark.parametrize( + "side_effect", [RoborockInvalidCredentials(), MqttSessionUnauthorized()] +) async def test_reauth_started( - hass: HomeAssistant, mock_roborock_entry: MockConfigEntry + hass: HomeAssistant, + mock_roborock_entry: MockConfigEntry, + side_effect: Exception, ) -> None: """Test reauth flow started.""" with patch( "homeassistant.components.roborock.create_device_manager", - side_effect=RoborockInvalidCredentials(), + side_effect=side_effect, ): await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done()