mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
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:
parent
e9abb357e4
commit
1887f11ec9
@ -61,7 +61,20 @@ class PilightLight(PilightBaseDevice, LightEntity):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the switch on by calling pilight.send service with on code."""
|
"""Turn the switch on by calling pilight.send service with on code."""
|
||||||
self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
# Update brightness only if provided as an argument.
|
||||||
dimlevel = int(self._brightness / (255 / self._dimlevel_max))
|
# 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)
|
self.set_state(turn_on=True, dimlevel=dimlevel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user