mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
Remove deprecated white_value support from MQTT light (#76848)
* Remove deprecated white_value support from MQTT light * Remove deprecated white_value support from MQTT JSON light * Remove deprecated white_value support from MQTT template light
This commit is contained in:
@ -106,23 +106,6 @@ light:
|
||||
payload_on: "on"
|
||||
payload_off: "off"
|
||||
|
||||
config for RGB Version with white value and scale:
|
||||
|
||||
light:
|
||||
platform: mqtt
|
||||
name: "Office Light RGB"
|
||||
state_topic: "office/rgb1/light/status"
|
||||
command_topic: "office/rgb1/light/switch"
|
||||
white_value_state_topic: "office/rgb1/white_value/status"
|
||||
white_value_command_topic: "office/rgb1/white_value/set"
|
||||
white_value_scale: 99
|
||||
rgb_state_topic: "office/rgb1/rgb/status"
|
||||
rgb_command_topic: "office/rgb1/rgb/set"
|
||||
rgb_scale: 99
|
||||
qos: 0
|
||||
payload_on: "on"
|
||||
payload_off: "off"
|
||||
|
||||
config for RGB Version with RGB command template:
|
||||
|
||||
light:
|
||||
@ -199,13 +182,11 @@ from homeassistant.components.mqtt.light.schema_basic import (
|
||||
CONF_RGB_COMMAND_TOPIC,
|
||||
CONF_RGBW_COMMAND_TOPIC,
|
||||
CONF_RGBWW_COMMAND_TOPIC,
|
||||
CONF_WHITE_VALUE_COMMAND_TOPIC,
|
||||
CONF_XY_COMMAND_TOPIC,
|
||||
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
@ -270,33 +251,6 @@ async def test_fail_setup_if_no_command_topic(hass, mqtt_mock_entry_no_yaml_conf
|
||||
assert hass.states.get("light.test") is None
|
||||
|
||||
|
||||
async def test_legacy_rgb_white_light(hass, mqtt_mock_entry_with_yaml_config):
|
||||
"""Test legacy RGB + white light flags brightness support."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
light.DOMAIN,
|
||||
{
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"name": "test",
|
||||
"command_topic": "test_light_rgb/set",
|
||||
"rgb_command_topic": "test_light_rgb/rgb/set",
|
||||
"white_value_command_topic": "test_light_rgb/white/set",
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_with_yaml_config()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
expected_features = (
|
||||
light.SUPPORT_COLOR | light.SUPPORT_BRIGHTNESS | light.SUPPORT_WHITE_VALUE
|
||||
)
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == expected_features
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) is None
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == ["hs", "rgbw"]
|
||||
|
||||
|
||||
async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
@ -325,7 +279,6 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("rgbw_color") is None
|
||||
assert state.attributes.get("rgbww_color") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) is None
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == ["onoff"]
|
||||
@ -341,7 +294,6 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("rgbw_color") is None
|
||||
assert state.attributes.get("rgbww_color") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "onoff"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == ["onoff"]
|
||||
@ -357,138 +309,6 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_legacy_controlling_state_via_topic(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
"""Test the controlling of the state via topic for legacy light (white_value)."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"name": "test",
|
||||
"state_topic": "test_light_rgb/status",
|
||||
"command_topic": "test_light_rgb/set",
|
||||
"brightness_state_topic": "test_light_rgb/brightness/status",
|
||||
"brightness_command_topic": "test_light_rgb/brightness/set",
|
||||
"rgb_state_topic": "test_light_rgb/rgb/status",
|
||||
"rgb_command_topic": "test_light_rgb/rgb/set",
|
||||
"color_temp_state_topic": "test_light_rgb/color_temp/status",
|
||||
"color_temp_command_topic": "test_light_rgb/color_temp/set",
|
||||
"effect_state_topic": "test_light_rgb/effect/status",
|
||||
"effect_command_topic": "test_light_rgb/effect/set",
|
||||
"hs_state_topic": "test_light_rgb/hs/status",
|
||||
"hs_command_topic": "test_light_rgb/hs/set",
|
||||
"white_value_state_topic": "test_light_rgb/white_value/status",
|
||||
"white_value_command_topic": "test_light_rgb/white_value/set",
|
||||
"xy_state_topic": "test_light_rgb/xy/status",
|
||||
"xy_command_topic": "test_light_rgb/xy/set",
|
||||
"qos": "0",
|
||||
"payload_on": 1,
|
||||
"payload_off": 0,
|
||||
}
|
||||
}
|
||||
color_modes = ["color_temp", "hs", "rgbw"]
|
||||
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_with_yaml_config()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
assert state.attributes.get("effect") is None
|
||||
assert state.attributes.get("hs_color") is None
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("rgbw_color") is None
|
||||
assert state.attributes.get("rgbww_color") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) is None
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
assert state.attributes.get("effect") is None
|
||||
assert state.attributes.get("hs_color") is None
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("rgbw_color") is None
|
||||
assert state.attributes.get("rgbww_color") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "unknown"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "0")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "100")
|
||||
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes["brightness"] == 100
|
||||
assert light_state.attributes.get(light.ATTR_COLOR_MODE) == "unknown"
|
||||
assert light_state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/color_temp/status", "300")
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes.get("color_temp") is None
|
||||
assert light_state.attributes.get(light.ATTR_COLOR_MODE) == "unknown"
|
||||
assert light_state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/white_value/status", "100")
|
||||
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes["white_value"] == 100
|
||||
assert light_state.attributes["color_temp"] == 300
|
||||
assert light_state.attributes.get(light.ATTR_COLOR_MODE) == "color_temp"
|
||||
assert light_state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/effect/status", "rainbow")
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes["effect"] == "rainbow"
|
||||
assert light_state.attributes.get(light.ATTR_COLOR_MODE) == "color_temp"
|
||||
assert light_state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/rgb/status", "125,125,125")
|
||||
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes.get("rgb_color") == (255, 187, 131)
|
||||
assert light_state.attributes.get(light.ATTR_COLOR_MODE) == "color_temp"
|
||||
assert light_state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/white_value/status", "0")
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
assert light_state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
assert light_state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/hs/status", "200,50")
|
||||
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes.get("hs_color") == (200, 50)
|
||||
assert light_state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
assert light_state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/xy/status", "0.675,0.322")
|
||||
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes.get("xy_color") == (0.672, 0.324)
|
||||
assert light_state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
assert light_state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
|
||||
async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_config):
|
||||
"""Test the controlling of the state via topic."""
|
||||
config = {
|
||||
@ -534,7 +354,6 @@ async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_confi
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("rgbw_color") is None
|
||||
assert state.attributes.get("rgbww_color") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) is None
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
@ -551,7 +370,6 @@ async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_confi
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("rgbw_color") is None
|
||||
assert state.attributes.get("rgbww_color") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "unknown"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
@ -611,125 +429,6 @@ async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_confi
|
||||
assert light_state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
|
||||
async def test_legacy_invalid_state_via_topic(
|
||||
hass, mqtt_mock_entry_with_yaml_config, caplog
|
||||
):
|
||||
"""Test handling of empty data via topic."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"name": "test",
|
||||
"state_topic": "test_light_rgb/status",
|
||||
"command_topic": "test_light_rgb/set",
|
||||
"brightness_state_topic": "test_light_rgb/brightness/status",
|
||||
"brightness_command_topic": "test_light_rgb/brightness/set",
|
||||
"rgb_state_topic": "test_light_rgb/rgb/status",
|
||||
"rgb_command_topic": "test_light_rgb/rgb/set",
|
||||
"color_temp_state_topic": "test_light_rgb/color_temp/status",
|
||||
"color_temp_command_topic": "test_light_rgb/color_temp/set",
|
||||
"effect_state_topic": "test_light_rgb/effect/status",
|
||||
"effect_command_topic": "test_light_rgb/effect/set",
|
||||
"hs_state_topic": "test_light_rgb/hs/status",
|
||||
"hs_command_topic": "test_light_rgb/hs/set",
|
||||
"white_value_state_topic": "test_light_rgb/white_value/status",
|
||||
"white_value_command_topic": "test_light_rgb/white_value/set",
|
||||
"xy_state_topic": "test_light_rgb/xy/status",
|
||||
"xy_command_topic": "test_light_rgb/xy/set",
|
||||
"qos": "0",
|
||||
"payload_on": 1,
|
||||
"payload_off": 0,
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_with_yaml_config()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
assert state.attributes.get("effect") is None
|
||||
assert state.attributes.get("hs_color") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") is None
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "1")
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/rgb/status", "255,255,255")
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "255")
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/effect/status", "none")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_temp") is None
|
||||
assert state.attributes.get("effect") == "none"
|
||||
assert state.attributes.get("hs_color") == (0, 0)
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") == (0.323, 0.329)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", "")
|
||||
assert "Ignoring empty state message" in caplog.text
|
||||
light_state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", "")
|
||||
assert "Ignoring empty brightness message" in caplog.text
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes["brightness"] == 255
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/effect/status", "")
|
||||
assert "Ignoring empty effect message" in caplog.text
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes["effect"] == "none"
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/rgb/status", "")
|
||||
assert "Ignoring empty rgb message" in caplog.text
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes.get("rgb_color") == (255, 255, 255)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/hs/status", "")
|
||||
assert "Ignoring empty hs message" in caplog.text
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes.get("hs_color") == (0, 0)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/hs/status", "bad,bad")
|
||||
assert "Failed to parse hs state update" in caplog.text
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes.get("hs_color") == (0, 0)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/xy/status", "")
|
||||
assert "Ignoring empty xy-color message" in caplog.text
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes.get("xy_color") == (0.323, 0.329)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/color_temp/status", "153")
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/white_value/status", "255")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("rgb_color") == (255, 254, 250)
|
||||
assert state.attributes.get("brightness") == 255
|
||||
assert state.attributes.get("color_temp") == 153
|
||||
assert state.attributes.get("effect") == "none"
|
||||
assert state.attributes.get("hs_color") == (54.768, 1.6)
|
||||
assert state.attributes.get("white_value") == 255
|
||||
assert state.attributes.get("xy_color") == (0.326, 0.333)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/color_temp/status", "")
|
||||
assert "Ignoring empty color temp message" in caplog.text
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes["color_temp"] == 153
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/white_value/status", "")
|
||||
assert "Ignoring empty white value message" in caplog.text
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes["white_value"] == 255
|
||||
|
||||
|
||||
async def test_invalid_state_via_topic(hass, mqtt_mock_entry_with_yaml_config, caplog):
|
||||
"""Test handling of empty data via topic."""
|
||||
config = {
|
||||
@ -955,148 +654,6 @@ async def test_brightness_from_rgb_controlling_scale(
|
||||
assert state.attributes.get("brightness") == 127
|
||||
|
||||
|
||||
async def test_legacy_white_value_controlling_scale(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
"""Test the white_value controlling scale."""
|
||||
with assert_setup_component(1, light.DOMAIN):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
light.DOMAIN,
|
||||
{
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"name": "test",
|
||||
"state_topic": "test_scale/status",
|
||||
"command_topic": "test_scale/set",
|
||||
"white_value_state_topic": "test_scale/white_value/status",
|
||||
"white_value_command_topic": "test_scale/white_value/set",
|
||||
"white_value_scale": "99",
|
||||
"qos": 0,
|
||||
"payload_on": "on",
|
||||
"payload_off": "off",
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_with_yaml_config()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_scale/status", "on")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("white_value") is None
|
||||
|
||||
async_fire_mqtt_message(hass, "test_scale/status", "off")
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test_scale/status", "on")
|
||||
|
||||
async_fire_mqtt_message(hass, "test_scale/white_value/status", "99")
|
||||
|
||||
light_state = hass.states.get("light.test")
|
||||
assert light_state.attributes["white_value"] == 255
|
||||
|
||||
|
||||
async def test_legacy_controlling_state_via_topic_with_templates(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
"""Test the setting of the state with a template."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"name": "test",
|
||||
"state_topic": "test_light_rgb/status",
|
||||
"command_topic": "test_light_rgb/set",
|
||||
"brightness_command_topic": "test_light_rgb/brightness/set",
|
||||
"rgb_command_topic": "test_light_rgb/rgb/set",
|
||||
"color_temp_command_topic": "test_light_rgb/color_temp/set",
|
||||
"effect_command_topic": "test_light_rgb/effect/set",
|
||||
"hs_command_topic": "test_light_rgb/hs/set",
|
||||
"white_value_command_topic": "test_light_rgb/white_value/set",
|
||||
"xy_command_topic": "test_light_rgb/xy/set",
|
||||
"brightness_state_topic": "test_light_rgb/brightness/status",
|
||||
"color_temp_state_topic": "test_light_rgb/color_temp/status",
|
||||
"effect_state_topic": "test_light_rgb/effect/status",
|
||||
"hs_state_topic": "test_light_rgb/hs/status",
|
||||
"rgb_state_topic": "test_light_rgb/rgb/status",
|
||||
"white_value_state_topic": "test_light_rgb/white_value/status",
|
||||
"xy_state_topic": "test_light_rgb/xy/status",
|
||||
"state_value_template": "{{ value_json.hello }}",
|
||||
"brightness_value_template": "{{ value_json.hello }}",
|
||||
"color_temp_value_template": "{{ value_json.hello }}",
|
||||
"effect_value_template": "{{ value_json.hello }}",
|
||||
"hs_value_template": '{{ value_json.hello | join(",") }}',
|
||||
"rgb_value_template": '{{ value_json.hello | join(",") }}',
|
||||
"white_value_template": "{{ value_json.hello }}",
|
||||
"xy_value_template": '{{ value_json.hello | join(",") }}',
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_with_yaml_config()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/rgb/status", '{"hello": [1, 2, 3]}')
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", '{"hello": "ON"}')
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/brightness/status", '{"hello": "50"}')
|
||||
async_fire_mqtt_message(
|
||||
hass, "test_light_rgb/color_temp/status", '{"hello": "300"}'
|
||||
)
|
||||
async_fire_mqtt_message(
|
||||
hass, "test_light_rgb/effect/status", '{"hello": "rainbow"}'
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("brightness") == 50
|
||||
assert state.attributes.get("rgb_color") == (84, 169, 255)
|
||||
assert state.attributes.get("color_temp") is None
|
||||
assert state.attributes.get("effect") == "rainbow"
|
||||
assert state.attributes.get("white_value") is None
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "test_light_rgb/white_value/status", '{"hello": "75"}'
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("brightness") == 50
|
||||
assert state.attributes.get("rgb_color") == (255, 187, 131)
|
||||
assert state.attributes.get("color_temp") == 300
|
||||
assert state.attributes.get("effect") == "rainbow"
|
||||
assert state.attributes.get("white_value") == 75
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/hs/status", '{"hello": [100,50]}')
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/white_value/status", '{"hello": "0"}')
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get("hs_color") == (100, 50)
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "test_light_rgb/xy/status", '{"hello": [0.123,0.123]}'
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get("xy_color") == (0.14, 0.131)
|
||||
|
||||
async_fire_mqtt_message(hass, "test_light_rgb/status", '{"hello": null}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_controlling_state_via_topic_with_templates(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
@ -1200,139 +757,6 @@ async def test_controlling_state_via_topic_with_templates(
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
|
||||
async def test_legacy_sending_mqtt_commands_and_optimistic(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
"""Test the sending of command in optimistic mode."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"name": "test",
|
||||
"command_topic": "test_light_rgb/set",
|
||||
"brightness_command_topic": "test_light_rgb/brightness/set",
|
||||
"rgb_command_topic": "test_light_rgb/rgb/set",
|
||||
"color_temp_command_topic": "test_light_rgb/color_temp/set",
|
||||
"effect_command_topic": "test_light_rgb/effect/set",
|
||||
"hs_command_topic": "test_light_rgb/hs/set",
|
||||
"white_value_command_topic": "test_light_rgb/white_value/set",
|
||||
"xy_command_topic": "test_light_rgb/xy/set",
|
||||
"effect_list": ["colorloop", "random"],
|
||||
"qos": 2,
|
||||
"payload_on": "on",
|
||||
"payload_off": "off",
|
||||
}
|
||||
}
|
||||
color_modes = ["color_temp", "hs", "rgbw"]
|
||||
fake_state = ha.State(
|
||||
"light.test",
|
||||
"on",
|
||||
{
|
||||
"brightness": 95,
|
||||
"hs_color": [100, 100],
|
||||
"effect": "random",
|
||||
"color_temp": 100,
|
||||
# TODO: Test restoring state with white_value
|
||||
"white_value": 0,
|
||||
},
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
||||
return_value=fake_state,
|
||||
), assert_setup_component(1, light.DOMAIN):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("brightness") == 95
|
||||
assert state.attributes.get("hs_color") == (100, 100)
|
||||
assert state.attributes.get("effect") == "random"
|
||||
assert state.attributes.get("color_temp") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
await common.async_turn_on(hass, "light.test")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"test_light_rgb/set", "on", 2, False
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
await common.async_turn_off(hass, "light.test")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"test_light_rgb/set", "off", 2, False
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
mqtt_mock.reset_mock()
|
||||
await common.async_turn_on(
|
||||
hass, "light.test", brightness=50, xy_color=[0.123, 0.123]
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
await common.async_turn_on(hass, "light.test", brightness=50, hs_color=[359, 78])
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
await common.async_turn_on(hass, "light.test", rgb_color=[255, 128, 0])
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "hs"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light_rgb/set", "on", 2, False),
|
||||
call("test_light_rgb/rgb/set", "255,128,0", 2, False),
|
||||
call("test_light_rgb/brightness/set", "50", 2, False),
|
||||
call("test_light_rgb/hs/set", "359.0,78.0", 2, False),
|
||||
call("test_light_rgb/xy/set", "0.14,0.131", 2, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes["rgb_color"] == (255, 128, 0)
|
||||
assert state.attributes["brightness"] == 50
|
||||
assert state.attributes["hs_color"] == (30.118, 100)
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes["xy_color"] == (0.611, 0.375)
|
||||
assert state.attributes.get("color_temp") is None
|
||||
|
||||
await common.async_turn_on(hass, "light.test", white_value=80, color_temp=125)
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "color_temp"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light_rgb/white_value/set", "80", 2, False),
|
||||
call("test_light_rgb/color_temp/set", "125", 2, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("rgb_color") == (221, 229, 255)
|
||||
assert state.attributes["brightness"] == 50
|
||||
assert state.attributes.get("hs_color") == (224.772, 13.249)
|
||||
assert state.attributes["white_value"] == 80
|
||||
assert state.attributes.get("xy_color") == (0.296, 0.301)
|
||||
assert state.attributes["color_temp"] == 125
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
@ -1884,98 +1308,6 @@ async def test_on_command_brightness_scaled(hass, mqtt_mock_entry_with_yaml_conf
|
||||
)
|
||||
|
||||
|
||||
async def test_legacy_on_command_rgb(hass, mqtt_mock_entry_with_yaml_config):
|
||||
"""Test on command in RGB brightness mode."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"name": "test",
|
||||
"command_topic": "test_light/set",
|
||||
"rgb_command_topic": "test_light/rgb",
|
||||
"white_value_command_topic": "test_light/white_value",
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
await common.async_turn_on(hass, "light.test", brightness=127)
|
||||
|
||||
# Should get the following MQTT messages.
|
||||
# test_light/rgb: '127,127,127'
|
||||
# test_light/set: 'ON'
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light/rgb", "127,127,127", 0, False),
|
||||
call("test_light/set", "ON", 0, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await common.async_turn_on(hass, "light.test", brightness=255)
|
||||
|
||||
# Should get the following MQTT messages.
|
||||
# test_light/rgb: '255,255,255'
|
||||
# test_light/set: 'ON'
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light/rgb", "255,255,255", 0, False),
|
||||
call("test_light/set", "ON", 0, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await common.async_turn_on(hass, "light.test", brightness=1)
|
||||
|
||||
# Should get the following MQTT messages.
|
||||
# test_light/rgb: '1,1,1'
|
||||
# test_light/set: 'ON'
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light/rgb", "1,1,1", 0, False),
|
||||
call("test_light/set", "ON", 0, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await common.async_turn_off(hass, "light.test")
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with("test_light/set", "OFF", 0, False)
|
||||
|
||||
# Ensure color gets scaled with brightness.
|
||||
await common.async_turn_on(hass, "light.test", rgb_color=[255, 128, 0])
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light/rgb", "1,0,0", 0, False),
|
||||
call("test_light/set", "ON", 0, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await common.async_turn_on(hass, "light.test", brightness=255)
|
||||
|
||||
# Should get the following MQTT messages.
|
||||
# test_light/rgb: '255,128,0'
|
||||
# test_light/set: 'ON'
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light/rgb", "255,128,0", 0, False),
|
||||
call("test_light/set", "ON", 0, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_on_command_rgb(hass, mqtt_mock_entry_with_yaml_config):
|
||||
"""Test on command in RGB brightness mode."""
|
||||
config = {
|
||||
@ -2486,7 +1818,6 @@ async def test_explicit_color_mode(hass, mqtt_mock_entry_with_yaml_config):
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("rgbw_color") is None
|
||||
assert state.attributes.get("rgbww_color") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) is None
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
@ -2503,7 +1834,6 @@ async def test_explicit_color_mode(hass, mqtt_mock_entry_with_yaml_config):
|
||||
assert state.attributes.get("rgb_color") is None
|
||||
assert state.attributes.get("rgbw_color") is None
|
||||
assert state.attributes.get("rgbww_color") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("xy_color") is None
|
||||
assert state.attributes.get(light.ATTR_COLOR_MODE) == "unknown"
|
||||
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
|
||||
@ -2923,14 +2253,12 @@ async def test_discovery_update_light_topic_and_template(
|
||||
"color_temp_command_topic": "test_light_rgb/state1",
|
||||
"effect_command_topic": "test_light_rgb/effect/set",
|
||||
"hs_command_topic": "test_light_rgb/hs/set",
|
||||
"white_value_command_topic": "test_light_rgb/white_value/set",
|
||||
"xy_command_topic": "test_light_rgb/xy/set",
|
||||
"brightness_state_topic": "test_light_rgb/state1",
|
||||
"color_temp_state_topic": "test_light_rgb/state1",
|
||||
"effect_state_topic": "test_light_rgb/state1",
|
||||
"hs_state_topic": "test_light_rgb/state1",
|
||||
"rgb_state_topic": "test_light_rgb/state1",
|
||||
"white_value_state_topic": "test_light_rgb/state1",
|
||||
"xy_state_topic": "test_light_rgb/state1",
|
||||
"state_value_template": "{{ value_json.state1.state }}",
|
||||
"brightness_value_template": "{{ value_json.state1.brightness }}",
|
||||
@ -2938,7 +2266,6 @@ async def test_discovery_update_light_topic_and_template(
|
||||
"effect_value_template": "{{ value_json.state1.fx }}",
|
||||
"hs_value_template": "{{ value_json.state1.hs }}",
|
||||
"rgb_value_template": "{{ value_json.state1.rgb }}",
|
||||
"white_value_template": "{{ value_json.state1.white }}",
|
||||
"xy_value_template": "{{ value_json.state1.xy }}",
|
||||
}
|
||||
|
||||
@ -2951,14 +2278,12 @@ async def test_discovery_update_light_topic_and_template(
|
||||
"color_temp_command_topic": "test_light_rgb/state2",
|
||||
"effect_command_topic": "test_light_rgb/effect/set",
|
||||
"hs_command_topic": "test_light_rgb/hs/set",
|
||||
"white_value_command_topic": "test_light_rgb/white_value/set",
|
||||
"xy_command_topic": "test_light_rgb/xy/set",
|
||||
"brightness_state_topic": "test_light_rgb/state2",
|
||||
"color_temp_state_topic": "test_light_rgb/state2",
|
||||
"effect_state_topic": "test_light_rgb/state2",
|
||||
"hs_state_topic": "test_light_rgb/state2",
|
||||
"rgb_state_topic": "test_light_rgb/state2",
|
||||
"white_value_state_topic": "test_light_rgb/state2",
|
||||
"xy_state_topic": "test_light_rgb/state2",
|
||||
"state_value_template": "{{ value_json.state2.state }}",
|
||||
"brightness_value_template": "{{ value_json.state2.brightness }}",
|
||||
@ -2966,7 +2291,6 @@ async def test_discovery_update_light_topic_and_template(
|
||||
"effect_value_template": "{{ value_json.state2.fx }}",
|
||||
"hs_value_template": "{{ value_json.state2.hs }}",
|
||||
"rgb_value_template": "{{ value_json.state2.rgb }}",
|
||||
"white_value_template": "{{ value_json.state2.white }}",
|
||||
"xy_value_template": "{{ value_json.state2.xy }}",
|
||||
}
|
||||
state_data1 = [
|
||||
@ -2981,7 +2305,6 @@ async def test_discovery_update_light_topic_and_template(
|
||||
[
|
||||
("brightness", 100),
|
||||
("color_temp", 123),
|
||||
("white_value", 100),
|
||||
("effect", "cycle"),
|
||||
],
|
||||
),
|
||||
@ -2998,7 +2321,7 @@ async def test_discovery_update_light_topic_and_template(
|
||||
)
|
||||
],
|
||||
"on",
|
||||
[("hs_color", (1, 2)), ("white_value", None)],
|
||||
[("hs_color", (1, 2))],
|
||||
),
|
||||
(
|
||||
[
|
||||
@ -3018,7 +2341,7 @@ async def test_discovery_update_light_topic_and_template(
|
||||
)
|
||||
],
|
||||
"on",
|
||||
[("xy_color", (0.3, 0.401))],
|
||||
[("xy_color", (0.3, 0.4))],
|
||||
),
|
||||
]
|
||||
state_data2 = [
|
||||
@ -3033,7 +2356,6 @@ async def test_discovery_update_light_topic_and_template(
|
||||
[
|
||||
("brightness", 50),
|
||||
("color_temp", 200),
|
||||
("white_value", 50),
|
||||
("effect", "loop"),
|
||||
],
|
||||
),
|
||||
@ -3083,7 +2405,7 @@ async def test_discovery_update_light_topic_and_template(
|
||||
)
|
||||
],
|
||||
"on",
|
||||
[("hs_color", (1.2, 2.2)), ("white_value", None)],
|
||||
[("hs_color", (1.2, 2.2))],
|
||||
),
|
||||
(
|
||||
[
|
||||
@ -3186,14 +2508,12 @@ async def test_discovery_update_light_template(
|
||||
"color_temp_command_topic": "test_light_rgb/state1",
|
||||
"effect_command_topic": "test_light_rgb/effect/set",
|
||||
"hs_command_topic": "test_light_rgb/hs/set",
|
||||
"white_value_command_topic": "test_light_rgb/white_value/set",
|
||||
"xy_command_topic": "test_light_rgb/xy/set",
|
||||
"brightness_state_topic": "test_light_rgb/state1",
|
||||
"color_temp_state_topic": "test_light_rgb/state1",
|
||||
"effect_state_topic": "test_light_rgb/state1",
|
||||
"hs_state_topic": "test_light_rgb/state1",
|
||||
"rgb_state_topic": "test_light_rgb/state1",
|
||||
"white_value_state_topic": "test_light_rgb/state1",
|
||||
"xy_state_topic": "test_light_rgb/state1",
|
||||
"state_value_template": "{{ value_json.state1.state }}",
|
||||
"brightness_value_template": "{{ value_json.state1.brightness }}",
|
||||
@ -3201,7 +2521,6 @@ async def test_discovery_update_light_template(
|
||||
"effect_value_template": "{{ value_json.state1.fx }}",
|
||||
"hs_value_template": "{{ value_json.state1.hs }}",
|
||||
"rgb_value_template": "{{ value_json.state1.rgb }}",
|
||||
"white_value_template": "{{ value_json.state1.white }}",
|
||||
"xy_value_template": "{{ value_json.state1.xy }}",
|
||||
}
|
||||
|
||||
@ -3214,14 +2533,12 @@ async def test_discovery_update_light_template(
|
||||
"color_temp_command_topic": "test_light_rgb/state1",
|
||||
"effect_command_topic": "test_light_rgb/effect/set",
|
||||
"hs_command_topic": "test_light_rgb/hs/set",
|
||||
"white_value_command_topic": "test_light_rgb/white_value/set",
|
||||
"xy_command_topic": "test_light_rgb/xy/set",
|
||||
"brightness_state_topic": "test_light_rgb/state1",
|
||||
"color_temp_state_topic": "test_light_rgb/state1",
|
||||
"effect_state_topic": "test_light_rgb/state1",
|
||||
"hs_state_topic": "test_light_rgb/state1",
|
||||
"rgb_state_topic": "test_light_rgb/state1",
|
||||
"white_value_state_topic": "test_light_rgb/state1",
|
||||
"xy_state_topic": "test_light_rgb/state1",
|
||||
"state_value_template": "{{ value_json.state2.state }}",
|
||||
"brightness_value_template": "{{ value_json.state2.brightness }}",
|
||||
@ -3229,7 +2546,6 @@ async def test_discovery_update_light_template(
|
||||
"effect_value_template": "{{ value_json.state2.fx }}",
|
||||
"hs_value_template": "{{ value_json.state2.hs }}",
|
||||
"rgb_value_template": "{{ value_json.state2.rgb }}",
|
||||
"white_value_template": "{{ value_json.state2.white }}",
|
||||
"xy_value_template": "{{ value_json.state2.xy }}",
|
||||
}
|
||||
state_data1 = [
|
||||
@ -3244,7 +2560,6 @@ async def test_discovery_update_light_template(
|
||||
[
|
||||
("brightness", 100),
|
||||
("color_temp", 123),
|
||||
("white_value", 100),
|
||||
("effect", "cycle"),
|
||||
],
|
||||
),
|
||||
@ -3281,7 +2596,7 @@ async def test_discovery_update_light_template(
|
||||
)
|
||||
],
|
||||
"on",
|
||||
[("white_value", None), ("xy_color", (0.3, 0.401))],
|
||||
[("xy_color", (0.3, 0.4))],
|
||||
),
|
||||
]
|
||||
state_data2 = [
|
||||
@ -3296,7 +2611,6 @@ async def test_discovery_update_light_template(
|
||||
[
|
||||
("brightness", 50),
|
||||
("color_temp", 200),
|
||||
("white_value", 50),
|
||||
("effect", "loop"),
|
||||
],
|
||||
),
|
||||
@ -3368,7 +2682,7 @@ async def test_discovery_update_light_template(
|
||||
)
|
||||
],
|
||||
"on",
|
||||
[("white_value", None), ("xy_color", (0.4, 0.3))],
|
||||
[("xy_color", (0.4, 0.3))],
|
||||
),
|
||||
(
|
||||
[
|
||||
@ -3378,7 +2692,7 @@ async def test_discovery_update_light_template(
|
||||
)
|
||||
],
|
||||
"on",
|
||||
[("white_value", None), ("xy_color", (0.4, 0.3))],
|
||||
[("xy_color", (0.4, 0.3))],
|
||||
),
|
||||
]
|
||||
|
||||
@ -3646,7 +2960,6 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
|
||||
"topic,value,attribute,attribute_value,init_payload",
|
||||
[
|
||||
("state_topic", "ON", None, "on", None),
|
||||
("brightness_state_topic", "60", "brightness", 60, ("state_topic", "ON")),
|
||||
(
|
||||
"color_mode_state_topic",
|
||||
"200",
|
||||
@ -3695,8 +3008,40 @@ async def test_encoding_subscribable_topics(
|
||||
config[CONF_RGBWW_COMMAND_TOPIC] = "light/CONF_RGBWW_COMMAND_TOPIC"
|
||||
config[CONF_XY_COMMAND_TOPIC] = "light/CONF_XY_COMMAND_TOPIC"
|
||||
config[CONF_EFFECT_LIST] = ["colorloop", "random"]
|
||||
if attribute and attribute == "brightness":
|
||||
config[CONF_WHITE_VALUE_COMMAND_TOPIC] = "light/CONF_WHITE_VALUE_COMMAND_TOPIC"
|
||||
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_with_yaml_config,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
value,
|
||||
attribute,
|
||||
attribute_value,
|
||||
init_payload,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"topic,value,attribute,attribute_value,init_payload",
|
||||
[
|
||||
("brightness_state_topic", "60", "brightness", 60, ("state_topic", "ON")),
|
||||
],
|
||||
)
|
||||
async def test_encoding_subscribable_topics_brightness(
|
||||
hass,
|
||||
mqtt_mock_entry_with_yaml_config,
|
||||
caplog,
|
||||
topic,
|
||||
value,
|
||||
attribute,
|
||||
attribute_value,
|
||||
init_payload,
|
||||
):
|
||||
"""Test handling of incoming encoded payload for a brightness only light."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG[light.DOMAIN])
|
||||
config[CONF_BRIGHTNESS_COMMAND_TOPIC] = "light/CONF_BRIGHTNESS_COMMAND_TOPIC"
|
||||
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
|
Reference in New Issue
Block a user