Fix Shelly brightness offset (#49007)

This commit is contained in:
Shay Levy 2021-04-13 01:52:51 +03:00 committed by GitHub
parent ff8e4fb77f
commit 5c71ba578d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,15 +118,16 @@ class ShellyLight(ShellyBlockEntity, LightEntity):
"""Brightness of light."""
if self.mode == "color":
if self.control_result:
brightness = self.control_result["gain"]
brightness_pct = self.control_result["gain"]
else:
brightness = self.block.gain
brightness_pct = self.block.gain
else:
if self.control_result:
brightness = self.control_result["brightness"]
brightness_pct = self.control_result["brightness"]
else:
brightness = self.block.brightness
return int(brightness / 100 * 255)
brightness_pct = self.block.brightness
return round(255 * brightness_pct / 100)
@property
def white_value(self) -> int:
@ -188,11 +189,11 @@ class ShellyLight(ShellyBlockEntity, LightEntity):
set_mode = None
params = {"turn": "on"}
if ATTR_BRIGHTNESS in kwargs:
tmp_brightness = int(kwargs[ATTR_BRIGHTNESS] / 255 * 100)
brightness_pct = int(100 * (kwargs[ATTR_BRIGHTNESS] + 1) / 255)
if hasattr(self.block, "gain"):
params["gain"] = tmp_brightness
params["gain"] = brightness_pct
if hasattr(self.block, "brightness"):
params["brightness"] = tmp_brightness
params["brightness"] = brightness_pct
if ATTR_COLOR_TEMP in kwargs:
color_temp = color_temperature_mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])
color_temp = min(self._max_kelvin, max(self._min_kelvin, color_temp))