mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Add exception translations to Renault (#143452)
This commit is contained in:
parent
2d20df37b1
commit
6f9c8b2aa0
@ -52,7 +52,7 @@ rules:
|
|||||||
entity-device-class: done
|
entity-device-class: done
|
||||||
entity-disabled-by-default: done
|
entity-disabled-by-default: done
|
||||||
entity-translations: done
|
entity-translations: done
|
||||||
exception-translations: todo
|
exception-translations: done
|
||||||
icon-translations: done
|
icon-translations: done
|
||||||
reconfiguration-flow: todo
|
reconfiguration-flow: todo
|
||||||
repair-issues: done
|
repair-issues: done
|
||||||
|
@ -43,7 +43,11 @@ def with_error_wrapping[**_P, _R](
|
|||||||
try:
|
try:
|
||||||
return await func(self, *args, **kwargs)
|
return await func(self, *args, **kwargs)
|
||||||
except RenaultException as err:
|
except RenaultException as err:
|
||||||
raise HomeAssistantError(err) from err
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="unknown_error",
|
||||||
|
translation_placeholders={"error": str(err)},
|
||||||
|
) from err
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@ -232,6 +232,9 @@
|
|||||||
},
|
},
|
||||||
"no_config_entry_for_device": {
|
"no_config_entry_for_device": {
|
||||||
"message": "No loaded config entry was found for device with ID {device_id}"
|
"message": "No loaded config entry was found for device with ID {device_id}"
|
||||||
|
},
|
||||||
|
"unknown_error": {
|
||||||
|
"message": "An unknown error occurred while communicating with the Renault servers: {error}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,13 +72,14 @@ async def test_service_set_ac_cancel(
|
|||||||
ATTR_VEHICLE: get_device_id(hass),
|
ATTR_VEHICLE: get_device_id(hass),
|
||||||
}
|
}
|
||||||
|
|
||||||
with (
|
with patch(
|
||||||
patch(
|
"renault_api.renault_vehicle.RenaultVehicle.set_ac_stop",
|
||||||
"renault_api.renault_vehicle.RenaultVehicle.set_ac_stop",
|
return_value=(
|
||||||
side_effect=RenaultException("Didn't work"),
|
schemas.KamereonVehicleHvacStartActionDataSchema.loads(
|
||||||
) as mock_action,
|
load_fixture("renault/action.set_ac_stop.json")
|
||||||
pytest.raises(HomeAssistantError, match="Didn't work"),
|
)
|
||||||
):
|
),
|
||||||
|
) as mock_action:
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN, SERVICE_AC_CANCEL, service_data=data, blocking=True
|
DOMAIN, SERVICE_AC_CANCEL, service_data=data, blocking=True
|
||||||
)
|
)
|
||||||
@ -380,3 +381,28 @@ async def test_service_invalid_device_id2(
|
|||||||
)
|
)
|
||||||
assert err.value.translation_key == "no_config_entry_for_device"
|
assert err.value.translation_key == "no_config_entry_for_device"
|
||||||
assert err.value.translation_placeholders == {"device_id": "REG-NUMBER"}
|
assert err.value.translation_placeholders == {"device_id": "REG-NUMBER"}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_service_exception(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry
|
||||||
|
) -> None:
|
||||||
|
"""Test that service invokes renault_api with correct data."""
|
||||||
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
data = {
|
||||||
|
ATTR_VEHICLE: get_device_id(hass),
|
||||||
|
}
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch(
|
||||||
|
"renault_api.renault_vehicle.RenaultVehicle.set_ac_stop",
|
||||||
|
side_effect=RenaultException("Didn't work"),
|
||||||
|
) as mock_action,
|
||||||
|
pytest.raises(HomeAssistantError, match="Didn't work"),
|
||||||
|
):
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN, SERVICE_AC_CANCEL, service_data=data, blocking=True
|
||||||
|
)
|
||||||
|
assert len(mock_action.mock_calls) == 1
|
||||||
|
assert mock_action.mock_calls[0][1] == ()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user