mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix Tasmota color scaling and RGBW lights (#50120)
This commit is contained in:
parent
40a18c10a0
commit
4136f9f203
@ -143,9 +143,14 @@ class TasmotaLight(
|
|||||||
|
|
||||||
rgb = attributes["color"]
|
rgb = attributes["color"]
|
||||||
# Tasmota's RGB color is adjusted for brightness, compensate
|
# Tasmota's RGB color is adjusted for brightness, compensate
|
||||||
red_compensated = clamp(round(rgb[0] / self._brightness * 255))
|
if self._brightness > 0:
|
||||||
green_compensated = clamp(round(rgb[1] / self._brightness * 255))
|
red_compensated = clamp(round(rgb[0] / self._brightness * 255))
|
||||||
blue_compensated = clamp(round(rgb[2] / self._brightness * 255))
|
green_compensated = clamp(round(rgb[1] / self._brightness * 255))
|
||||||
|
blue_compensated = clamp(round(rgb[2] / self._brightness * 255))
|
||||||
|
else:
|
||||||
|
red_compensated = 0
|
||||||
|
green_compensated = 0
|
||||||
|
blue_compensated = 0
|
||||||
self._rgb = [red_compensated, green_compensated, blue_compensated]
|
self._rgb = [red_compensated, green_compensated, blue_compensated]
|
||||||
if "color_temp" in attributes:
|
if "color_temp" in attributes:
|
||||||
self._color_temp = attributes["color_temp"]
|
self._color_temp = attributes["color_temp"]
|
||||||
@ -211,6 +216,13 @@ class TasmotaLight(
|
|||||||
return None
|
return None
|
||||||
return [*self._rgb, self._white_value]
|
return [*self._rgb, self._white_value]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def force_update(self):
|
||||||
|
"""Force update."""
|
||||||
|
if self.color_mode == COLOR_MODE_RGBW:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
@ -239,9 +251,9 @@ class TasmotaLight(
|
|||||||
if ATTR_RGBW_COLOR in kwargs and COLOR_MODE_RGBW in supported_color_modes:
|
if ATTR_RGBW_COLOR in kwargs and COLOR_MODE_RGBW in supported_color_modes:
|
||||||
rgbw = kwargs[ATTR_RGBW_COLOR]
|
rgbw = kwargs[ATTR_RGBW_COLOR]
|
||||||
# Tasmota does not support direct RGBW control, the light must be set to
|
# Tasmota does not support direct RGBW control, the light must be set to
|
||||||
# either white mode or color mode. Set the mode according to max of rgb
|
# either white mode or color mode. Set the mode to white if white channel
|
||||||
# and white channels
|
# is on, and to color otheruse
|
||||||
if max(rgbw[0:3]) > rgbw[3]:
|
if rgbw[3] == 0:
|
||||||
attributes["color"] = [rgbw[0], rgbw[1], rgbw[2]]
|
attributes["color"] = [rgbw[0], rgbw[1], rgbw[2]]
|
||||||
else:
|
else:
|
||||||
white_value_normalized = rgbw[3] / DEFAULT_BRIGHTNESS_MAX
|
white_value_normalized = rgbw[3] / DEFAULT_BRIGHTNESS_MAX
|
||||||
|
@ -855,8 +855,8 @@ async def test_sending_mqtt_commands_rgbw(hass, mqtt_mock, setup_tasmota):
|
|||||||
)
|
)
|
||||||
mqtt_mock.async_publish.reset_mock()
|
mqtt_mock.async_publish.reset_mock()
|
||||||
|
|
||||||
# Set color when setting brighter color than white
|
# Set color when setting white is off
|
||||||
await common.async_turn_on(hass, "light.test", rgbw_color=[128, 64, 32, 16])
|
await common.async_turn_on(hass, "light.test", rgbw_color=[128, 64, 32, 0])
|
||||||
mqtt_mock.async_publish.assert_called_once_with(
|
mqtt_mock.async_publish.assert_called_once_with(
|
||||||
"tasmota_49A3BC/cmnd/Backlog",
|
"tasmota_49A3BC/cmnd/Backlog",
|
||||||
"NoDelay;Power1 ON;NoDelay;Color2 128,64,32",
|
"NoDelay;Power1 ON;NoDelay;Color2 128,64,32",
|
||||||
@ -865,7 +865,7 @@ async def test_sending_mqtt_commands_rgbw(hass, mqtt_mock, setup_tasmota):
|
|||||||
)
|
)
|
||||||
mqtt_mock.async_publish.reset_mock()
|
mqtt_mock.async_publish.reset_mock()
|
||||||
|
|
||||||
# Set white when setting brighter white than color
|
# Set white when white is on
|
||||||
await common.async_turn_on(hass, "light.test", rgbw_color=[16, 64, 32, 128])
|
await common.async_turn_on(hass, "light.test", rgbw_color=[16, 64, 32, 128])
|
||||||
mqtt_mock.async_publish.assert_called_once_with(
|
mqtt_mock.async_publish.assert_called_once_with(
|
||||||
"tasmota_49A3BC/cmnd/Backlog",
|
"tasmota_49A3BC/cmnd/Backlog",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user