diff --git a/homeassistant/components/knx/quality_scale.yaml b/homeassistant/components/knx/quality_scale.yaml index a6bbaf18bcb..63aa4578159 100644 --- a/homeassistant/components/knx/quality_scale.yaml +++ b/homeassistant/components/knx/quality_scale.yaml @@ -99,7 +99,7 @@ rules: status: exempt comment: | Since all entities are configured manually, names are user-defined. - exception-translations: todo + exception-translations: done icon-translations: done reconfiguration-flow: todo repair-issues: todo diff --git a/homeassistant/components/knx/services.py b/homeassistant/components/knx/services.py index fc28e0850ed..7b8c7ec2371 100644 --- a/homeassistant/components/knx/services.py +++ b/homeassistant/components/knx/services.py @@ -87,7 +87,9 @@ def get_knx_module(hass: HomeAssistant) -> KNXModule: try: return hass.data[KNX_MODULE_KEY] 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( @@ -166,7 +168,11 @@ async def service_exposure_register_modify(call: ServiceCall) -> None: removed_exposure = knx_module.service_exposures.pop(group_address) except KeyError as err: 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 removed_exposure.async_remove() @@ -234,13 +240,17 @@ async def service_send_to_knx_bus(call: ServiceCall) -> None: transcoder = DPTBase.parse_transcoder(attr_type) if transcoder is None: 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: payload = transcoder.to_knx(attr_payload) except ConversionError as err: 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 elif isinstance(attr_payload, int): payload = DPTBinary(attr_payload) diff --git a/homeassistant/components/knx/strings.json b/homeassistant/components/knx/strings.json index 77228ea34d9..a4195dc7d2d 100644 --- a/homeassistant/components/knx/strings.json +++ b/homeassistant/components/knx/strings.json @@ -143,6 +143,20 @@ "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": { "step": { "init": { diff --git a/tests/components/knx/test_services.py b/tests/components/knx/test_services.py index c4b48b5e81d..617d2f31bc0 100644 --- a/tests/components/knx/test_services.py +++ b/tests/components/knx/test_services.py @@ -6,6 +6,7 @@ import pytest from xknx.telegram.apci import GroupValueResponse, GroupValueWrite 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.core import HomeAssistant 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}, 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"