Add translation for tedee exceptions (#126963)
parent
8a266aac34
commit
d9eb419ecc
|
@ -10,6 +10,7 @@ from homeassistant.exceptions import HomeAssistantError
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import TedeeConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .coordinator import TedeeApiCoordinator
|
||||
from .entity import TedeeEntity
|
||||
|
||||
|
@ -108,7 +109,9 @@ class TedeeLockEntity(TedeeEntity, LockEntity):
|
|||
await self.coordinator.async_request_refresh()
|
||||
except (TedeeClientException, Exception) as ex:
|
||||
raise HomeAssistantError(
|
||||
f"Failed to unlock the door. Lock {self._lock.lock_id}"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="unlock_failed",
|
||||
translation_placeholders={"lock_id": str(self._lock.lock_id)},
|
||||
) from ex
|
||||
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
|
@ -121,7 +124,9 @@ class TedeeLockEntity(TedeeEntity, LockEntity):
|
|||
await self.coordinator.async_request_refresh()
|
||||
except (TedeeClientException, Exception) as ex:
|
||||
raise HomeAssistantError(
|
||||
f"Failed to lock the door. Lock {self._lock.lock_id}"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="lock_failed",
|
||||
translation_placeholders={"lock_id": str(self._lock.lock_id)},
|
||||
) from ex
|
||||
|
||||
|
||||
|
@ -143,5 +148,7 @@ class TedeeLockWithLatchEntity(TedeeLockEntity):
|
|||
await self.coordinator.async_request_refresh()
|
||||
except (TedeeClientException, Exception) as ex:
|
||||
raise HomeAssistantError(
|
||||
f"Failed to unlatch the door. Lock {self._lock.lock_id}"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="open_failed",
|
||||
translation_placeholders={"lock_id": str(self._lock.lock_id)},
|
||||
) from ex
|
||||
|
|
|
@ -63,5 +63,16 @@
|
|||
"name": "Pullspring duration"
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"lock_failed": {
|
||||
"message": "Failed to lock the door. Lock {lock_id}"
|
||||
},
|
||||
"unlock_failed": {
|
||||
"message": "Failed to unlock the door. Lock {lock_id}"
|
||||
},
|
||||
"open_failed": {
|
||||
"message": "Failed to unlatch the door. Lock {lock_id}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ async def test_lock_errors(
|
|||
) -> None:
|
||||
"""Test event errors."""
|
||||
mock_tedee.lock.side_effect = TedeeClientException("Boom")
|
||||
with pytest.raises(HomeAssistantError, match="Failed to lock the door. Lock 12345"):
|
||||
with pytest.raises(HomeAssistantError) as exc_info:
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_LOCK,
|
||||
|
@ -161,11 +161,10 @@ async def test_lock_errors(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert exc_info.value.translation_key == "lock_failed"
|
||||
|
||||
mock_tedee.unlock.side_effect = TedeeClientException("Boom")
|
||||
with pytest.raises(
|
||||
HomeAssistantError, match="Failed to unlock the door. Lock 12345"
|
||||
):
|
||||
with pytest.raises(HomeAssistantError) as exc_info:
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_UNLOCK,
|
||||
|
@ -174,11 +173,10 @@ async def test_lock_errors(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert exc_info.value.translation_key == "unlock_failed"
|
||||
|
||||
mock_tedee.open.side_effect = TedeeClientException("Boom")
|
||||
with pytest.raises(
|
||||
HomeAssistantError, match="Failed to unlatch the door. Lock 12345"
|
||||
):
|
||||
with pytest.raises(HomeAssistantError) as exc_info:
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_OPEN,
|
||||
|
@ -187,6 +185,7 @@ async def test_lock_errors(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert exc_info.value.translation_key == "open_failed"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
Loading…
Reference in New Issue