From 56ee99372d0fb10248eb45159856824e7ffa9a79 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 4 Nov 2020 10:03:32 +0100 Subject: [PATCH] Force color or white mode exclusivity for Tasmota lights (#42772) --- homeassistant/components/tasmota/light.py | 5 +++++ tests/components/tasmota/test_light.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/homeassistant/components/tasmota/light.py b/homeassistant/components/tasmota/light.py index 1a41e7373fd..a680d873f9f 100644 --- a/homeassistant/components/tasmota/light.py +++ b/homeassistant/components/tasmota/light.py @@ -128,6 +128,11 @@ class TasmotaLight( white_value = float(attributes["white_value"]) percent_white = white_value / TASMOTA_BRIGHTNESS_MAX self._white_value = percent_white * 255 + if self._white_value == 0: + self._color_temp = None + self._white_value = None + if self._white_value is not None and self._white_value > 0: + self._hs = None self.async_write_ha_state() @property diff --git a/tests/components/tasmota/test_light.py b/tests/components/tasmota/test_light.py index 48b1dec7232..9210c577a5e 100644 --- a/tests/components/tasmota/test_light.py +++ b/tests/components/tasmota/test_light.py @@ -432,6 +432,8 @@ async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota): state = hass.states.get("light.test") assert state.state == STATE_ON assert state.attributes.get("white_value") == 127.5 + # Setting white > 0 should clear the color + assert not state.attributes.get("rgb_color") async_fire_mqtt_message( hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}' @@ -440,6 +442,15 @@ async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota): assert state.state == STATE_ON assert state.attributes.get("color_temp") == 300 + async_fire_mqtt_message( + hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":0}' + ) + state = hass.states.get("light.test") + assert state.state == STATE_ON + # Setting white to 0 should clear the white_value and color_temp + assert not state.attributes.get("white_value") + assert not state.attributes.get("color_temp") + async_fire_mqtt_message( hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Scheme":3}' )