Fix Tasmota color scaling and RGBW lights (#50120)
This commit is contained in:
parent
40a18c10a0
commit
4136f9f203
2 changed files with 21 additions and 9 deletions
|
@ -143,9 +143,14 @@ class TasmotaLight(
|
|||
|
||||
rgb = attributes["color"]
|
||||
# Tasmota's RGB color is adjusted for brightness, compensate
|
||||
red_compensated = clamp(round(rgb[0] / self._brightness * 255))
|
||||
green_compensated = clamp(round(rgb[1] / self._brightness * 255))
|
||||
blue_compensated = clamp(round(rgb[2] / self._brightness * 255))
|
||||
if self._brightness > 0:
|
||||
red_compensated = clamp(round(rgb[0] / 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]
|
||||
if "color_temp" in attributes:
|
||||
self._color_temp = attributes["color_temp"]
|
||||
|
@ -211,6 +216,13 @@ class TasmotaLight(
|
|||
return None
|
||||
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
|
||||
def is_on(self):
|
||||
"""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:
|
||||
rgbw = kwargs[ATTR_RGBW_COLOR]
|
||||
# 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
|
||||
# and white channels
|
||||
if max(rgbw[0:3]) > rgbw[3]:
|
||||
# either white mode or color mode. Set the mode to white if white channel
|
||||
# is on, and to color otheruse
|
||||
if rgbw[3] == 0:
|
||||
attributes["color"] = [rgbw[0], rgbw[1], rgbw[2]]
|
||||
else:
|
||||
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()
|
||||
|
||||
# Set color when setting brighter color than white
|
||||
await common.async_turn_on(hass, "light.test", rgbw_color=[128, 64, 32, 16])
|
||||
# Set color when setting white is off
|
||||
await common.async_turn_on(hass, "light.test", rgbw_color=[128, 64, 32, 0])
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog",
|
||||
"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()
|
||||
|
||||
# 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])
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue