mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Add color_mode support to tasmota light (#49599)
This commit is contained in:
@ -11,14 +11,7 @@ from hatasmota.utils import (
|
||||
)
|
||||
|
||||
from homeassistant.components import light
|
||||
from homeassistant.components.light import (
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_COLOR,
|
||||
SUPPORT_COLOR_TEMP,
|
||||
SUPPORT_EFFECT,
|
||||
SUPPORT_TRANSITION,
|
||||
SUPPORT_WHITE_VALUE,
|
||||
)
|
||||
from homeassistant.components.light import SUPPORT_EFFECT, SUPPORT_TRANSITION
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON
|
||||
|
||||
@ -60,6 +53,8 @@ async def test_attributes_on_off(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.attributes.get("min_mireds") is None
|
||||
assert state.attributes.get("max_mireds") is None
|
||||
assert state.attributes.get("supported_features") == 0
|
||||
assert state.attributes.get("supported_color_modes") == ["onoff"]
|
||||
assert state.attributes.get("color_mode") == "onoff"
|
||||
|
||||
|
||||
async def test_attributes_dimmer_tuya(hass, mqtt_mock, setup_tasmota):
|
||||
@ -83,7 +78,9 @@ async def test_attributes_dimmer_tuya(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.attributes.get("effect_list") is None
|
||||
assert state.attributes.get("min_mireds") is None
|
||||
assert state.attributes.get("max_mireds") is None
|
||||
assert state.attributes.get("supported_features") == SUPPORT_BRIGHTNESS
|
||||
assert state.attributes.get("supported_features") == 0
|
||||
assert state.attributes.get("supported_color_modes") == ["brightness"]
|
||||
assert state.attributes.get("color_mode") == "brightness"
|
||||
|
||||
|
||||
async def test_attributes_dimmer(hass, mqtt_mock, setup_tasmota):
|
||||
@ -106,10 +103,9 @@ async def test_attributes_dimmer(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.attributes.get("effect_list") is None
|
||||
assert state.attributes.get("min_mireds") is None
|
||||
assert state.attributes.get("max_mireds") is None
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
||||
)
|
||||
assert state.attributes.get("supported_features") == SUPPORT_TRANSITION
|
||||
assert state.attributes.get("supported_color_modes") == ["brightness"]
|
||||
assert state.attributes.get("color_mode") == "brightness"
|
||||
|
||||
|
||||
async def test_attributes_ct(hass, mqtt_mock, setup_tasmota):
|
||||
@ -132,10 +128,9 @@ async def test_attributes_ct(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.attributes.get("effect_list") is None
|
||||
assert state.attributes.get("min_mireds") == 153
|
||||
assert state.attributes.get("max_mireds") == 500
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_TRANSITION
|
||||
)
|
||||
assert state.attributes.get("supported_features") == SUPPORT_TRANSITION
|
||||
assert state.attributes.get("supported_color_modes") == ["color_temp"]
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_attributes_ct_reduced(hass, mqtt_mock, setup_tasmota):
|
||||
@ -159,10 +154,9 @@ async def test_attributes_ct_reduced(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.attributes.get("effect_list") is None
|
||||
assert state.attributes.get("min_mireds") == 200
|
||||
assert state.attributes.get("max_mireds") == 380
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_TRANSITION
|
||||
)
|
||||
assert state.attributes.get("supported_features") == SUPPORT_TRANSITION
|
||||
assert state.attributes.get("supported_color_modes") == ["color_temp"]
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_attributes_rgb(hass, mqtt_mock, setup_tasmota):
|
||||
@ -193,8 +187,10 @@ async def test_attributes_rgb(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.attributes.get("max_mireds") is None
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_EFFECT | SUPPORT_TRANSITION
|
||||
== SUPPORT_EFFECT | SUPPORT_TRANSITION
|
||||
)
|
||||
assert state.attributes.get("supported_color_modes") == ["rgb"]
|
||||
assert state.attributes.get("color_mode") == "rgb"
|
||||
|
||||
|
||||
async def test_attributes_rgbw(hass, mqtt_mock, setup_tasmota):
|
||||
@ -225,12 +221,10 @@ async def test_attributes_rgbw(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.attributes.get("max_mireds") is None
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS
|
||||
| SUPPORT_COLOR
|
||||
| SUPPORT_EFFECT
|
||||
| SUPPORT_TRANSITION
|
||||
| SUPPORT_WHITE_VALUE
|
||||
== SUPPORT_EFFECT | SUPPORT_TRANSITION
|
||||
)
|
||||
assert state.attributes.get("supported_color_modes") == ["rgb", "rgbw"]
|
||||
assert state.attributes.get("color_mode") == "rgbw"
|
||||
|
||||
|
||||
async def test_attributes_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
@ -261,13 +255,10 @@ async def test_attributes_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.attributes.get("max_mireds") == 500
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS
|
||||
| SUPPORT_COLOR
|
||||
| SUPPORT_COLOR_TEMP
|
||||
| SUPPORT_EFFECT
|
||||
| SUPPORT_TRANSITION
|
||||
| SUPPORT_WHITE_VALUE
|
||||
== SUPPORT_EFFECT | SUPPORT_TRANSITION
|
||||
)
|
||||
assert state.attributes.get("supported_color_modes") == ["color_temp", "rgb"]
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_attributes_rgbww_reduced(hass, mqtt_mock, setup_tasmota):
|
||||
@ -299,13 +290,10 @@ async def test_attributes_rgbww_reduced(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.attributes.get("max_mireds") == 380
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS
|
||||
| SUPPORT_COLOR
|
||||
| SUPPORT_COLOR_TEMP
|
||||
| SUPPORT_EFFECT
|
||||
| SUPPORT_TRANSITION
|
||||
| SUPPORT_WHITE_VALUE
|
||||
== SUPPORT_EFFECT | SUPPORT_TRANSITION
|
||||
)
|
||||
assert state.attributes.get("supported_color_modes") == ["color_temp", "rgb"]
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_on_off(hass, mqtt_mock, setup_tasmota):
|
||||
@ -325,29 +313,35 @@ async def test_controlling_state_via_mqtt_on_off(hass, mqtt_mock, setup_tasmota)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == "unavailable"
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_mode") == "onoff"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"ON"}')
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_mode") == "onoff"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"OFF"}')
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_ct(hass, mqtt_mock, setup_tasmota):
|
||||
@ -367,19 +361,23 @@ async def test_controlling_state_via_mqtt_ct(hass, mqtt_mock, setup_tasmota):
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == "unavailable"
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
||||
@ -387,6 +385,7 @@ async def test_controlling_state_via_mqtt_ct(hass, mqtt_mock, setup_tasmota):
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("brightness") == 127.5
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}'
|
||||
@ -394,6 +393,7 @@ async def test_controlling_state_via_mqtt_ct(hass, mqtt_mock, setup_tasmota):
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_temp") == 300
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
# Tasmota will send "Color" also for CT light, this should be ignored
|
||||
async_fire_mqtt_message(
|
||||
@ -403,6 +403,7 @@ async def test_controlling_state_via_mqtt_ct(hass, mqtt_mock, setup_tasmota):
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_temp") == 300
|
||||
assert state.attributes.get("brightness") == 127.5
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
@ -422,19 +423,23 @@ async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == "unavailable"
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
||||
@ -442,22 +447,27 @@ 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("brightness") == 127.5
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"255,128,0"}'
|
||||
hass,
|
||||
"tasmota_49A3BC/tele/STATE",
|
||||
'{"POWER":"ON","Color":"128,64,0","White":0}',
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("rgb_color") == (255, 128, 0)
|
||||
assert state.attributes.get("color_mode") == "rgb"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":50}'
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("white_value") == 127.5
|
||||
assert "white_value" not in state.attributes
|
||||
# Setting white > 0 should clear the color
|
||||
assert not state.attributes.get("rgb_color")
|
||||
assert "rgb_color" not in state.attributes
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}'
|
||||
@ -465,15 +475,18 @@ 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("color_temp") == 300
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
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")
|
||||
# Setting white to 0 should clear the color_temp
|
||||
assert "white_value" not in state.attributes
|
||||
assert "color_temp" not in state.attributes
|
||||
assert state.attributes.get("rgb_color") == (255, 128, 0)
|
||||
assert state.attributes.get("color_mode") == "rgb"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Scheme":3}'
|
||||
@ -511,19 +524,23 @@ async def test_controlling_state_via_mqtt_rgbww_hex(hass, mqtt_mock, setup_tasmo
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == "unavailable"
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
||||
@ -531,29 +548,33 @@ async def test_controlling_state_via_mqtt_rgbww_hex(hass, mqtt_mock, setup_tasmo
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("brightness") == 127.5
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"FF8000"}'
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"804000","White":0}'
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("rgb_color") == (255, 128, 0)
|
||||
assert state.attributes.get("color_mode") == "rgb"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"00FF800000"}'
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"0080400000"}'
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("rgb_color") == (0, 255, 128)
|
||||
assert state.attributes.get("color_mode") == "rgb"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":50}'
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("white_value") == 127.5
|
||||
assert "white_value" not in state.attributes
|
||||
# Setting white > 0 should clear the color
|
||||
assert not state.attributes.get("rgb_color")
|
||||
assert "rgb_color" not in state.attributes
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}'
|
||||
@ -561,6 +582,7 @@ async def test_controlling_state_via_mqtt_rgbww_hex(hass, mqtt_mock, setup_tasmo
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_temp") == 300
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":0}'
|
||||
@ -570,6 +592,7 @@ async def test_controlling_state_via_mqtt_rgbww_hex(hass, mqtt_mock, setup_tasmo
|
||||
# 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")
|
||||
assert state.attributes.get("color_mode") == "rgb"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Scheme":3}'
|
||||
@ -607,19 +630,23 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(hass, mqtt_mock, setup_tasm
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == "unavailable"
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert "color_mode" not in state.attributes
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
||||
@ -627,22 +654,27 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(hass, mqtt_mock, setup_tasm
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("brightness") == 127.5
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"255,128,0"}'
|
||||
hass,
|
||||
"tasmota_49A3BC/tele/STATE",
|
||||
'{"POWER":"ON","Color":"128,64,0","White":0}',
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("rgb_color") == (255, 128, 0)
|
||||
assert state.attributes.get("color_mode") == "rgb"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":50}'
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("white_value") == 127.5
|
||||
assert "white_value" not in state.attributes
|
||||
# Setting white > 0 should clear the color
|
||||
assert not state.attributes.get("rgb_color")
|
||||
assert "rgb_color" not in state.attributes
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}'
|
||||
@ -650,6 +682,7 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(hass, mqtt_mock, setup_tasm
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("color_temp") == 300
|
||||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":0}'
|
||||
@ -659,6 +692,7 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(hass, mqtt_mock, setup_tasm
|
||||
# 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")
|
||||
assert state.attributes.get("color_mode") == "rgb"
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Scheme":3}'
|
||||
@ -765,6 +799,102 @@ async def test_sending_mqtt_commands_rgbww_tuya(hass, mqtt_mock, setup_tasmota):
|
||||
)
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_rgbw(hass, mqtt_mock, setup_tasmota):
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
config["lt_st"] = 4 # 4 channel light (RGBW)
|
||||
mac = config["mac"]
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
f"{DEFAULT_PREFIX}/{mac}/config",
|
||||
json.dumps(config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
# Turn the light on and verify MQTT message is sent
|
||||
await common.async_turn_on(hass, "light.test")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog", "NoDelay;Power1 ON", 0, False
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
# Tasmota is not optimistic, the state should still be off
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# Turn the light off and verify MQTT message is sent
|
||||
await common.async_turn_off(hass, "light.test")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog", "NoDelay;Power1 OFF", 0, False
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
# Turn the light on and verify MQTT messages are sent
|
||||
await common.async_turn_on(hass, "light.test", brightness=192)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog", "NoDelay;Dimmer 75", 0, False
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
# Set color when setting color
|
||||
await common.async_turn_on(hass, "light.test", rgb_color=[128, 64, 32])
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog",
|
||||
"NoDelay;Power1 ON;NoDelay;Color2 128,64,32",
|
||||
0,
|
||||
False,
|
||||
)
|
||||
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])
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog",
|
||||
"NoDelay;Power1 ON;NoDelay;Color2 128,64,32",
|
||||
0,
|
||||
False,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
# Set white when setting brighter white than color
|
||||
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",
|
||||
"NoDelay;Power1 ON;NoDelay;White 50",
|
||||
0,
|
||||
False,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await common.async_turn_on(hass, "light.test", white_value=128)
|
||||
# white_value should be ignored
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog",
|
||||
"NoDelay;Power1 ON",
|
||||
0,
|
||||
False,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await common.async_turn_on(hass, "light.test", effect="Random")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog",
|
||||
"NoDelay;Power1 ON;NoDelay;Scheme 4",
|
||||
0,
|
||||
False,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
@ -811,10 +941,10 @@ async def test_sending_mqtt_commands_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await common.async_turn_on(hass, "light.test", rgb_color=[255, 128, 0])
|
||||
await common.async_turn_on(hass, "light.test", rgb_color=[128, 64, 32])
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog",
|
||||
"NoDelay;Power1 ON;NoDelay;Color2 255,128,0",
|
||||
"NoDelay;Power1 ON;NoDelay;Color2 128,64,32",
|
||||
0,
|
||||
False,
|
||||
)
|
||||
@ -830,9 +960,10 @@ async def test_sending_mqtt_commands_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await common.async_turn_on(hass, "light.test", white_value=128)
|
||||
# white_value should be ignored
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog",
|
||||
"NoDelay;Power1 ON;NoDelay;White 50",
|
||||
"NoDelay;Power1 ON",
|
||||
0,
|
||||
False,
|
||||
)
|
||||
@ -1000,7 +1131,7 @@ async def test_transition(hass, mqtt_mock, setup_tasmota):
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"tasmota_49A3BC/tele/STATE",
|
||||
'{"POWER":"ON","Dimmer":50, "Color":"0,255,0"}',
|
||||
'{"POWER":"ON","Dimmer":50, "Color":"0,255,0", "White":0}',
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
@ -1040,7 +1171,9 @@ async def test_transition(hass, mqtt_mock, setup_tasmota):
|
||||
|
||||
# Fake state update from the light
|
||||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50, "CT":153}'
|
||||
hass,
|
||||
"tasmota_49A3BC/tele/STATE",
|
||||
'{"POWER":"ON","Dimmer":50, "CT":153, "White":50}',
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
@ -1324,10 +1457,8 @@ async def test_discovery_update_reconfigure_light(
|
||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{config[CONF_MAC]}/config", data1)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.test")
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
||||
)
|
||||
assert state.attributes.get("supported_features") == SUPPORT_TRANSITION
|
||||
assert state.attributes.get("supported_color_modes") == ["brightness"]
|
||||
|
||||
# Reconfigure as RGB light
|
||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{config[CONF_MAC]}/config", data2)
|
||||
@ -1335,8 +1466,9 @@ async def test_discovery_update_reconfigure_light(
|
||||
state = hass.states.get("light.test")
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_EFFECT | SUPPORT_TRANSITION
|
||||
== SUPPORT_EFFECT | SUPPORT_TRANSITION
|
||||
)
|
||||
assert state.attributes.get("supported_color_modes") == ["rgb"]
|
||||
|
||||
|
||||
async def test_availability_when_connection_lost(
|
||||
|
Reference in New Issue
Block a user