From a0a9f26312f94eb06c794244dd68a0204b33447a Mon Sep 17 00:00:00 2001 From: andrey-git Date: Tue, 3 Jan 2017 21:31:44 +0200 Subject: [PATCH] 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 --- homeassistant/components/light/zwave.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/light/zwave.py b/homeassistant/components/light/zwave.py index 30fa0611e45..d973f8d8dd2 100644 --- a/homeassistant/components/light/zwave.py +++ b/homeassistant/components/light/zwave.py @@ -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