mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 22:18:40 +00:00
Add exception handling for rate limited or unauthorized MQTT requests (#158997)
This commit is contained in:
committed by
Bram Kragten
parent
b608dcb2eb
commit
d64313cd28
@@ -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(
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user