@@ -139,8 +139,14 @@ def test_set_value_invalid_min_step(int_format):
139139 with patch (path ) as mock_notify :
140140 char .set_value (5.55 )
141141 # Ensure floating point is dropped on an int property
142- # Ensure value is lowered to match minStep
143- assert char .value == 4
142+ # Ensure value is rounded to match minStep
143+ assert char .value == 6
144+ assert mock_notify .called is False
145+
146+ char .set_value (6.00 )
147+ # Ensure floating point is dropped on an int property
148+ # Ensure value is rounded to match minStep
149+ assert char .value == 6
144150 assert mock_notify .called is False
145151
146152 char .broker = Mock ()
@@ -159,6 +165,51 @@ def test_set_value_invalid_min_step(int_format):
159165 assert mock_notify .call_count == 1
160166
161167
168+ def test_set_value_invalid_min_float ():
169+ """Test setting the value of a characteristic that is outside the minStep."""
170+ props = PROPERTIES .copy ()
171+ props ["Format" ] = HAP_FORMAT_FLOAT
172+ props ["minStep" ] = 0.1
173+ char = get_char (props , min_value = 0 , max_value = 26 )
174+
175+ char .set_value (5.55 )
176+ # Ensure value is rounded to match minStep
177+ assert char .value == 5.5
178+
179+ char .set_value (22.2 )
180+ # Ensure value is rounded to match minStep
181+ assert char .value == 22.2
182+
183+ char .set_value (22.200000 )
184+ # Ensure value is rounded to match minStep
185+ assert char .value == 22.2
186+
187+ props = PROPERTIES .copy ()
188+ props ["Format" ] = HAP_FORMAT_FLOAT
189+ props ["minStep" ] = 0.00001
190+ char = get_char (props , min_value = 0 , max_value = 26 )
191+
192+ char .set_value (5.55 )
193+ # Ensure value is rounded to match minStep
194+ assert char .value == 5.55
195+
196+ char .set_value (22.2 )
197+ # Ensure value is rounded to match minStep
198+ assert char .value == 22.2
199+
200+ char .set_value (22.200000 )
201+ # Ensure value is rounded to match minStep
202+ assert char .value == 22.2
203+
204+ char .set_value (22.12345678 )
205+ # Ensure value is rounded to match minStep
206+ assert char .value == 22.12346
207+
208+ char .set_value (0 )
209+ # Ensure value is not modified
210+ assert char .value == 0
211+
212+
162213@pytest .mark .parametrize ("int_format" , HAP_FORMAT_INTS )
163214def test_set_value_int (int_format ):
164215 """Test setting the value of a characteristic."""
0 commit comments