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.py
This commit is contained in:
Harvtronix authored and Adam Mills committed 2018-09-13 10:38:07 -04:00
1 parent e59ba28fe6
commit d076251b18
2 files changed
+31 -1

No files matched your search

+11 -1
View File
@@ -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