From 81b8a509bc5ce766b70c85b0a44678f53601f559 Mon Sep 17 00:00:00 2001 From: Cyborg2017 Date: Fri, 30 Jan 2026 13:41:24 +0800 Subject: [PATCH] fix: correct brightness mapping for 0-255 configured light devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed the erroneous brightness value mapping (1-100 ↔ 0-255) for devices configured with brightness range [0, 255]. The previous logic incorrectly assumed these devices actually operated in a 1-100 range, causing inaccurate brightness values. --- custom_components/midea_auto_cloud/light.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/custom_components/midea_auto_cloud/light.py b/custom_components/midea_auto_cloud/light.py index 068478a..53cc423 100644 --- a/custom_components/midea_auto_cloud/light.py +++ b/custom_components/midea_auto_cloud/light.py @@ -165,11 +165,9 @@ class MideaLightEntity(MideaEntity, LightEntity): if brightness_value is not None: brightness_value = int(brightness_value) if brightness_value is not None: - # 如果配置是[0, 255]但实际设备范围是1-100,需要特殊处理 + # 配置是[0, 255]直接使用 if self._brightness_min == 0 and self._brightness_max == 255: - # 特殊处理:设备1-100范围映射到HA的0-255范围 - ha_brightness = round(brightness_value * 2.55) # 1-100 -> 0-255 - return max(1, min(255, ha_brightness)) + return max(1, min(255, brightness_value)) else: # 正常范围映射 device_range = self._brightness_max - self._brightness_min @@ -244,11 +242,11 @@ class MideaLightEntity(MideaEntity, LightEntity): if target_brightness is not None and self._key_brightness and self._brightness_is_range: # 范围模式:将Home Assistant的0-255映射到设备范围 - # 如果配置是[0, 255]但实际设备范围是1-100,需要特殊处理 + target_brightness = max(0, min(255, target_brightness)) + + # 配置是[0, 255]直接使用 if self._brightness_min == 0 and self._brightness_max == 255: - # 特殊处理:配置[0,255]但实际设备范围是1-100 - device_brightness = round(target_brightness / 2.55) # 0-255 -> 0-100 - device_brightness = max(1, min(100, device_brightness)) # 确保在1-100范围内 + device_brightness = target_brightness else: # 正常范围映射 device_range = self._brightness_max - self._brightness_min