Do not default Pilight lights to max brightness (#39549)

Fix pilight lights would always turned on at max brightness instead of just turning on. Some 433mhz dimmers (like the KAKU series) remember their last brightness setting.

Fix pilight lights would not respect configured dimlevel_min
This commit is contained in:
Daniel de Jong 2020-09-17 22:48:52 +02:00 committed by GitHub
parent e9abb357e4
commit 1887f11ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,7 +61,20 @@ class PilightLight(PilightBaseDevice, LightEntity):
def turn_on(self, **kwargs):
"""Turn the switch on by calling pilight.send service with on code."""
self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
dimlevel = int(self._brightness / (255 / self._dimlevel_max))
# Update brightness only if provided as an argument.
# This will allow the switch to keep its previous brightness level.
dimlevel = None
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]
# Calculate pilight brightness (as a range of 0 to 15)
# By creating a percentage
percentage = self._brightness / 255
# Then calculate the dimmer range (aka amount of available brightness steps).
dimrange = self._dimlevel_max - self._dimlevel_min
# Finally calculate the pilight brightness.
# We add dimlevel_min back in to ensure the minimum is always reached.
dimlevel = int(percentage * dimrange + self._dimlevel_min)
self.set_state(turn_on=True, dimlevel=dimlevel)