mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add exception translations for KNX services (#146104)
This commit is contained in:
parent
842e7ce171
commit
980dbf364d
@ -99,7 +99,7 @@ rules:
|
|||||||
status: exempt
|
status: exempt
|
||||||
comment: |
|
comment: |
|
||||||
Since all entities are configured manually, names are user-defined.
|
Since all entities are configured manually, names are user-defined.
|
||||||
exception-translations: todo
|
exception-translations: done
|
||||||
icon-translations: done
|
icon-translations: done
|
||||||
reconfiguration-flow: todo
|
reconfiguration-flow: todo
|
||||||
repair-issues: todo
|
repair-issues: todo
|
||||||
|
@ -87,7 +87,9 @@ def get_knx_module(hass: HomeAssistant) -> KNXModule:
|
|||||||
try:
|
try:
|
||||||
return hass.data[KNX_MODULE_KEY]
|
return hass.data[KNX_MODULE_KEY]
|
||||||
except KeyError as err:
|
except KeyError as err:
|
||||||
raise HomeAssistantError("KNX entry not loaded") from err
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN, translation_key="integration_not_loaded"
|
||||||
|
) from err
|
||||||
|
|
||||||
|
|
||||||
SERVICE_KNX_EVENT_REGISTER_SCHEMA = vol.Schema(
|
SERVICE_KNX_EVENT_REGISTER_SCHEMA = vol.Schema(
|
||||||
@ -166,7 +168,11 @@ async def service_exposure_register_modify(call: ServiceCall) -> None:
|
|||||||
removed_exposure = knx_module.service_exposures.pop(group_address)
|
removed_exposure = knx_module.service_exposures.pop(group_address)
|
||||||
except KeyError as err:
|
except KeyError as err:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
f"Could not find exposure for '{group_address}' to remove."
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="service_exposure_remove_not_found",
|
||||||
|
translation_placeholders={
|
||||||
|
"group_address": group_address,
|
||||||
|
},
|
||||||
) from err
|
) from err
|
||||||
|
|
||||||
removed_exposure.async_remove()
|
removed_exposure.async_remove()
|
||||||
@ -234,13 +240,17 @@ async def service_send_to_knx_bus(call: ServiceCall) -> None:
|
|||||||
transcoder = DPTBase.parse_transcoder(attr_type)
|
transcoder = DPTBase.parse_transcoder(attr_type)
|
||||||
if transcoder is None:
|
if transcoder is None:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
f"Invalid type for knx.send service: {attr_type}"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="service_send_invalid_type",
|
||||||
|
translation_placeholders={"type": attr_type},
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
payload = transcoder.to_knx(attr_payload)
|
payload = transcoder.to_knx(attr_payload)
|
||||||
except ConversionError as err:
|
except ConversionError as err:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
f"Invalid payload for knx.send service: {err}"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="service_send_invalid_payload",
|
||||||
|
translation_placeholders={"error": str(err)},
|
||||||
) from err
|
) from err
|
||||||
elif isinstance(attr_payload, int):
|
elif isinstance(attr_payload, int):
|
||||||
payload = DPTBinary(attr_payload)
|
payload = DPTBinary(attr_payload)
|
||||||
|
@ -143,6 +143,20 @@
|
|||||||
"unsupported_tunnel_type": "Selected tunneling type not supported by gateway."
|
"unsupported_tunnel_type": "Selected tunneling type not supported by gateway."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"exceptions": {
|
||||||
|
"integration_not_loaded": {
|
||||||
|
"message": "KNX integration is not loaded."
|
||||||
|
},
|
||||||
|
"service_exposure_remove_not_found": {
|
||||||
|
"message": "Could not find exposure for `{group_address}` to remove."
|
||||||
|
},
|
||||||
|
"service_send_invalid_payload": {
|
||||||
|
"message": "Invalid payload for `knx.send` service. {error}"
|
||||||
|
},
|
||||||
|
"service_send_invalid_type": {
|
||||||
|
"message": "Invalid type for `knx.send` service: {type}"
|
||||||
|
}
|
||||||
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"step": {
|
"step": {
|
||||||
"init": {
|
"init": {
|
||||||
|
@ -6,6 +6,7 @@ import pytest
|
|||||||
from xknx.telegram.apci import GroupValueResponse, GroupValueWrite
|
from xknx.telegram.apci import GroupValueResponse, GroupValueWrite
|
||||||
|
|
||||||
from homeassistant.components.knx import async_unload_entry as knx_async_unload_entry
|
from homeassistant.components.knx import async_unload_entry as knx_async_unload_entry
|
||||||
|
from homeassistant.components.knx.const import DOMAIN
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -295,4 +296,5 @@ async def test_service_setup_failed(hass: HomeAssistant, knx: KNXTestKit) -> Non
|
|||||||
{"address": "1/2/3", "payload": True, "response": False},
|
{"address": "1/2/3", "payload": True, "response": False},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert str(exc_info.value) == "KNX entry not loaded"
|
assert exc_info.value.translation_domain == DOMAIN
|
||||||
|
assert exc_info.value.translation_key == "integration_not_loaded"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user