mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
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.
This commit is contained in:
parent
028e08c7f6
commit
29f50ddc9c
@ -104,7 +104,7 @@ def byte_to_zwave_brightness(value):
|
|||||||
`value` -- (int) Brightness byte value from 0-255.
|
`value` -- (int) Brightness byte value from 0-255.
|
||||||
"""
|
"""
|
||||||
if value > 0:
|
if value > 0:
|
||||||
return max(1, int((value / 255) * 99))
|
return max(1, round((value / 255) * 99))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,13 +100,23 @@ def test_dimmer_turn_on(mock_openzwave):
|
|||||||
|
|
||||||
node.reset_mock()
|
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})
|
device.turn_on(**{ATTR_BRIGHTNESS: 120})
|
||||||
|
|
||||||
assert node.set_dimmer.called
|
assert node.set_dimmer.called
|
||||||
value_id, brightness = node.set_dimmer.mock_calls[0][1]
|
value_id, brightness = node.set_dimmer.mock_calls[0][1]
|
||||||
|
|
||||||
assert value_id == value.value_id
|
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:
|
with patch.object(light, "_LOGGER", MagicMock()) as mock_logger:
|
||||||
device.turn_on(**{ATTR_TRANSITION: 35})
|
device.turn_on(**{ATTR_TRANSITION: 35})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user