mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Improve user-facing error messages in HomeWizard Energy (#104547)
This commit is contained in:
parent
670e5a2eae
commit
321b24b146
@ -8,6 +8,7 @@ from homewizard_energy.errors import DisabledError, RequestError
|
|||||||
|
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
from .entity import HomeWizardEntity
|
from .entity import HomeWizardEntity
|
||||||
|
|
||||||
_HomeWizardEntityT = TypeVar("_HomeWizardEntityT", bound=HomeWizardEntity)
|
_HomeWizardEntityT = TypeVar("_HomeWizardEntityT", bound=HomeWizardEntity)
|
||||||
@ -30,11 +31,19 @@ def homewizard_exception_handler(
|
|||||||
try:
|
try:
|
||||||
await func(self, *args, **kwargs)
|
await func(self, *args, **kwargs)
|
||||||
except RequestError as ex:
|
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:
|
except DisabledError as ex:
|
||||||
await self.hass.config_entries.async_reload(
|
await self.hass.config_entries.async_reload(
|
||||||
self.coordinator.config_entry.entry_id
|
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
|
return handler
|
||||||
|
@ -167,5 +167,13 @@
|
|||||||
"name": "Cloud connection"
|
"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
|
# Raise RequestError when identify is called
|
||||||
mock_homewizardenergy.identify.side_effect = RequestError()
|
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(
|
await hass.services.async_call(
|
||||||
button.DOMAIN,
|
button.DOMAIN,
|
||||||
button.SERVICE_PRESS,
|
button.SERVICE_PRESS,
|
||||||
@ -73,7 +76,10 @@ async def test_identify_button(
|
|||||||
# Raise RequestError when identify is called
|
# Raise RequestError when identify is called
|
||||||
mock_homewizardenergy.identify.side_effect = DisabledError()
|
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(
|
await hass.services.async_call(
|
||||||
button.DOMAIN,
|
button.DOMAIN,
|
||||||
button.SERVICE_PRESS,
|
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.assert_called_with(brightness=127)
|
||||||
|
|
||||||
mock_homewizardenergy.state_set.side_effect = RequestError
|
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(
|
await hass.services.async_call(
|
||||||
number.DOMAIN,
|
number.DOMAIN,
|
||||||
SERVICE_SET_VALUE,
|
SERVICE_SET_VALUE,
|
||||||
@ -79,7 +82,10 @@ async def test_number_entities(
|
|||||||
)
|
)
|
||||||
|
|
||||||
mock_homewizardenergy.state_set.side_effect = DisabledError
|
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(
|
await hass.services.async_call(
|
||||||
number.DOMAIN,
|
number.DOMAIN,
|
||||||
SERVICE_SET_VALUE,
|
SERVICE_SET_VALUE,
|
||||||
|
@ -120,7 +120,10 @@ async def test_switch_entities(
|
|||||||
# Test request error handling
|
# Test request error handling
|
||||||
mocked_method.side_effect = RequestError
|
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(
|
await hass.services.async_call(
|
||||||
switch.DOMAIN,
|
switch.DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
@ -128,7 +131,10 @@ async def test_switch_entities(
|
|||||||
blocking=True,
|
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(
|
await hass.services.async_call(
|
||||||
switch.DOMAIN,
|
switch.DOMAIN,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
@ -139,7 +145,10 @@ async def test_switch_entities(
|
|||||||
# Test disabled error handling
|
# Test disabled error handling
|
||||||
mocked_method.side_effect = DisabledError
|
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(
|
await hass.services.async_call(
|
||||||
switch.DOMAIN,
|
switch.DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
@ -147,7 +156,10 @@ async def test_switch_entities(
|
|||||||
blocking=True,
|
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(
|
await hass.services.async_call(
|
||||||
switch.DOMAIN,
|
switch.DOMAIN,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user