From 5c71ba578db1ba433c3275184016b006ec6cae67 Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Tue, 13 Apr 2021 01:52:51 +0300 Subject: [PATCH] Fix Shelly brightness offset (#49007) --- homeassistant/components/shelly/light.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/shelly/light.py b/homeassistant/components/shelly/light.py index a9e13796875..370522415fd 100644 --- a/homeassistant/components/shelly/light.py +++ b/homeassistant/components/shelly/light.py @@ -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))