Prevent turning on tellduslive lights with 0 brightness (#23135)

* Prevent turning on tellduslive lights with 0 brightness

It was possible for the light compontent to get in a state where the last_brightness was set to zero, and when turning on (by calling turn_on) it would call the TellStick with 0 dim level, ergo not turning on the light.

With this, it will fall back on a 75% dim level if the level is set to zero.

* Wrap long log line over two lines

And using a more proper way of formatting the message

* Fallback to 100% instead of 75%
This commit is contained in:
Magnus Brange 2019-05-02 12:53:32 +02:00 committed by Martin Hjelmare
parent a7ef1eabb0
commit 21575938ef

View File

@ -67,6 +67,11 @@ class TelldusLiveLight(TelldusLiveEntity, Light):
def turn_on(self, **kwargs):
"""Turn the light on."""
brightness = kwargs.get(ATTR_BRIGHTNESS, self._last_brightness)
if brightness == 0:
fallback_brightness = 100
_LOGGER.info("Setting brightness to %d%%, because it was 0",
fallback_brightness)
brightness = int(fallback_brightness*255/100)
self.device.dim(level=brightness)
self.changed()