Improve user-facing error messages in HomeWizard Energy (#104547)
parent
670e5a2eae
commit
321b24b146
|
@ -8,6 +8,7 @@ from homewizard_energy.errors import DisabledError, RequestError
|
|||
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
from .const import DOMAIN
|
||||
from .entity import HomeWizardEntity
|
||||
|
||||
_HomeWizardEntityT = TypeVar("_HomeWizardEntityT", bound=HomeWizardEntity)
|
||||
|
@ -30,11 +31,19 @@ def homewizard_exception_handler(
|
|||
try:
|
||||
await func(self, *args, **kwargs)
|
||||
except RequestError as ex:
|
||||
raise HomeAssistantError from ex
|
||||
raise HomeAssistantError(
|
||||
"An error occurred while communicating with HomeWizard device",
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="communication_error",
|
||||
) from ex
|
||||
except DisabledError as ex:
|
||||
await self.hass.config_entries.async_reload(
|
||||
self.coordinator.config_entry.entry_id
|
||||
)
|
||||
raise HomeAssistantError from ex
|
||||
raise HomeAssistantError(
|
||||
"The local API of the HomeWizard device is disabled",
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="api_disabled",
|
||||
) from ex
|
||||
|
||||
return handler
|
||||
|
|
|
@ -167,5 +167,13 @@
|
|||
"name": "Cloud connection"
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"api_disabled": {
|
||||
"message": "The local API of the HomeWizard device is disabled"
|
||||
},
|
||||
"communication_error": {
|
||||
"message": "An error occurred while communicating with HomeWizard device"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,10 @@ async def test_identify_button(
|
|||
# Raise RequestError when identify is called
|
||||
mock_homewizardenergy.identify.side_effect = RequestError()
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=r"^An error occurred while communicating with HomeWizard device$",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
button.DOMAIN,
|
||||
button.SERVICE_PRESS,
|
||||
|
@ -73,7 +76,10 @@ async def test_identify_button(
|
|||
# Raise RequestError when identify is called
|
||||
mock_homewizardenergy.identify.side_effect = DisabledError()
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=r"^The local API of the HomeWizard device is disabled$",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
button.DOMAIN,
|
||||
button.SERVICE_PRESS,
|
||||
|
|
|
@ -67,7 +67,10 @@ async def test_number_entities(
|
|||
mock_homewizardenergy.state_set.assert_called_with(brightness=127)
|
||||
|
||||
mock_homewizardenergy.state_set.side_effect = RequestError
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=r"^An error occurred while communicating with HomeWizard device$",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
number.DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
|
@ -79,7 +82,10 @@ async def test_number_entities(
|
|||
)
|
||||
|
||||
mock_homewizardenergy.state_set.side_effect = DisabledError
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=r"^The local API of the HomeWizard device is disabled$",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
number.DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
|
|
|
@ -120,7 +120,10 @@ async def test_switch_entities(
|
|||
# Test request error handling
|
||||
mocked_method.side_effect = RequestError
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=r"^An error occurred while communicating with HomeWizard device$",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
switch.DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
|
@ -128,7 +131,10 @@ async def test_switch_entities(
|
|||
blocking=True,
|
||||
)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=r"^An error occurred while communicating with HomeWizard device$",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
switch.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
|
@ -139,7 +145,10 @@ async def test_switch_entities(
|
|||
# Test disabled error handling
|
||||
mocked_method.side_effect = DisabledError
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=r"^The local API of the HomeWizard device is disabled$",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
switch.DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
|
@ -147,7 +156,10 @@ async def test_switch_entities(
|
|||
blocking=True,
|
||||
)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=r"^The local API of the HomeWizard device is disabled$",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
switch.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
|
|
Loading…
Reference in New Issue