429 files
This commit is contained in:
1 parent
472c19bceb
commit
963cce81a7
566 files changed
+50311
-47616
No files matched your search
@@ -29,11 +29,18 @@ class SpookService(AbstractSpookEntityComponentService[NumberEntity]):
|
||||
call: ServiceCall,
|
||||
) -> None:
|
||||
"""Handle the service call."""
|
||||
amount = call.data.get("amount", entity.step or 1)
|
||||
if not math.isclose(amount % entity.step, 0, abs_tol=1e-9):
|
||||
step = entity.step or 1
|
||||
amount = call.data.get("amount", step)
|
||||
remainder = amount % step
|
||||
# Float modulo wraps around just short of the step, 0.3 % 0.1 is
|
||||
# 0.09999999999999998, so a remainder against either end is a clean multiple.
|
||||
if not (
|
||||
math.isclose(remainder, 0, rel_tol=0, abs_tol=1e-9)
|
||||
or math.isclose(remainder, step, rel_tol=0, abs_tol=1e-9)
|
||||
):
|
||||
msg = (
|
||||
f"Amount {amount} not valid for {entity.entity_id}, "
|
||||
f"it needs to be a multiple of {entity.step}"
|
||||
f"it needs to be a multiple of {step}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
Reference in new issue
Block a user