Keep previous brightness of dimming zwave light upon turning it on/off (#5160)

* Keep previous brightness of dimming zwave light upon turning it on/off

* Fix initialization

* Use value 255 to set dimmer to previous value
pull/5164/head
andrey-git 2017-01-03 21:31:44 +02:00 committed by John Arild Berentsen
parent 21f59a0732
commit a0a9f26312
1 changed files with 6 additions and 5 deletions

View File

@ -79,7 +79,7 @@ def brightness_state(value):
if value.data > 0:
return (value.data / 99) * 255, STATE_ON
else:
return 255, STATE_OFF
return 0, STATE_OFF
class ZwaveDimmer(zwave.ZWaveDeviceEntity, Light):
@ -165,12 +165,13 @@ class ZwaveDimmer(zwave.ZWaveDeviceEntity, Light):
def turn_on(self, **kwargs):
"""Turn the device on."""
# Zwave multilevel switches use a range of [0, 99] to control
# brightness. Level 255 means to set it to previous value.
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]
# Zwave multilevel switches use a range of [0, 99] to control
# brightness.
brightness = int((self._brightness / 255) * 99)
brightness = int((self._brightness / 255) * 99)
else:
brightness = 255
if self._value.node.set_dimmer(self._value.value_id, brightness):
self._state = STATE_ON