Changing z-wave brightness calculation to respect 0x01 and 0x02 byte values (#16420)
* Changing z-wave brightness calculation to respect 0x01 and 0x02 byte values * adding additional line breaks to satisfy houndci * - Update comment style for linter - Add additional unit test to increase code coverage * Update zwave.pypull/16598/head
parent
e59ba28fe6
commit
d076251b18
|
@ -63,6 +63,16 @@ def brightness_state(value):
|
|||
return 0, STATE_OFF
|
||||
|
||||
|
||||
def byte_to_zwave_brightness(value):
|
||||
"""Convert brightness in 0-255 scale to 0-99 scale.
|
||||
|
||||
`value` -- (int) Brightness byte value from 0-255.
|
||||
"""
|
||||
if value > 0:
|
||||
return max(1, int((value / 255) * 99))
|
||||
return 0
|
||||
|
||||
|
||||
def ct_to_hs(temp):
|
||||
"""Convert color temperature (mireds) to hs."""
|
||||
colorlist = list(
|
||||
|
@ -187,7 +197,7 @@ class ZwaveDimmer(zwave.ZWaveDeviceEntity, Light):
|
|||
# brightness. Level 255 means to set it to previous value.
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
self._brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
brightness = int((self._brightness / 255) * 99)
|
||||
brightness = byte_to_zwave_brightness(self._brightness)
|
||||
else:
|
||||
brightness = 255
|
||||
|
||||
|
|
|
@ -105,6 +105,26 @@ def test_dimmer_turn_on(mock_openzwave):
|
|||
assert entity_id == device.entity_id
|
||||
|
||||
|
||||
def test_dimmer_min_brightness(mock_openzwave):
|
||||
"""Test turning on a dimmable Z-Wave light to its minimum brightness."""
|
||||
node = MockNode()
|
||||
value = MockValue(data=0, node=node)
|
||||
values = MockLightValues(primary=value)
|
||||
device = zwave.get_device(node=node, values=values, node_config={})
|
||||
|
||||
assert not device.is_on
|
||||
|
||||
device.turn_on(**{ATTR_BRIGHTNESS: 1})
|
||||
|
||||
assert device.is_on
|
||||
assert device.brightness == 1
|
||||
|
||||
device.turn_on(**{ATTR_BRIGHTNESS: 0})
|
||||
|
||||
assert device.is_on
|
||||
assert device.brightness == 0
|
||||
|
||||
|
||||
def test_dimmer_transitions(mock_openzwave):
|
||||
"""Test dimming transition on a dimmable Z-Wave light."""
|
||||
node = MockNode()
|
||||
|
|
Loading…
Reference in New Issue