mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 23:07:09 +00:00
Add translation for tedee exceptions (#126963)
This commit is contained in:
parent
8a266aac34
commit
d9eb419ecc
@ -10,6 +10,7 @@ from homeassistant.exceptions import HomeAssistantError
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import TedeeConfigEntry
|
from . import TedeeConfigEntry
|
||||||
|
from .const import DOMAIN
|
||||||
from .coordinator import TedeeApiCoordinator
|
from .coordinator import TedeeApiCoordinator
|
||||||
from .entity import TedeeEntity
|
from .entity import TedeeEntity
|
||||||
|
|
||||||
@ -108,7 +109,9 @@ class TedeeLockEntity(TedeeEntity, LockEntity):
|
|||||||
await self.coordinator.async_request_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
except (TedeeClientException, Exception) as ex:
|
except (TedeeClientException, Exception) as ex:
|
||||||
raise HomeAssistantError(
|
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
|
) from ex
|
||||||
|
|
||||||
async def async_lock(self, **kwargs: Any) -> None:
|
async def async_lock(self, **kwargs: Any) -> None:
|
||||||
@ -121,7 +124,9 @@ class TedeeLockEntity(TedeeEntity, LockEntity):
|
|||||||
await self.coordinator.async_request_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
except (TedeeClientException, Exception) as ex:
|
except (TedeeClientException, Exception) as ex:
|
||||||
raise HomeAssistantError(
|
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
|
) from ex
|
||||||
|
|
||||||
|
|
||||||
@ -143,5 +148,7 @@ class TedeeLockWithLatchEntity(TedeeLockEntity):
|
|||||||
await self.coordinator.async_request_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
except (TedeeClientException, Exception) as ex:
|
except (TedeeClientException, Exception) as ex:
|
||||||
raise HomeAssistantError(
|
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
|
) from ex
|
||||||
|
@ -63,5 +63,16 @@
|
|||||||
"name": "Pullspring duration"
|
"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:
|
) -> None:
|
||||||
"""Test event errors."""
|
"""Test event errors."""
|
||||||
mock_tedee.lock.side_effect = TedeeClientException("Boom")
|
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(
|
await hass.services.async_call(
|
||||||
LOCK_DOMAIN,
|
LOCK_DOMAIN,
|
||||||
SERVICE_LOCK,
|
SERVICE_LOCK,
|
||||||
@ -161,11 +161,10 @@ async def test_lock_errors(
|
|||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
assert exc_info.value.translation_key == "lock_failed"
|
||||||
|
|
||||||
mock_tedee.unlock.side_effect = TedeeClientException("Boom")
|
mock_tedee.unlock.side_effect = TedeeClientException("Boom")
|
||||||
with pytest.raises(
|
with pytest.raises(HomeAssistantError) as exc_info:
|
||||||
HomeAssistantError, match="Failed to unlock the door. Lock 12345"
|
|
||||||
):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LOCK_DOMAIN,
|
LOCK_DOMAIN,
|
||||||
SERVICE_UNLOCK,
|
SERVICE_UNLOCK,
|
||||||
@ -174,11 +173,10 @@ async def test_lock_errors(
|
|||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
assert exc_info.value.translation_key == "unlock_failed"
|
||||||
|
|
||||||
mock_tedee.open.side_effect = TedeeClientException("Boom")
|
mock_tedee.open.side_effect = TedeeClientException("Boom")
|
||||||
with pytest.raises(
|
with pytest.raises(HomeAssistantError) as exc_info:
|
||||||
HomeAssistantError, match="Failed to unlatch the door. Lock 12345"
|
|
||||||
):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LOCK_DOMAIN,
|
LOCK_DOMAIN,
|
||||||
SERVICE_OPEN,
|
SERVICE_OPEN,
|
||||||
@ -187,6 +185,7 @@ async def test_lock_errors(
|
|||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
assert exc_info.value.translation_key == "open_failed"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user