Fix z-wave brightness off by one (#34170)

Z-wave would drop the floating point by calling
int() instead of round() which would result in
the brightness being off by one in many cases.
pull/34177/head
J. Nick Koston 2020-04-13 17:51:35 -05:00 committed by GitHub
parent 028e08c7f6
commit 29f50ddc9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -104,7 +104,7 @@ def byte_to_zwave_brightness(value):
`value` -- (int) Brightness byte value from 0-255.
"""
if value > 0:
return max(1, int((value / 255) * 99))
return max(1, round((value / 255) * 99))
return 0

View File

@ -100,13 +100,23 @@ def test_dimmer_turn_on(mock_openzwave):
node.reset_mock()
device.turn_on(**{ATTR_BRIGHTNESS: 224})
assert node.set_dimmer.called
value_id, brightness = node.set_dimmer.mock_calls[0][1]
assert value_id == value.value_id
assert brightness == 87 # round(224 / 255 * 99)
node.reset_mock()
device.turn_on(**{ATTR_BRIGHTNESS: 120})
assert node.set_dimmer.called
value_id, brightness = node.set_dimmer.mock_calls[0][1]
assert value_id == value.value_id
assert brightness == 46 # int(120 / 255 * 99)
assert brightness == 47 # round(120 / 255 * 99)
with patch.object(light, "_LOGGER", MagicMock()) as mock_logger:
device.turn_on(**{ATTR_TRANSITION: 35})