291 files
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
from ....const import DOMAIN
|
||||
@@ -54,11 +54,17 @@ def step_amount(entity: InputNumber, call: ServiceCall) -> float:
|
||||
math.isclose(remainder, 0, rel_tol=0, abs_tol=_FLOAT_TOLERANCE)
|
||||
or math.isclose(remainder, step, rel_tol=0, abs_tol=_FLOAT_TOLERANCE)
|
||||
):
|
||||
msg = (
|
||||
f"Amount {amount} not valid for {entity.entity_id}, "
|
||||
f"it needs to be a multiple of {step}"
|
||||
# A validation error, so the frontend shows this message. It shows a
|
||||
# plain ValueError as "Unknown error".
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="amount_not_a_multiple_of_step",
|
||||
translation_placeholders={
|
||||
"amount": str(amount),
|
||||
"entity_id": entity.entity_id,
|
||||
"step": str(step),
|
||||
},
|
||||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
return amount
|
||||
|
||||
|
||||
Reference in New Issue
Block a user