Skip to content

Commit bb08b31

Browse files
authored
Add exception handling for rate limited or unauthorized MQTT requests (home-assistant#158997)
1 parent 50621df commit bb08b31

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

homeassistant/components/roborock/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from roborock.devices.device import RoborockDevice
1919
from roborock.devices.device_manager import UserParams, create_device_manager
2020
from roborock.map.map_parser import MapParserConfig
21+
from roborock.mqtt.session import MqttSessionUnauthorized
2122

2223
from homeassistant.const import CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
2324
from homeassistant.core import Event, HomeAssistant
@@ -92,6 +93,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: RoborockConfigEntry) ->
9293
translation_domain=DOMAIN,
9394
translation_key="no_user_agreement",
9495
) from err
96+
except MqttSessionUnauthorized as err:
97+
raise ConfigEntryAuthFailed(
98+
translation_domain=DOMAIN,
99+
translation_key="mqtt_unauthorized",
100+
) from err
95101
except RoborockException as err:
96102
_LOGGER.debug("Failed to get Roborock home data: %s", err)
97103
raise ConfigEntryNotReady(

homeassistant/components/roborock/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@
426426
"map_failure": {
427427
"message": "Something went wrong creating the map"
428428
},
429+
"mqtt_unauthorized": {
430+
"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."
431+
},
429432
"no_coordinators": {
430433
"message": "No devices were able to successfully setup"
431434
},

tests/components/roborock/test_init.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
RoborockNoUserAgreement,
1414
)
1515
from roborock.exceptions import RoborockException
16+
from roborock.mqtt.session import MqttSessionUnauthorized
1617

1718
from homeassistant.components.homeassistant import (
1819
DOMAIN as HA_DOMAIN,
@@ -70,13 +71,18 @@ async def test_home_assistant_stop(
7071
assert device_manager.close.called
7172

7273

74+
@pytest.mark.parametrize(
75+
"side_effect", [RoborockInvalidCredentials(), MqttSessionUnauthorized()]
76+
)
7377
async def test_reauth_started(
74-
hass: HomeAssistant, mock_roborock_entry: MockConfigEntry
78+
hass: HomeAssistant,
79+
mock_roborock_entry: MockConfigEntry,
80+
side_effect: Exception,
7581
) -> None:
7682
"""Test reauth flow started."""
7783
with patch(
7884
"homeassistant.components.roborock.create_device_manager",
79-
side_effect=RoborockInvalidCredentials(),
85+
side_effect=side_effect,
8086
):
8187
await async_setup_component(hass, DOMAIN, {})
8288
await hass.async_block_till_done()

0 commit comments

Comments
 (0)