File tree Expand file tree Collapse file tree
custom_components/spook/ectoplasms/number/services
tests/ectoplasms/number/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ async def async_handle_service(
3333 if not math .isclose (amount % entity .step , 0 , abs_tol = 1e-9 ):
3434 msg = (
3535 f"Amount { amount } not valid for { entity .entity_id } , "
36- f"it needs to be a multiple of { entity .step } " ,
36+ f"it needs to be a multiple of { entity .step } "
3737 )
3838 raise ValueError (msg )
3939
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ async def async_handle_service(
3333 if not math .isclose (amount % entity .step , 0 , abs_tol = 1e-9 ):
3434 msg = (
3535 f"Amount { amount } not valid for { entity .entity_id } , "
36- f"it needs to be a multiple of { entity .step } " ,
36+ f"it needs to be a multiple of { entity .step } "
3737 )
3838 raise ValueError (msg )
3939
Original file line number Diff line number Diff line change @@ -52,6 +52,27 @@ async def test_number_services_handle_string_native_values(
5252 assert entity .set_value == expected
5353
5454
55+ @pytest .mark .parametrize (
56+ "service_cls" ,
57+ [increment .SpookService , decrement .SpookService ],
58+ )
59+ async def test_number_services_raise_readable_error_for_invalid_amount (
60+ hass : Any ,
61+ service_cls : type [increment .SpookService | decrement .SpookService ],
62+ ) -> None :
63+ """Test invalid amounts raise a readable error."""
64+ entity = MockNumberEntity (1.5 )
65+ call = SimpleNamespace (data = {"amount" : 0.2 })
66+
67+ with pytest .raises (
68+ ValueError ,
69+ match = escape (
70+ "Amount 0.2 not valid for number.test, it needs to be a multiple of 0.5"
71+ ),
72+ ):
73+ await service_cls (hass ).async_handle_service (entity , call )
74+
75+
5576@pytest .mark .parametrize (
5677 "service_cls" ,
5778 [increment .SpookService , decrement .SpookService ],
You can’t perform that action at this time.
0 commit comments